Browse code

multiple searchlight radii

git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@186 83ab2cfd-5345-466c-8aeb-2b2739fb922d

Christoph Budziszewski authored on 26/04/2009 22:01:30
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,4 @@
1
+function a = getArray(fieldhandle)
2
+str = get(fieldhandle,'String');
3
+a = eval([ '[' str ']' ]);
4
+end
0 5
\ No newline at end of file
... ...
@@ -1,3 +1,3 @@
1 1
 function r = getSearchlightRadius(model)
2
-r = getDouble(model.txtSearchlightRadius);
2
+r = getArray(model.txtSearchlightRadius);
3 3
 end
4 4
\ No newline at end of file
... ...
@@ -13,7 +13,7 @@ pstopts = args.psthOpts;
13 13
 pstopts.eventList = args.eventList;
14 14
 pstopts.sessionList = sessionlist;
15 15
 
16
-radius = fbsargs.radius;
16
+radiusList = fbsargs.radius;
17 17
 
18 18
 timeline = header.timeline;
19 19
 timeline.frameShiftStart = header.frameShift.frameShiftStart;
... ...
@@ -60,7 +60,7 @@ for s = 1:nSubjects
60 60
     indexToCoordMap = java.util.HashMap;
61 61
     coordToIndexMap = java.util.HashMap;
62 62
     for iVoxel = 1:nVoxel
63
-        coord = [x(iVoxel) y(iVoxel) z(iVoxel)]
63
+        coord = [x(iVoxel) y(iVoxel) z(iVoxel)];
64 64
         a = java.util.Vector(3,0);
65 65
         a.add(0,coord(1));
66 66
         a.add(1,coord(2));
... ...
@@ -104,7 +104,7 @@ for s = 1:nSubjects
104 104
     pause(0.001) % flush system event queue (respond to ctrl-c)
105 105
     tic
106 106
     
107
-    display(sprintf('rastering %g coordinates with approx. %g mm radius',nVoxel,radius));
107
+    display(sprintf('rastering %g coordinates',nVoxel));
108 108
     % for each timeslice
109 109
     globalStart     = timeline.psthStart;
110 110
     globalEnd       = timeline.psthEnd;
... ...
@@ -117,8 +117,6 @@ for s = 1:nSubjects
117 117
     % tmp = spm_imatrix(V(kImage).mat); %
118 118
     % vdim = tmp(7:9); % Voxel-Size
119 119
     
120
-
121
-    
122 120
     mask_image = load_nii(subjects{s}.roiFile.fname);
123 121
     
124 122
     vdim = mask_image.hdr.dime.pixdim(2:4);
... ...
@@ -134,64 +132,69 @@ if isempty( fbsargs.timeline )
134 132
 	fbsTimeLine = 1:nSamplePoints;
135 133
     fbsTimeLine = fbsTimeLine +globalStart;
136 134
 else 
135
+    %preferred!
137 136
 	fbsTimeLine = fbsargs.timeline;
138 137
 end
139 138
 
140
-
141
-    for timeShiftIdx = fbsTimeLine
139
+for timeShiftIdx = fbsTimeLine
142 140
         
143 141
     % center timepoint && relative shift
144 142
     frameStartIdx  = floor(-globalStart+1+timeShiftIdx - 0.5*decodeDuration);
145 143
     frameEndIdx    = min(ceil(frameStartIdx+decodeDuration + 0.5*decodeDuration),-globalStart+globalEnd);
146 144
 
147
-        img3D = zeros(size(mask_image)); %output image prepare
148
-
145
+        for r = radiusList
146
+            img3D{r} = zeros(size(mask_image)); %output image prepare
147
+        end
148
+        
149 149
         for iVoxel = 1:nVoxel % linear structure avoids 3D-Loop.
150 150
             if (mod(iVoxel,100)== 0)
151 151
                 display(sprintf('Status: %03u / %03u Timepoints, %05u / %05u Coordinates',find(fbsTimeLine == timeShiftIdx),length(fbsTimeLine),iVoxel,nVoxel));
152 152
                 pause(0.001) %flush system event queue
153 153
             end
