Browse code

kleine änderungen code move

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

Christoph Budziszewski authored on08/01/2009 11:44:25
Showing5 changed files
... ...
@@ -3,6 +3,8 @@ function outputStruct = calculateDecodePerformance(inputStruct,SubjectID)
3 3
 
4 4
 addpath 'libsvm-mat-2.88-1';
5 5
 
6
+SINGLE = 1;
7
+
6 8
 outputStruct = struct;
7 9
 
8 10
 namehelper      = strcat('s',SubjectID);
... ...
@@ -66,12 +68,16 @@ maxPerformance = -inf;
66 68
         
67 69
             svmdata      = tmp(:,2:size(tmp,2));
68 70
             svmlabel     = tmp(:,1);
69
-            performance  = svmtrain(svmlabel, svmdata, svmargs);
71
+            
72
+            if SINGLE
73
+                performance  = svmtrain(svmlabel, svmdata, svmargs);
70 74
 
71
-            minPerformance = min(minPerformance,performance);
72
-            maxPerformance = max(maxPerformance,performance);
75
+                minPerformance = min(minPerformance,performance);
76
+                maxPerformance = max(maxPerformance,performance);
73 77
 
74
-            decodePerformance = [decodePerformance; performance];
78
+                decodePerformance = [decodePerformance; performance];
79
+            end
80
+            
75 81
         end
76 82
         
77 83
         outputStruct.decodePerformance  = decodePerformance;
... ...
@@ -80,215 +86,5 @@ maxPerformance = -inf;
80 86
         outputStruct.rawTimeCourse      = pst;
81 87
         outputStruct.minPerformance     = minPerformance;
82 88
         outputStruct.maxPerformance     = maxPerformance;
