-
Notifications
You must be signed in to change notification settings - Fork 0
/
rmMainPostSearch.m
194 lines (168 loc) · 7.61 KB
/
rmMainPostSearch.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
function view = rmMainPostSearch(view,roiFileName,wSearch,rmFile, varargin)
% rmMain - main retinotopy model program
%
% view = rmMain([view],[roiFileName],[wSearch],[varargin]);
%
% view : mrVista view structure or view pointer [required]
% roiFileName : Restrict analysis to this ROI file [default = [] (none)]
% unless ROI file is loaded in the view struct.
% wSearch : 1 = grid search only ("coarse"),
% 2 = minimization search only ("fine"),
% 3 = grid followed by minimization search [default]
% 4 = grid followed by two minimization searches, the first
% with temporal decimation, the second without.
% 5 = grid followed by two minimization searches, followed
% by HRF search, followed by PRF search
% varargin : Other arguments can include redefinitions of
% parameter (argument type) [default]
% General parameters:
% pRF model ({'model','model2'}) [{'one gaussian'}]
% hrf ({int,string,matrix}) [user defined]
% matFileName (string) ['retModel-currentDateAndTime']
% Grid search parameters (first stage):
% coarse to fine (boolean) [1,true]
% coarse sample (boolean) [1,true]
% coarse blur params (matrix) [5 1]
% decimate (int) [0]
% gridpoints (int) [50]
% number of sigmas (int) [24]
% space sigmas (sting) ['linlog']
% relative grid step (float) [2.3548]
% scale with sigmas (boolean) [0,false]
% min pRF size (float) [0.2]
% max pRF size (float) [stimulus radius]
% sigmaRatio (matrix) [2 4 6 8]
% outerlimit (float) [2]
% Minimization search parameters (second stage):
% vethresh (float) [0.15]
% maxiter (int) [25]
% expand range (int) [5]
% See 'rmDefineParameters' for details.
%
% Examples:
% Basic call. Writes out the relevant file inside of Gray\yourDataType directory.
% Called this way, the results are not attached to the current VOLUME
% global. They results can still be loaded in from the GUI.
%
% vw = VOLUME{1};
% roiFileName = 'leftMT';
% searchType = 'coarse to fine';
% rmMain(vw,roiFileName,searchType);
%
% Called this way, the current VOLUME is updated with the results of the
% analysis. The results are written to file, as above. Notice that you
% can make the call with multiple model names and both will be created for
% you. They are both stored in the same output file.
%
% outFileName = 'myFile'
% prfModels = {'one gaussian','difference of gaussians'};
% VOLUME{1} = rmMain(vw,roiFileName,searchType,'matFileName', outFileName,'model',prfModels);
%
%
% 2005/2006 SOD: wrote it.
%-----------------------------------
% argument checks
%-----------------------------------
if notDefined('view'), error('Need view struct'); end;
if notDefined('roiFileName'), roiFileName = []; end;
if notDefined('wSearch'), wSearch = 3; end;
if isnumeric(wSearch), wSearch = num2str(wSearch); end;
if nargin > 3,
addArg = varargin;
else
addArg = [];
end;
% If we do a search fit we need the optimization toolbox. We try to reserve
% it here. If not successfull we continue anyway and let rmSearchFit try
% just before we really need it.
if wSearch>1,
reserveToolbox('optimization');
end
% view can either be a proper view structure, in which case we skip this
% step and continue, or a set of pointers that point to how to create the
% view struct. If the latter we create the view struct here. This is useful
% for running the analysis in the background.
if ~isstruct(view),
view = rmInitView(view,roiFileName);
end
load(rmFile);
view = viewSet(view,'rmModel', model);
view = viewSet(view,'rmFile', rmFile);
for n=1:length(params.stim)
if strcmp(params.stim(n).imFile(1:15), '/media/Storage3')
params.stim(n).imFile=['/mnt/data' params.stim(n).imFile(16:end)];
end
if strcmp(params.stim(n).paramsFile(1:15), '/media/Storage3')
params.stim(n).paramsFile=['/mnt/data' params.stim(n).paramsFile(16:end)];
end
end
% record the annotation for this stimulus, for reference
% (kept outside rmMakeStimulus, so that function won't need the view)
% for n = 1:length(params.stim)
% params.stim(n).annotation = annotation(view, n);
% end
%-----------------------------------
% Different fitting strategies
%-----------------------------------
switch lower(wSearch)
case {'3','2 stage coarse to fine fit','coarse to fine'}
fprintf(1,'[%s]:Two stage coarse-to-fine fit.\n',mfilename);
view = rmSearchFit(view,params);
case {'4','3 stage coarse to fine fit','coarse to fine 2'}
% fprintf(1,'[%s]:Three stage coarse-to-fine fit.\n',mfilename);
% view = rmSearchFit(view,params,params.analysis.coarseDecimate);
% view = rmSearchFit(view,params);
view = rmFinalFit(view,params);
case {'5','3x2 stage coarse to fine fit','coarse to fine and hrf'}
[view,params] = rmHrfSearchFit(view,params);
view = rmFinalFit(view,params);
view = rmSearchFit(view,params);
case {'6','HRF coarse to fine fit','hrf'}
[view, params] = rmHrfSearchFit(view, params);
view = rmFinalFit(view,params);
view = rmSearchFit(view, params);
case {'7','search fit and reset params'}
% Modify existing fit AND refresh the parameters. This is
% particularly useful when the initial model is estimated from a
% different data-set (or stimulus).
% If you do not want to reset the fitting params see option 2
% above.
fprintf(1,'[%s]:Refining fit above a certain threshold (fine fit).\n',mfilename);
fprintf(1,'[%s]: *****************************************\n',mfilename);
fprintf(1,'[%s]: * WARNING:Resetting fitting parameters! *\n',mfilename);
fprintf(1,'[%s]: *****************************************\n',mfilename);
view = rmSearchFit(view,params);
case {'8','grid with hrf'}
%ve=rmGet(view.rm.retinotopyModels{1}, 've');
%if any(ve>params.analysis.hrfmins.thresh.ve)
%view = rmSelect(view, 2); view = rmLoadDefault(view);
[view, params] = rmHrfSearchFit(view, params);
view = rmGridFit(view,params);
%end
case {'9','grid monotonic'}
view = rmGridFitMonotonic(view,params);
case {'10'}
view = rmGridFitMonotonic(view,params);
[view, params] = rmHrfSearchFit_monotonic(view, params);
view = rmGridFitMonotonic(view,params);
case {'11'}
params.wData='roi';
[view,params] = rmHrfSearchFitPerVoxel(view,params);
params.wData='roi';
view = rmFinalFitPerVoxelHrf(view,params);
view = rmSearchFitPerVoxelHrf(view,params);
view = rmFinalFitPerVoxelHrf(view,params);
otherwise
error('[%s]:Unknown search option: %s',mfilename,wSearch);
end
%-----------------------------------
% Final fit (only for certain models)
%-----------------------------------
switch lower(wSearch)
case {'1','coarse','grid fit', '4', '8', '9', '10', '11'}
%do nothing
otherwise
view = rmFinalFit(view,params);
end
% done
return;