manual renamings, better FBS savePath (ISO-Date)
Christoph Budziszewski

Christoph Budziszewski commited on 2009-04-07 15:07:27
Zeige 8 geänderte Dateien mit 137 Einfügungen und 20 Löschungen.


git-svn-id: https://svn.discofish.de/MATLAB/spmtoolbox/SVMCrossVal@172 83ab2cfd-5345-466c-8aeb-2b2739fb922d
... ...
@@ -133,14 +133,17 @@ switch task
133 133
         assignin('base','decode',decode);
134 134
     case 'SOM'
135 135
         display('SOM');
136
-        somopts = '';
137
-        decode = som_combined_subject_batch(header,data,somopts);
136
+        disp('not implemented')
137
+
138
+    case 'X-SOM'
139
+        display('X-SOM');
140
+        somopts.size = [3 3];
141
+        somopts.lattice = 'rect';
142
+        decode = som_xsubject_performance(header,data,somopts);
138 143
         decode.header = header;
139 144
         assignin('base','decode',decode);
140
-    case 'X-SOM'
141
-        disp('not implemented')
142 145
     case 'FBS'
143
-        disp('this method is under high development.')
146
+        display('FBS');
144 147
         fbsargs.svmopts = getSvmArgs(model,1);
145 148
         header.svmrnd   = getSvmRnd(model);
146 149
         fbsargs.radius  = getSearchlightRadius(model);
... ...
@@ -1,7 +1,7 @@
1 1
 function output =  runFBSImageMaskMode(header,subjectdata,fbsargs)
2 2
 addpath('NIFTI_20090325');
3 3
 
4
-savePath = fullfile('output',sprintf('%s',date))
4
+savePath = fullfile('output',datestr(now,30));
5 5
 mkdir(savePath);
6 6
 
7 7
 args = header.args;
... ...
@@ -172,6 +172,7 @@ for s = 1:nSubjects
172 172
     
173 173
     end %for each timeslice
174 174
     display('rastering done');
175
+    display(sprintf('result images saved to %s',savePath));
175 176
     
176 177
     elapsed{s}.decode = toc;
177 178
     assignin('base','timing',elapsed);
... ...
@@ -1,12 +1,15 @@
1 1
 %% subject loop
2 2
 function decode = som_combined_subject_batch(header,subjectdata,somOpts)
3 3
 
4
+somOpts.size = [3 3];
5
+somOpts.lattice = 'rect';
6
+
4 7
 addpath 'somtoolbox2';
5 8
 
6
-nSubjects = numel(subjectdata);
7
-if(nSubjects < 2) 
8
-    error('SVMCrossVal:xsvmSubjectLoop:tooFewSubjects','You need at least 2 Subjects in this Across-Subject analysis!');
9
-end
9
+% nSubjects = numel(subjectdata);
10
+% if(nSubjects < 2) 
11
+%     error('SVMCrossVal:xsvmSubjectLoop:tooFewSubjects','You need at least 2 Subjects in this Across-Subject analysis!');
12
+% end
10 13
 
11 14
 RANDOMIZE_DATAPOINTS = 1;
12 15
 