83
-
84
-% display(sprintf('Min CrossVal Accuracy: %g%% \t Max CrossVal Accuracy: %g%%',minPerformance,maxPerformance));
85
-end
86
-
87
-
88
-function extr = calculateImageData(voxelList,des,smoothed)
89
-
90
-dtype='PSTH';
91
-
92
-switch dtype 
93
-    case 'PSTH'
94
-        V=des.xY.VY;
95
-    case 'betas'
96
-        V=des.Vbeta;
97
-end;
98
-
99
-if V(1).fname(1)~='D'
100
-     for z=1:length(V) % Change Drive Letter!\
101
-      	V(z).fname(1) = 'D';
102
-     end; 
103
-end
104
-
105
-if (~smoothed)
106
-  for z=1:length(V) % Change Drive Letter!\
107
-      % D:....SUBJECTID\session\swfanders...
108
-      % D:....SUBJECTID\session\wfanders...
109
-      tmp = findstr(filesep,V(z).fname);
110
-      V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
111
-  end;
112
-end
113
-
114
-% rad = 0; % one voxel
115
-% opt = 1; % xyz coordinates [mm]
116
-
117
-
118
-vox = voxelList;
119
-nRoi = size(vox,1);
120
-
121
-nImg = numel(V);
122
-
123
-for k=1:nImg
124
-	extr(k) = struct(...
125
-        'val',   repmat(NaN, [1 nRoi]),...
126
-		'mean',  repmat(NaN, [1 nRoi]),...
127
-		'sum',   repmat(NaN, [1 nRoi]),...
128
-		'nvx',   repmat(NaN, [1 nRoi]),...
129
-		'posmm', repmat(NaN, [3 nRoi]),...
130
-		'posvx', repmat(NaN, [3 nRoi]));
131
-
132
-    roicenter = round(inv(V(k).mat)*[vox, ones(nRoi,1)]');
133
-
134
-	for l = 1:nRoi
135
-
136
-%         if rad==0
137
-            x = roicenter(1,l);
138
-            y = roicenter(2,l);
139
-            z = roicenter(3,l);
140
-%         else
141
-%             tmp = spm_imatrix(V(k).mat);
142
-%             vdim = tmp(7:9);
143
-%             vxrad = ceil((rad*ones(1,3))./(ones(nRoi,1)*vdim))';
144
-%             [x y z] = ndgrid(-vxrad(1,l):sign(vdim(1)):vxrad(1,l), ...
145
-%                       -vxrad(2,l):sign(vdim(2)):vxrad(2,l), ...
146
-%                       -vxrad(3,l):sign(vdim(3)):vxrad(3,l));
147
-%             sel = (x./vxrad(1,l)).^2 + (y./vxrad(2,l)).^2 + ...
148
-%                   (z./vxrad(3,l)).^2 <= 1;
149
-%             x = roicenter(1,l)+x(sel(:));
150
-%             y = roicenter(2,l)+y(sel(:));
151
-%             z = roicenter(3,l)+z(sel(:));
152
-%         end;
153
-
154
-
155
-		dat                 = spm_sample_vol(V(k), x, y, z,0);
156
-		[maxv maxi]         = max(dat);
157
-		tmp                 = V(k).mat*[x(maxi); y(maxi); z(maxi);1]; % Max Pos
158
-		extr(k).val(l)      = maxv;
159
-		extr(k).sum(l)      = sum(dat);
160
-		extr(k).mean(l)     = nanmean(dat);
161
-        extr(k).nvx(l)      = numel(dat);
162
-		extr(k).posmm(:,l)  = tmp(1:3);
163
-		extr(k).posvx(:,l)  = [x(maxi); y(maxi); z(maxi)]; % Max Pos
164
-	end;
165
-
166
-end;
167 89
 end
168 90
 
169
-% disp(sprintf('Extracted at %.1f %.1f %.1f [xyz(mm)], average of %i voxel(s) [%.1fmm radius Sphere]',vox,length(x),rad));
170
-
171
-function pst = calculatePST(des,globalStart,baselineStart,baselineEnd,globalEnd,eventList,data,sessionList)
172
-    bstart          = baselineStart;
173
-    bend            = baselineEnd;
174
-    edur            = 12;
175
-    pre             =  globalStart;
176
-    post            =  globalEnd;
177
-    res             = 1;
178
-
179
-    normz           = 'file';
180
-    pm              = 0;
181
-
182
-    lsess           = getNumberOfScans(des);
183
-    nSessions       = getNumberOfSessions(des);
184
-    tr              = 2;
185
-
186
-    [evntrow evntcol]=size(eventList);
187
-    
188
-
189
-    hsec=str2num(des.xsDes.High_pass_Filter(8:end-3)); % Highpass filter [sec] from SPM.mat
190
-
191
-    if strcmp(des.xBF.UNITS,'secs')
192
-        unitsecs=1;
193
-    end;
194
-
195
-    nScansPerSession=getNumberOfScans(des);
196
-    %stime=[0:tr:max(nScansPerSession)*tr+post-tr]; % Stimulus time for raw data plot
197
-    stime=0:tr:max(nScansPerSession)*tr+round(post/tr)*tr-tr; % Stimulus time for raw data plot
198
-
199
-
200
-
201
-    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202
-    % RUN
203
-    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204
-
205
-
206
-    % Digital Highpass
207
-    Rp=0.5;
208
-    Rs=20;
209
-    NO=1;
210
-    Wp=1/((1/2/tr)/(1/hsec));
211
-    [B, A] = ellip(NO,Rp,Rs,Wp,'high');
212
-
213
-    sdata(1:max(nScansPerSession)+round(post/tr),1:nSessions)=nan; % Open Data Matrix
214
-    for z=1:nSessions % Fill Data Matrix sessionwise
215
-        sdata(1:nScansPerSession(z),z)=data(sum(nScansPerSession(1:z))-nScansPerSession(z)+1:sum(nScansPerSession(1:z)))';
216
-    end;
217
-%         usdata=sdata; % Keep unfiltered data
218
-
219
-    sdatamean=nanmean(nanmean(sdata(:,:)));
220
-    for z=1:nSessions
221
-%             X(:,z)=[1:1:max(nScansPerSession)]'; % #Volume
222
-        sdata(1:nScansPerSession(z),z)=filtfilt(B,A,sdata(1:nScansPerSession(z),z)); %Filter Data (Highpass)
223
-    end;
224
-    sdata=sdata+sdatamean;
225
-
226
-
227
-    %%%%Parametric Modulation Modus%%%%
228
-    if pm %Find Parameters for Event of Interest
229
-        [imods modss mods erow evntrow eventList] = getParametricMappingEvents(eventList,evntrow,des,pmf);
230
-    end;
231
-    %%%%PM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232
-
233
-
234
-    for zr=1:evntrow
235
-        n{zr}=0;
236
-        nn{zr}=0; 
237
-        nnn{zr}=0;
238
-        sstart{zr}=1;
239
-    end;
240
-
241
-
242
-    sesst0=0; 
243
-    for sessionID=sessionList
244
-        if sessionID>1
245
-            sesst0(sessionID)=sum(lsess(1:sessionID-1))*tr;  
246
-        end;
247
-        for zr=1:evntrow  %LABEL NUMBER, EVENT GROUP
248
-            sstart{zr}=n{zr}+1;
249
-            for ze=1:evntcol % EVENT INDEX in EventList
250
-                if ze==1 || (ze>1 && eventList(zr,ze)~=eventList(zr,ze-1))
251
-                    for zz=1:length(des.Sess(sessionID).U(eventList(zr,ze)).ons) % EVENT REPETITION NUMBER
252
-                        if ~unitsecs
253
-                            des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)=(des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)-1)*tr;
254
-                            des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)=(des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)-1)*tr;
255
-                        end;
256
-
257
-                        nnn{zr}=nnn{zr}+1; % INFO for rawdataplot start
258
-                        if des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)<edur
259
-                            mev{zr}(nnn{zr},1:2)=[des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+sesst0(sessionID) edur]; % modeled event [onset length]
260
-                        else
261
-                            mev{zr}(nnn{zr},1:2)=[des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+sesst0(sessionID) des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)];
262
-                        end; % INFO for rawdataplot end
263
-
264
-                        n{zr}=n{zr}+1;
265
-                        pst{zr}(n{zr},:)=interp1(stime,sdata(:,sessionID),[des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+pre:res:des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+post],'linear');
266
-                        if strcmp(normz,'epoc')
267
-                            bline=nanmean(pst{zr}(n{zr},round(-pre/res+(bstart)/res+1):round(-pre/res+(bend)/res+1)));
268
-                            if isnan(bline)
269
-                                pst{zr}(n{zr},1:-pre/res+post/res+1)=nan;
270
-                            else
271
-%                                     nn{zr}=nn{zr}+1;
272
-                                pst{zr}(n{zr},:)=(pst{zr}(n{zr},:)-bline)/bline*100; % 'epoch-based' normalization
273
-                            end;
274
-                        end;
275
-                    end;
276
-                end;
277
-            end;
278
-            if ~strcmp(normz,'epoc')
279
-                bline(zr)=nanmean(nanmean(pst{zr}(sstart{zr}:n{zr},-pre/res+(bstart)/res+1:-pre/res+(bend)/res+1)));
280
-                bstd(zr)=nanmean(nanstd(pst{zr}(sstart{zr}:n{zr},-pre/res+(bstart)/res+1:-pre/res+(bend)/res+1)));
281
-                nn{zr}=n{zr};
282
-            end;
283
-        end;
284
-        if strcmp(normz,'filz')
285
-            for zr=1:evntrow
286
-                pst{zr}(sstart{zr}:n{zr},:)=(pst{zr}(sstart{zr}:n{zr},:)-mean(bline))/mean(bstd); % session-based z-score normalization
287
-            end;
288
-        elseif strcmp(normz,'file')
289
-            for zr=1:evntrow
290
-                pst{zr}(sstart{zr}:n{zr},:)=(pst{zr}(sstart{zr}:n{zr},:)-mean(bline))/mean(bline)*100; % session-based normalization
291
-            end;
292
-        end;
293
-    end;
294
-end
... ...
@@ -36,9 +36,6 @@ end
36 36
         calculateParams.eventList       = classStruct.eventMatrix; %[9,11,13; 10,12,14];
