-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathattemptModelRecovery.m
98 lines (72 loc) · 2.82 KB
/
attemptModelRecovery.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function attemptModelRecovery(recoveryType, mode, saveDir, varargin)
% INPUT
% recoveryType Analyse each data set with only the true model, and simply
% attempt to recover parameters, or analyse will all models,
% fitting parameters and comparing models. Use 'params', and
% 'models' respectively.
% mode Run on 'cluster' or 'local'.
% saveDir Directory for saving simulated data and fits.
% varargin (Optional). Provide a standard dataset that has been fitted.
% Then the simulated data will be based on the fitted parameters.
addpath('./modellingTools')
addpath('./analysisFuns')
addpath('./circstat-matlab')
addpath('./lautils-mat/stats')
if isempty(varargin)
templateDSet = false;
else
templateDSet = true;
Template = varargin{1};
end
%% Simulate
if ~templateDSet
% Simulate participants from each of the key models
allModels = enumerateModels('key');
AllDSets = cell(length(allModels), 1);
GeneralSpec.NumPtpnt = 10;
GeneralSpec.TrialsPerCond = 256;
GeneralSpec.SetSizes = [2, 3, 4, 6];
GeneralSpec.Kappa_s = [0, 1.5];
GeneralSpec.StatType = 'circ';
Spec = repmat(GeneralSpec, length(allModels), 1);
for iSpec = 1 : length(allModels)
Spec(iSpec).Name = allModels{iSpec};
for iP = 1 : GeneralSpec.NumPtpnt
Spec(iSpec).Params(iP) = assignDefaultParamValues(allModels{iSpec});
end
AllDSets{iSpec} = produceStandardFormatDSet(Spec(iSpec));
end
elseif templateDSet
allModels = mT_findAppliedModels(Template);
AllDSets = cell(length(allModels), 1);
for iSpec = 1 : length(allModels)
AllDSets{iSpec} = simulateDSetBasedOnReal(Template, iSpec, struct());
end
end
%% Model recovery attempts
% Look over all simulations
for iSpec = 1 : length(AllDSets)
% Analyse the data using each model if requested
if strcmp(recoveryType, 'models')
models = allModels;
trueModelNum= iSpec;
elseif strcmp(recoveryType, 'params')
models = allModels(iSpec);
trueModelNum = 1;
end
% Check things are organised in the way we will probably assume later
assert(isequal(models{trueModelNum}, AllDSets{iSpec}.SimSpec.Name));
if strcmp(mode, 'cluster')
AllDSets{iSpec} = fitModels(AllDSets{iSpec}, models, ...
mode, saveDir, length(AllDSets{iSpec}.P));
elseif strcmp(mode, 'local')
AllDSets{iSpec} = fitModels(AllDSets{iSpec}, models, mode, [], ...
length(AllDSets{iSpec}.P));
end
end
%% Save if running locally
if strcmp(mode, 'local')
AllDSets = mT_removeFunctionHandles(AllDSets, ...
{'FindSampleSize', 'FindIncludedTrials'});
save([saveDir '\ModelRecoveryData'], 'AllDSets')
end