154
-            % get surrounding coordinate-IDs within radius
155
-            sphere = fbs_buildSphere(mapping,iVoxel,radius,vdim);
156
-%             pause
157
-
158
-            %build svm inputmatrix
159
-            svmdata = [];
160
-            svmlabel = [];
161
-            anyvoxel = 1;
162
-            for pstConditionGroup = 1:size(pst{1,anyvoxel},2)
163
-                for dp = 1:size(pst{1,anyvoxel}{1,pstConditionGroup},1) % data point
164
-                    svmlabel = [svmlabel; lm_getSVMLabel(labelMap,eventList(pstConditionGroup,1))];
165
-                    row = [];
166
-                    for voxel = 1:size(sphere,2)
167
-                        row = [row, pst{1,voxel}{1,pstConditionGroup}(dp,frameStartIdx:frameEndIdx)]; % label,[value,value,...],[value,value,...]...
154
+            for radius = radiusList
155
+                % get surrounding coordinate-IDs within radius
156
+                sphere = fbs_buildSphere(mapping,iVoxel,radius,vdim);
157
+                
158
+                %build svm inputmatrix
159
+                svmdata = [];
160
+                svmlabel = [];
161
+                anyvoxel = 1;
162
+                for pstConditionGroup = 1:size(pst{1,anyvoxel},2)
163
+                    for dp = 1:size(pst{1,anyvoxel}{1,pstConditionGroup},1) % data point
164
+                        svmlabel = [svmlabel; lm_getSVMLabel(labelMap,eventList(pstConditionGroup,1))];
165
+                        row = [];
166
+                        for voxel = 1:size(sphere,2)
167
+                            row = [row, pst{1,voxel}{1,pstConditionGroup}(dp,frameStartIdx:frameEndIdx)]; % label,[value,value,...],[value,value,...]...
168
+                        end
169
+                        svmdata  = [svmdata; row];
168 170
                     end
169
-                    svmdata  = [svmdata; row];
170 171
                 end
171
-            end
172
-
173
-            if RANDOMIZE_DATAPOINTS
174
-%                 [svmlabel svmdata]
175
-                rndindex  = randperm(length(svmlabel));
176
-                svmdata   = svmdata(rndindex,:);
177
-                svmlabel  = svmlabel(rndindex);
178
-            end
179
-            
180
-            decode = svm_single_crossval(svmlabel,svmdata,svmopts);
181
-            % save the decode value to the corresponding coordinate
182
-
183
-            coord = mapping.indexToCoordMap.get(iVoxel)
184
-            x = coord(1);
185
-            y = coord(2);
186
-            z = coord(3);
187
-            
188
-            img3D(x,y,z) = ((decode/100)-0.5)*2; % range [-1:1]
189
-            
190
-        end  %for each voxel
191
-
192
-        nii = make_nii(img3D,vdim,mask_image.hdr.hist.originator(1:3),16,...
193
-            sprintf('decode performance, time relative to onset: %g to %g sec',frameStartIdx,frameEndIdx));
194
-        save_nii(nii,fullfile(savePath,sprintf('%s-%03g',subjects{s}.name,timeShiftIdx)));
172
+                
173
+                if RANDOMIZE_DATAPOINTS
174
+                    %                 [svmlabel svmdata]
175
+                    rndindex  = randperm(length(svmlabel));
176
+                    svmdata   = svmdata(rndindex,:);
177
+                    svmlabel  = svmlabel(rndindex);
178
+                end
179
+                
180
+                decode = svm_single_crossval(svmlabel,svmdata,svmopts);
181
+                % save the decode value to the corresponding coordinate
182
+                
183
+                coord = mapping.indexToCoordMap.get(iVoxel);
184
+                x = coord(1);
185
+                y = coord(2);
186
+                z = coord(3);
187
+                
188
+                img3D{radius}(x,y,z) = ((decode/100)-0.5)*2; % range [-1:1]
189
+                
190
+            end %for each radius
191
+        end %for each voxel
192
+
193
+        for radius = radiusList
194
+            nii = make_nii(img3D{radius},vdim,mask_image.hdr.hist.originator(1:3),16,...
195
+                sprintf('decode performance, time relative to onset: %g to %g sec',frameStartIdx,frameEndIdx));
196
+            save_nii(nii,fullfile(savePath,sprintf('%s-r%g-t%+03g',subjects{s}.name,radius,timeShiftIdx)));
197
+        end
195 198
     end %for each timeslice
196 199
     display('rastering done');
197 200
     display(sprintf('result images saved to %s',savePath));