37 37
 %         calculateParams.eventList       = getPSTEventMatrix(calculateParams.labelMap);
38 38
         
39
-%         params = struct;
40
-%         params.nClasses = 2;
41
-        
42 39
         subjectSelection = getSubjectIDString(paramModel);
43 40
         decode = struct;
44 41
         decode.decodePerformance = [];
... ...
@@ -53,26 +50,21 @@ end
53 50
             display('... done.');
54 51
 
55 52
             %% calculate
56
-            display(sprintf('calculating cross-validation performance time-shift for Subject %s. Please Wait. ...',SubjectID));
57 53
             calculateParams.(namehelper).des             = spm.SPM;
58 54
             calculateParams.(namehelper).voxelList       = parseVoxelList(paramModel,SubjectID);
59
-            
60 55
             assignin('base','calculateParams',calculateParams);
61
-            
62
-    %         [decodeTable rawTimeCourse] = calculateDecodePerformance(spm,params.frameShiftStart,params.frameShiftEnd,params.xTimeWindow,params.svmopts,1:4,params.sessionList,params.voxelList,params.classList,params.labelMap,params.normalize);
56
+
57
+            display(sprintf('calculating cross-validation performance time-shift for Subject %s. Please Wait. ...',SubjectID));
63 58
             display('switching off all warnings');
