-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParameterEstimator_caller.m
279 lines (199 loc) · 10.4 KB
/
ParameterEstimator_caller.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
function [x,aic,bic,nll_x,x0] = ParameterEstimator_caller(rn,data,fittingType)
SaveDir = '.'; % Location for models to be saved out
if ~exist('rn','var')
rn = 0;
warning('Using default value for `rn` (0)')
end
% addpath(genpath('C:\Users\cege-user\Documents\MacaqueColorCategories'))
%% Load or generate data
% data = generateSimulatedData;
% DataDir = 'C:\Users\cege-user\Documents\MacaqueColorCategories\Data\';
% if ~exist('data','var')
% data = combineData(DataDir); % TODO Switch to csv
% end
%
% data.trialdata.nBig = 64;
% data.trialdata.nSmall = 4;
% data.trialdata.nTrials = 98104;
% warning('Assuming nBig, nSmall, and nTrials')
%% Overwrite `data` with simulated responses, for testing purposes
% remove `response` to get new data,
% given fixed parameters
% aka, just use the cues/choices etc
%
% rng(rn)
%
% stimulusRemapping = rand(1,data.trialdata.nBig);
% skewedGaussians = rand(1,data.trialdata.nBig);
%
% choiceInds = cell2mat(data.trialdata.choices);
% cueInd = cell2mat(data.trialdata.cues);
%
% [nll_data,data] = GenerativeModel([],... % anonymous function so that we can pass additional parameters
% 'choiceInds', choiceInds',...
% 'cueInd', cueInd,...
% 'nTrials', data.trialdata.nTrials,...
% 'nBig', data.trialdata.nBig, ...
% 'nSmall', data.trialdata.nSmall,...
% 'dPrime', 1,...
% 'gaussianWidth', 60,...
% 'stimulusRemappingPol', stimulusRemapping,...
% 'skewedGaussians', skewedGaussians);
%
% plotSimilarityMatrix(data.trialdata.similarityMatrix)
%
% data.trialdata.nBig = 64;
% data.trialdata.nSmall = 4;
% data.trialdata.nTrials = 98104;
% warning('Assuming nBig, nSmall, and nTrials')
%% Key:
% 1 - Free Similarity Matrix
% 2 - dPrime
% 3 - stimulus remapping (cartesian)
% 4 - stimulus remapping (polar, angle in degrees)
% 5 - gaussianWidth
% 6 - skewedGaussians
% 7 - offsetGaussian
%% dPrimeAndGaussianWidth
if strcmp(fittingType,'dPrimeAndGaussianWidth')
params = [0,1,0,0,1,0,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn);
save([SaveDir, filesep,...
fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).')
% save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
end
%% Single fitting - ssnu
if strcmp(fittingType,'single-ssnu')
params = [0,1,0,0,1,0,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn);
% save([SaveDir, filesep,...
% fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
% '-regexp', '^(?!(data)$).')
% % save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
disp(x(1))
disp(x(2))
params = [0,0,0,1,0,0,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn,[],[],...
'dPrime', x(1),...
'gaussianWidth', x(2));
save([SaveDir, filesep,...
fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).')
% save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
end
%% Single fitting - sg
if strcmp(fittingType,'single-sg')
params = [0,1,0,0,1,0,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn);
% save([SaveDir, filesep,...
% fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
% '-regexp', '^(?!(data)$).')
% % save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
params = [0,0,0,0,0,1,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn,[],[],...
'dPrime', x(1),...
'gaussianWidth', x(2));
save([SaveDir, filesep,...
fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).')
% save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
end
%% Single fitting - og
if strcmp(fittingType,'single-og')
params = [0,1,0,0,1,0,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn);
% save([SaveDir, filesep,...
% fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
% '-regexp', '^(?!(data)$).')
% % save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
disp(x(1))
disp(x(2))
params = [0,0,0,0,0,0,1];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn,[],[],...
'dPrime', x(1),...
'gaussianWidth', x(2));
save([SaveDir, filesep,...
fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).')
% save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
end
%% GaussianWidthsAndSkewedGaussians
if strcmp(fittingType,'GaussianWidthsAndSkewedGaussians')
params = [0,0,0,0,1,1,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn,[],[],...
'dPrime',2);
save([SaveDir, filesep,...
fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).')
% save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
end
%% Simultaneous fitting
if strcmp(fittingType,'simultaneous')
params = [0,1,0,1,1,1,0];
[x,aic,bic,nll_x,x0] = ParameterEstimator(data,params,rn);
save([SaveDir, filesep,...
fittingType,num2str(rn),datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).')
% save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
end
%% Iterative fitting
if strcmp(fittingType,'iterative')
rng(rn);
% Here we want the result to be reproducible, but we want each loop to
% be different, and so we call the rng _here_ instead of passing it to
% `ParamaterEstimator`
% Initialise starting values
currentValues.dPrime = 1;
currentValues.gaussianWidth = 60;
currentValues.stimulusRemapping = NaN; % NaN defaults to no stimulus remapping
currentValues.skewedGaussians = NaN; % NaN defaults to no skew in the gaussians
for i = 1:3
params = [0,1,0,0,0,0,0]; % dPrime
[currentValues.dPrime,...
aic,bic,nll_x,x0] = ParameterEstimator(data,params,randi(100,1),[],[],...
'dPrime', currentValues.dPrime,...
'gaussianWidth', currentValues.gaussianWidth,...
'stimulusRemappingPol', currentValues.stimulusRemapping,...
'skewedGaussians', currentValues.skewedGaussians);
save([SaveDir, filesep,...
fittingType, datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).') % save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
params = [0,0,0,0,1,0,0]; % gaussianWidth
[currentValues.gaussianWidth,...
aic,bic,nll_x,x0] = ParameterEstimator(data,params,randi(10,1),[],[],...
'dPrime', currentValues.dPrime,...
'gaussianWidth', currentValues.gaussianWidth,...
'stimulusRemappingPol', currentValues.stimulusRemapping,...
'skewedGaussians', currentValues.skewedGaussians);
save([SaveDir, filesep,...
fittingType, datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).') % save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
params = [0,0,0,1,0,0,0]; % gaussianWidth
[currentValues.stimulusRemapping,...
aic,bic,nll_x,x0] = ParameterEstimator(data,params,randi(10,1),[],[],...
'dPrime', currentValues.dPrime,...
'gaussianWidth', currentValues.gaussianWidth,...
'stimulusRemappingPol', currentValues.stimulusRemapping,...
'skewedGaussians', currentValues.skewedGaussians);
save([SaveDir, filesep,...
fittingType, datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).') % save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
params = [0,0,0,0,0,1,0]; % gaussianWidth
[currentValues.skewedGaussians,...
aic,bic,nll_x,x0] = ParameterEstimator(data,params,randi(10,1),[],[],...
'dPrime', currentValues.dPrime,...
'gaussianWidth', currentValues.gaussianWidth,...
'stimulusRemappingPol', currentValues.stimulusRemapping,...
'skewedGaussians', currentValues.skewedGaussians);
save([SaveDir, filesep,...
fittingType, datestr(now,'yymmdd-HHMMSS'),'.mat'],...
'-regexp', '^(?!(data)$).') % save everything except data (https://www.mathworks.com/matlabcentral/answers/101287-how-do-i-save-all-of-the-workspace-variables-except-for-a-certain-specified-variable-name-in-matlab#answer_110635)
end
load('iterative230817-153048.mat')
x = [currentValues.dPrime,...
currentValues.stimulusRemapping,...
currentValues.gaussianWidth,...
currentValues.skewedGaussians'];
end
end