... ...
@@ -42,17 +45,22 @@ display(sprintf('%u -fold cross validation for %u timeslices.\n',nSubjects,size(
42 45
 % pause
43 46
 
44 47
 for timeIndex = 1:timeLineEnd-timeLineStart+1
48
+    cross_value = [];
49
+    for validationSubjectID = 1:nSubjects
45 50
         svm_train_label = [];
46 51
         svm_train_data  = [];
47 52
         svm_validation_label = [];
48 53
         svm_validation_data  = [];
49 54
         for subjectDataID = 1:nSubjects
50 55
             svmstruct = calculateSVMTables(timePointMatrix{subjectDataID},timeIndex);
56
+            if subjectDataID == validationSubjectID
51 57
                 svm_validation_label = svmstruct.svmlabel;
52 58
                 svm_validation_data  = svmstruct.svmdata;
59
+            else
53 60
                 svm_train_label = [svm_train_label; svmstruct.svmlabel];
54 61
                 svm_train_data  = [svm_train_data;  svmstruct.svmdata];
55 62
             end
63
+        end
56 64
         
57 65
         if RANDOMIZE_DATAPOINTS
58 66
             rndindex  = randperm(length(svm_train_label));
... ...
@@ -60,15 +68,13 @@ for timeIndex = 1:timeLineEnd-timeLineStart+1
60 68
             svm_train_label  = svm_train_label(rndindex);
61 69
         end
62 70
 
63
-        [sD sM] = train_som(svmlabel, svmdata, somOpts)
71
+        [sD sM] = train_som(svm_train_label, svm_train_data, somOpts);
64 72
 
65
-%         [plabel accuracy dvalue] = svmpredict(svm_validation_label,svm_validation_data,svmmodel,'');
66
-        cross_value = [cross_value accuracy(1)];
73
+        performance = som_decode(sD, sM, svm_validation_data,svm_validation_label);
67 74
         
68
-    end
75
+        cross_value = [cross_value performance];
69 76
     decode.decodePerformance = [decode.decodePerformance; cross_value];
70
-    
71 77
 end
72
-
73
-disp('decode done');
78
+   display('decode done'); 
74 79
 end
80
+
... ...
@@ -0,0 +1,6 @@
1
+function decode = som_decode(sD, sM, svm_validation_data,svm_validation_label)
2
+% the number of hits in each map-unit.
3
+
4
+sValD = som_data_struct(svm_validation_data,'label',num2str(svm_validation_label));
5
+h   = som_hits(sM,sValD);
6
+bmu = som_bmus(sM, sValD, 'best');
0 7
\ No newline at end of file
... ...
@@ -0,0 +1,17 @@
1
+function [sD sM] = som_train(svmlabel, svmdata, somOptions)
2
+
3
+som_size = somOptions.size;
4
+som_lattice = somOptions.lattice;
5
+
6
+display('SOM TRAINING');
7
+addpath 'somtoolbox2';
8
+sD = som_data_struct(svmdata,'label',num2str(svmlabel));
9
+assignin('base','sD',sD);
10
+sM = som_make(sD,'msize', som_size,'lattice', som_lattice);
11
+
12
+sM = som_autolabel(sM,sD,'vote');
13
+
14
+assignin('base','sD',sD);
15
+assignin('base','sM',sM);
16
+display('type ''figure'' before visualisation');
17
+end
0 18
\ No newline at end of file
... ...
@@ -0,0 +1,79 @@
1
+%% subject loop
2
+function decode = som_xsubject_performance(header,subjectdata,somOpts)
3
+
4
+addpath 'somtoolbox2';
5
+
6
+nSubjects = numel(subjectdata);
7
+if(nSubjects < 2) 
8
+    error('SVMCrossVal:somXSubjectPerformance:tooFewSubjects','You need at least 2 Subjects in this Across-Subject analysis!');
9
+end
10
+
11
+RANDOMIZE_DATAPOINTS = 1;
12
+
13
+decode = struct;
14
+decode.decodePerformance = [];
15
+decode.rawTimeCourse     = [];
16
+
17
+disp(sprintf('computinig additional datastructs for %u subjects',nSubjects));
18
+
19
+timeline = header.timeline;
20
+timeline.frameShiftStart = header.frameShift.frameShiftStart;
21
+timeline.frameShiftEnd   = header.frameShift.frameShiftEnd;
22
+timeline.decodeDuration  = header.frameShift.decodeDuration;
23
+
24
+% TimePointMatrix
25
+for subjectDataID = 1:nSubjects
26
+    currentSubject = subjectdata{subjectDataID};
27
+    timePointArgs.pst           = currentSubject.pst;
28
+    timePointArgs.labelMap      = LabelMap(header.classDef.labelCells,header.classDef.conditionCells);
29
+    timePointArgs.eventList     = header.classDef.eventMatrix;
30
+
31
+    timePointMatrix{subjectDataID} = buildTimePointMatrix(timeline,timePointArgs);
32
+    
33
+    decode.rawTimeCourse = [decode.rawTimeCourse currentSubject.pst];
34
+end
35
+
36
+% timeframe x-subject validation
37
+timeLineStart   = timeline.frameShiftStart;
38
+timeLineEnd     = timeline.frameShiftEnd;
39
+
40
+display(sprintf('%u -fold cross validation for %u timeslices.\n',nSubjects,size(1:timeLineEnd-timeLineStart+1,2)));
41
+% disp(sprintf('Press ANY-Key to continue.\n Use Retrun if your Keyboard lacks the ANY-Key.'));
42
+% pause
43
+
44
+for timeIndex = 1:timeLineEnd-timeLineStart+1
45
+    cross_value = [];
46
+    for validationSubjectID = 1:nSubjects
47
+        svm_train_label = [];
48
+        svm_train_data  = [];
49
+        svm_validation_label = [];
50
+        svm_validation_data  = [];
51
+        for subjectDataID = 1:nSubjects
52
+            svmstruct = calculateSVMTables(timePointMatrix{subjectDataID},timeIndex);
53
+            if subjectDataID == validationSubjectID
54
+                svm_validation_label = svmstruct.svmlabel;
55
+                svm_validation_data  = svmstruct.svmdata;
56
+            else
57
+                svm_train_label = [svm_train_label; svmstruct.svmlabel];
58
+                svm_train_data  = [svm_train_data;  svmstruct.svmdata];
59
+            end
60
+        end
61
+        
62
+        if RANDOMIZE_DATAPOINTS
63
+            rndindex  = randperm(length(svm_train_label));
64
+            svm_train_data   = svm_train_data(rndindex,:);
65
+            svm_train_label  = svm_train_label(rndindex);
66
+        end
67
+
68
+        [sD sM] = som_train(svm_train_label, svm_train_data, somOpts);
69
+
70
+        performance = som_decode(sD, sM, svm_validation_data,svm_validation_label);
71
+        
72
+        cross_value = [cross_value performance];
73
+    end
74
+        
75
+    decode.decodePerformance = [decode.decodePerformance; cross_value];
76
+end
77
+   display('decode done'); 
78
+end
79
+
... ...
@@ -1,10 +1,15 @@
1 1
 function [sD sM] = train_som(svmlabel, svmdata, somOptions)
2 2
 
3
+som_size = somOptions.size;
4
+som_lattice = somOptions.lattice;
5
+
3 6
 display('SOM TRAINING');
4 7
 addpath 'somtoolbox2';
5 8
 sD = som_data_struct(svmdata,'label',num2str(svmlabel));
6 9
 assignin('base','sD',sD);
7
-sM = som_make(sD,'msize', [3 3],'lattice', 'hexa');
10
+sM = som_make(sD,'msize', som_size,'lattice', som_lattice);
11
+
12
+sM = som_autolabel(sM,sD,'vote');
8 13
 
9 14
 assignin('base','sD',sD);
10 15
 assignin('base','sM',sM);
... ...
@@ -335,7 +335,7 @@ pSOM = uipanel(parent,'Units','normalized','Position',[0.5 0.4 0.5 0.4]);
335 335
     set(pSOM,'Title','SOM Classification');
336 336
     set(pSOM,'BackgroundColor',basecolor);
337 337
 
338
-    model.txtSOMopts = createTextField(pSOM,[0 0.75 1 0.25],'4x3 rect');
338
+    model.txtSOMopts = createTextField(pSOM,[0 0.75 1 0.25],'3x3 rect');
339 339
     set(model.txtSOMopts,'HorizontalAlignment','left');
340 340
     set(model.txtSOMopts,'Enable','off');
341 341
 
... ...
@@ -351,7 +351,7 @@ pSOM = uipanel(parent,'Units','normalized','Position',[0.5 0.4 0.5 0.4]);
351 351
     btnRunXSOM = uicontrol(pSOM,'String','run SOM X-Subject validation',...
352 352
         'Units','normalized',...
353 353
         'Position',[0.0 0.0 1 0.25]);
354
-    set(btnRunXSOM,'Enable','off');
354
+    set(btnRunXSOM,'Enable','on');
355 355
     
356 356
 pSearchlight = uipanel(parent,'Units','normalized','Position',[0.0 0.1 1 0.3]);
357 357
     set(pSearchlight,'Title','Spatiotemporal FB classification');
358 358