64
-            warning_state = warning('off','all');
59
+            warning_state               = warning('off','all');
65 60
             display('calculating ...');
66
-            decode.(namehelper) = calculateDecodePerformance(calculateParams,SubjectID);
61
+            decode.(namehelper)         = calculateDecodePerformance(calculateParams,SubjectID);
67 62
             display('... done');
68 63
             display('restoring warnings');
69 64
             warning(warning_state);
70 65
             
71
-            decode.decodePerformance = [decode.decodePerformance decode.(namehelper).decodePerformance];
72
-            decode.rawTimeCourse = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];
73
-  
74
-            
75
-%             display(sprintf('Min CrossVal Accuracy: %g%% \t Max CrossVal Accuracy: %g%%',decode.minPerformance,decode.maxPerformance));
66
+            decode.decodePerformance    = [decode.decodePerformance decode.(namehelper).decodePerformance];
67
+            decode.rawTimeCourse        = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];
76 68
 
77 69
             assignin('base','decode',decode);
78 70
         end
... ...
@@ -80,10 +72,10 @@ end
80 72
         display('Finished calculations.');
81 73
         display('Plotting...');
82 74
 
83
-        plotParams = struct;
84
-        plotParams.psthStart = calculateParams.psthStart;
85
-        plotParams.psthEnd   = calculateParams.psthEnd;
86
-        plotParams.nClasses  = length(calculateParams.classList);
75
+        plotParams                   = struct;
76
+        plotParams.psthStart         = calculateParams.psthStart;
77
+        plotParams.psthEnd           = calculateParams.psthEnd;
78
+        plotParams.nClasses          = length(calculateParams.classList);
87 79
         
88 80
         plotParams.frameShiftStart   = calculateParams.frameShiftStart;
89 81
         plotParams.frameShiftEnd     = calculateParams.frameShiftEnd;
90 82
new file mode 100644
... ...
@@ -0,0 +1,80 @@
1
+function extr = calculateImageData(voxelList,des,smoothed)
2
+
3
+dtype='PSTH';
4
+
5
+switch dtype 
6
+    case 'PSTH'
7
+        V=des.xY.VY;
8
+    case 'betas'
9
+        V=des.Vbeta;
10
+end;
11
+
12
+if V(1).fname(1)~='D'
13
+     for z=1:length(V) % Change Drive Letter!\
14
+      	V(z).fname(1) = 'D';
15
+     end; 
16
+end
17
+
18
+if (~smoothed)
19
+  for z=1:length(V) % Change Drive Letter!\
20
+      % D:....SUBJECTID\session\swfanders...
21
+      % D:....SUBJECTID\session\wfanders...
22
+      tmp = findstr(filesep,V(z).fname);
23
+      V(z).fname = strcat(V(z).fname(1:tmp(end)),V(z).fname(tmp(end)+2:end));
24
+  end;
25
+end
26
+
27
+% rad = 0; % one voxel
28
+% opt = 1; % xyz coordinates [mm]
29
+
30
+
31
+vox = voxelList;
32
+nRoi = size(vox,1);
33
+
34
+nImg = numel(V);
35
+
36
+for k=1:nImg
37
+	extr(k) = struct(...
38
+        'val',   repmat(NaN, [1 nRoi]),...
39
+		'mean',  repmat(NaN, [1 nRoi]),...
40
+		'sum',   repmat(NaN, [1 nRoi]),...
41
+		'nvx',   repmat(NaN, [1 nRoi]),...
42
+		'posmm', repmat(NaN, [3 nRoi]),...
43
+		'posvx', repmat(NaN, [3 nRoi]));
44
+
45
+    roicenter = round(inv(V(k).mat)*[vox, ones(nRoi,1)]');
46
+
47
+	for l = 1:nRoi
48
+
49
+%         if rad==0
50
+            x = roicenter(1,l);
51
+            y = roicenter(2,l);
52
+            z = roicenter(3,l);
53
+%         else
54
+%             tmp = spm_imatrix(V(k).mat);
55
+%             vdim = tmp(7:9);
56
+%             vxrad = ceil((rad*ones(1,3))./(ones(nRoi,1)*vdim))';
57
+%             [x y z] = ndgrid(-vxrad(1,l):sign(vdim(1)):vxrad(1,l), ...
58
+%                       -vxrad(2,l):sign(vdim(2)):vxrad(2,l), ...
59
+%                       -vxrad(3,l):sign(vdim(3)):vxrad(3,l));
60
+%             sel = (x./vxrad(1,l)).^2 + (y./vxrad(2,l)).^2 + ...
61
+%                   (z./vxrad(3,l)).^2 <= 1;
62
+%             x = roicenter(1,l)+x(sel(:));
63
+%             y = roicenter(2,l)+y(sel(:));
64
+%             z = roicenter(3,l)+z(sel(:));
65
+%         end;
66
+
67
+
68
+		dat                 = spm_sample_vol(V(k), x, y, z,0);
69
+		[maxv maxi]         = max(dat);
70
+		tmp                 = V(k).mat*[x(maxi); y(maxi); z(maxi);1]; % Max Pos
71
+		extr(k).val(l)      = maxv;
72
+		extr(k).sum(l)      = sum(dat);
73
+		extr(k).mean(l)     = nanmean(dat);
74
+        extr(k).nvx(l)      = numel(dat);
75
+		extr(k).posmm(:,l)  = tmp(1:3);
76
+		extr(k).posvx(:,l)  = [x(maxi); y(maxi); z(maxi)]; % Max Pos
77
+	end;
78
+
79
+end;
80
+end
0 81
\ No newline at end of file
1 82
new file mode 100644
... ...
@@ -0,0 +1,124 @@
1
+function pst = calculatePST(des,globalStart,baselineStart,baselineEnd,globalEnd,eventList,data,sessionList)
2
+    bstart          = baselineStart;
3
+    bend            = baselineEnd;
4
+    edur            = 12;
5
+    pre             =  globalStart;
6
+    post            =  globalEnd;
7
+    res             = 1;
8
+
9
+    normz           = 'file';
10
+    pm              = 0;
11
+
12
+    lsess           = getNumberOfScans(des);
13
+    nSessions       = getNumberOfSessions(des);
14
+    tr              = 2;
15
+
16
+    [evntrow evntcol]=size(eventList);
17
+    
18
+
19
+    hsec=str2num(des.xsDes.High_pass_Filter(8:end-3)); % Highpass filter [sec] from SPM.mat
20
+
21
+    if strcmp(des.xBF.UNITS,'secs')
22
+        unitsecs=1;
23
+    end;
24
+
25
+    nScansPerSession=getNumberOfScans(des);
26
+    %stime=[0:tr:max(nScansPerSession)*tr+post-tr]; % Stimulus time for raw data plot
27
+    stime=0:tr:max(nScansPerSession)*tr+round(post/tr)*tr-tr; % Stimulus time for raw data plot
28
+
29
+
30
+
31
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32
+    % RUN
33
+    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34
+
35
+
36
+    % Digital Highpass
37
+    Rp=0.5;
38
+    Rs=20;
39
+    NO=1;
40
+    Wp=1/((1/2/tr)/(1/hsec));
41
+    [B, A] = ellip(NO,Rp,Rs,Wp,'high');
42
+
43
+    sdata(1:max(nScansPerSession)+round(post/tr),1:nSessions)=nan; % Open Data Matrix
44
+    for z=1:nSessions % Fill Data Matrix sessionwise
45
+        sdata(1:nScansPerSession(z),z)=data(sum(nScansPerSession(1:z))-nScansPerSession(z)+1:sum(nScansPerSession(1:z)))';
46
+    end;
47
+%         usdata=sdata; % Keep unfiltered data
48
+
49
+    sdatamean=nanmean(nanmean(sdata(:,:)));
50
+    for z=1:nSessions
51
+%             X(:,z)=[1:1:max(nScansPerSession)]'; % #Volume
52
+        sdata(1:nScansPerSession(z),z)=filtfilt(B,A,sdata(1:nScansPerSession(z),z)); %Filter Data (Highpass)
53
+    end;
54
+    sdata=sdata+sdatamean;
55
+
56
+
57
+    %%%%Parametric Modulation Modus%%%%
58
+    if pm %Find Parameters for Event of Interest
59
+        [imods modss mods erow evntrow eventList] = getParametricMappingEvents(eventList,evntrow,des,pmf);
60
+    end;
61
+    %%%%PM%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62
+
63
+
64
+    for zr=1:evntrow
65
+        n{zr}=0;
66
+        nn{zr}=0; 
67
+        nnn{zr}=0;
68
+        sstart{zr}=1;
69
+    end;
70
+
71
+
72
+    sesst0=0; 
73
+    for sessionID=sessionList
74
+        if sessionID>1
75
+            sesst0(sessionID)=sum(lsess(1:sessionID-1))*tr;  
76
+        end;
77
+        for zr=1:evntrow  %LABEL NUMBER, EVENT GROUP
78
+            sstart{zr}=n{zr}+1;
79
+            for ze=1:evntcol % EVENT INDEX in EventList
80
+                if ze==1 || (ze>1 && eventList(zr,ze)~=eventList(zr,ze-1))
81
+                    for zz=1:length(des.Sess(sessionID).U(eventList(zr,ze)).ons) % EVENT REPETITION NUMBER
82
+                        if ~unitsecs
83
+                            des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)=(des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)-1)*tr;
84
+                            des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)=(des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)-1)*tr;
85
+                        end;
86
+
87
+                        nnn{zr}=nnn{zr}+1; % INFO for rawdataplot start
88
+                        if des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)<edur
89
+                            mev{zr}(nnn{zr},1:2)=[des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+sesst0(sessionID) edur]; % modeled event [onset length]
90
+                        else
91
+                            mev{zr}(nnn{zr},1:2)=[des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+sesst0(sessionID) des.Sess(sessionID).U(eventList(zr,ze)).dur(zz)];
92
+                        end; % INFO for rawdataplot end
93
+
94
+                        n{zr}=n{zr}+1;
95
+                        pst{zr}(n{zr},:)=interp1(stime,sdata(:,sessionID),[des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+pre:res:des.Sess(sessionID).U(eventList(zr,ze)).ons(zz)+post],'linear');
96
+                        if strcmp(normz,'epoc')
97
+                            bline=nanmean(pst{zr}(n{zr},round(-pre/res+(bstart)/res+1):round(-pre/res+(bend)/res+1)));
98
+                            if isnan(bline)
99
+                                pst{zr}(n{zr},1:-pre/res+post/res+1)=nan;
100
+                            else
101
+%                                     nn{zr}=nn{zr}+1;
102
+                                pst{zr}(n{zr},:)=(pst{zr}(n{zr},:)-bline)/bline*100; % 'epoch-based' normalization
103
+                            end;
104
+                        end;
105
+                    end;
106
+                end;
107
+            end;
108
+            if ~strcmp(normz,'epoc')
109
+                bline(zr)=nanmean(nanmean(pst{zr}(sstart{zr}:n{zr},-pre/res+(bstart)/res+1:-pre/res+(bend)/res+1)));
110
+                bstd(zr)=nanmean(nanstd(pst{zr}(sstart{zr}:n{zr},-pre/res+(bstart)/res+1:-pre/res+(bend)/res+1)));
111
+                nn{zr}=n{zr};
112
+            end;
113
+        end;
114
+        if strcmp(normz,'filz')
115
+            for zr=1:evntrow
116
+                pst{zr}(sstart{zr}:n{zr},:)=(pst{zr}(sstart{zr}:n{zr},:)-mean(bline))/mean(bstd); % session-based z-score normalization
117
+            end;
118
+        elseif strcmp(normz,'file')
119
+            for zr=1:evntrow
120
+                pst{zr}(sstart{zr}:n{zr},:)=(pst{zr}(sstart{zr}:n{zr},:)-mean(bline))/mean(bline)*100; % session-based normalization
121
+            end;
122
+        end;
123
+    end;
124
+end
0 125
\ No newline at end of file
... ...
@@ -15,6 +15,8 @@ function spm_SVMCrossVal
15 15
     set(frame,'Units','normalize');
16 16
     
17 17
     
18
+    savemenu = uimenu(frame,'Label','Save/Load');
19
+    
18 20
     model.subjectMap = SubjectRoiMapping;
19 21
     nElementRows = 24;
20 22
     optionLineHeight = 1.0/nElementRows;
... ...
@@ -38,7 +40,9 @@ function spm_SVMCrossVal
38 40
                     'Position',[firstColumn firstRow 0.66*frameWidth controlElementHeight*6]);
39 41
     set(model.subjectSelector,'BackgroundColor','w');
40 42
     
41
-    model.txtSmoothed = createTextField(pSubject,[0.68*frameWidth firstRow  0.25*frameWidth controlElementHeight],'1');
43
+    model.txtSmoothed     = createTextField(pSubject,[0.68*frameWidth firstRow  0.25*frameWidth controlElementHeight],'1');
44
+    model.txtMultisubject = createTextField(pSubject,[0.68*frameWidth firstRow*2  0.25*frameWidth controlElementHeight],'single');
45
+    set(model.txtMultisubject,'enable','off');
42 46
 
43 47
     % PSTH
44 48
     firstColumn  = 5.00;
... ...
@@ -60,12 +64,12 @@ function spm_SVMCrossVal
60 64
     lFramsSize  = createLabel(pPSTH, [firstColumn  fifthRow  0.33*frameWidth controlElementHeight],'SVM Frame Size');
61 65
     
62 66
     
63
-    model.txtBaselineStart   = createTextField(pPSTH,[secondColumn thirdRow  0.25*frameWidth controlElementHeight],'-22.0');
64
-    model.txtBaselineEnd     = createTextField(pPSTH,[thirdColumn  thirdRow  0.25*frameWidth controlElementHeight],'-20.0');
65
-    model.txtPSTHStart       = createTextField(pPSTH,[secondColumn secondRow 0.25*frameWidth controlElementHeight],'-25.0');
66
-    model.txtPSTHEnd         = createTextField(pPSTH,[thirdColumn  secondRow 0.25*frameWidth controlElementHeight],' 20.0');
67
-    model.txtFrameShiftStart = createTextField(pPSTH,[secondColumn fourthRow 0.25*frameWidth controlElementHeight],'-20.0');
68
-    model.txtFrameShiftEnd   = createTextField(pPSTH,[thirdColumn  fourthRow 0.25*frameWidth controlElementHeight],' 15.0');
67
+    model.txtPSTHStart       = createTextField(pPSTH,[secondColumn secondRow 0.25*frameWidth controlElementHeight],'-1.0');
68
+    model.txtPSTHEnd         = createTextField(pPSTH,[thirdColumn  secondRow 0.25*frameWidth controlElementHeight],' 35.0');
69
+    model.txtBaselineStart   = createTextField(pPSTH,[secondColumn thirdRow  0.25*frameWidth controlElementHeight],'-3.0');
70
+    model.txtBaselineEnd     = createTextField(pPSTH,[thirdColumn  thirdRow  0.25*frameWidth controlElementHeight],'-1.0');
71
+    model.txtFrameShiftStart = createTextField(pPSTH,[secondColumn fourthRow 0.25*frameWidth controlElementHeight],'-5.0');
72
+    model.txtFrameShiftEnd   = createTextField(pPSTH,[thirdColumn  fourthRow 0.25*frameWidth controlElementHeight],' 45.0');
69 73
     model.txtFrameShiftDur   = createTextField(pPSTH,[secondColumn fifthRow  0.25*frameWidth controlElementHeight],' 0');
70 74
 
71 75
                 
... ...
@@ -107,8 +111,35 @@ function spm_SVMCrossVal
107 111
     set(model.txtSVMopts,'HorizontalAlignment','left');
108 112
 
109 113
     set(btnRunButton,'Callback',{@cbRunSVM,model}); % set here, because of model.    
114
+    uimenu(savemenu,'Label','Save','Callback',{@mcb_save,model});
115
+    uimenu(savemenu,'Label','Load','Callback',{@mcb_load,model});
116
+
110 117
     set(frame,'Visible','on');
111 118
 end
119
+
120
+function mcb_save(src,event,model)
121
+display('SAVE');
122
+
123
+end
124
+
125
+function mcb_load(src,event,model)
126
+display('LOAD');
127
+end
128
+
129
+function sane = isSane(model)
130
+% TODO
131
+sane = 1;
132
+end
133
+
134
+function cbRunSVM(src,evnt,model)
135
+    display('RUN');
136
+    if isSane(model)
137
+        classify(model)
138
+    else
139
+        error('spmtoolbox:SVMCrossVal:paramcheck','please verify all parameters');
140
+    end
141
+end
142
+
112 143
     
113 144
 function label = createLabel(parent,  pos, labelText)
114 145
     label = uicontrol(parent,'Style','text','String',labelText,'Position',pos);
... ...
@@ -134,38 +165,6 @@ function drpField = createDropDown(parent,pos,selectionModel)
134 165
   set(drpField,'BackgroundColor','w');
135 166
 end
136 167
 
137
-function sane = isSane(model)
138
-    sane = 1;
139
-end
140
-
141
-
142
-function cbRunSVM(src,evnt,model)
143
-
144
-    display('RUN');
145
-
146
-    % TODO test parameter values
147
-    
148
-    if isSane(model)
149
-        set(0,'userdata',model);
150
-%         set(src,'Enable','off');
151
-%         assignin('base','guiParams',model);
152
-        classify(model)
153
-%         set(src,'Enable','on');
154
-    else
155
-        %todo error beep!
156
-        error('spmtoolbox:SVMCrossVal:paramcheck','please verify all parameters');
157
-    end
158
-                                        
159
-end
160
-
161
-
162
-function save(model)
163
-
164
-end
165
-
166
-function model = load()
167
-end
168
-
169 168
 
170 169
 
171 170