Browse code

new labels, some cleanup

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

Christoph Budziszewski authored on07/08/2009 17:23:37
Showing1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 %% subject loop
2 2
 function decode = xsvm_subject_loop(header,subjectdata,svmopts)
3
-
4
-addpath(fullfile(getTbxPath,'libsvm-mat-2.88-1'));
3
+global NODALYZE_LIBSVM;
4
+addpath(fullfile(getTbxPath,NODALYZE_LIBSVM));
5 5
 
6 6
 nSubjects = numel(subjectdata);
7 7
 if(nSubjects < 2) 
Browse code

spm2 compatibility, start change study

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

Christoph Budziszewski authored on22/05/2009 11:16:41
Showing1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 %% subject loop
2 2
 function decode = xsvm_subject_loop(header,subjectdata,svmopts)
3 3
 
4
-addpath 'libsvm-mat-2.88-1';
4
+addpath(fullfile(getTbxPath,'libsvm-mat-2.88-1'));
5 5
 
6 6
 nSubjects = numel(subjectdata);
7 7
 if(nSubjects < 2) 
Browse code

added some batch files, workaround for NAN - Bug

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

Christoph Budziszewski authored on23/04/2009 16:48:20
Showing1 changed files
... ...
@@ -8,7 +8,8 @@ if(nSubjects < 2)
8 8
     error('SVMCrossVal:xsvmSubjectLoop:tooFewSubjects','You need at least 2 Subjects in this Across-Subject analysis!');
9 9
 end
10 10
 
11
-RANDOMIZE_DATAPOINTS = 1;
11
+RANDOMIZE_DATAPOINTS = header.svmrnd;
12
+NAN_AS_ZERO = header.nantozero;
12 13
 
13 14
 decode = struct;
14 15
 decode.decodePerformance = [];
... ...
@@ -64,6 +65,11 @@ for timeIndex = 1:timeLineEnd-timeLineStart+1
64 65
             svm_train_data   = svm_train_data(rndindex,:);
65 66
             svm_train_label  = svm_train_label(rndindex);
66 67
         end
68
+        
69
+        if NAN_AS_ZERO
70
+            svm_train_data(isnan(svm_train_data))=0;
71
+        end
72
+        
67 73
 
68 74
         svmmodel = svmtrain(svm_train_label,svm_train_data,svmopts);
69 75
         
Browse code

added randomize datapoints option

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

Christoph Budziszewski authored on16/03/2009 20:09:44
Showing1 changed files
... ...
@@ -8,7 +8,7 @@ if(nSubjects < 2)
8 8
     error('SVMCrossVal:xsvmSubjectLoop:tooFewSubjects','You need at least 2 Subjects in this Across-Subject analysis!');
9 9
 end
10 10
 
11
-RANDOMIZE_DATAPOINTS = 0;
11
+RANDOMIZE_DATAPOINTS = 1;
12 12
 
13 13
 decode = struct;
14 14
 decode.decodePerformance = [];
Browse code

task-models implementet.

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

Christoph Budziszewski authored on16/03/2009 17:26:16
Showing1 changed files
... ...
@@ -4,6 +4,9 @@ function decode = xsvm_subject_loop(header,subjectdata,svmopts)
4 4
 addpath 'libsvm-mat-2.88-1';
5 5
 
6 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
7 10
 
8 11
 RANDOMIZE_DATAPOINTS = 0;
9 12
 
Browse code

first plot button. not working. Idea: 3 tasks = 3 models.

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

Christoph Budziszewski authored on16/03/2009 17:07:44
Showing1 changed files
... ...
@@ -14,6 +14,9 @@ decode.rawTimeCourse     = [];
14 14
 disp(sprintf('computinig additional datastructs for %u subjects',nSubjects));
15 15
 
16 16
 timeline = header.timeline;
17
+timeline.frameShiftStart = header.frameShift.frameShiftStart;
18
+timeline.frameShiftEnd   = header.frameShift.frameShiftEnd;
19
+timeline.decodeDuration  = header.frameShift.decodeDuration;
17 20
 
18 21
 % TimePointMatrix
19 22
 for subjectDataID = 1:nSubjects
Browse code

GUI Task Switch: selfmade TabbedPanel

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

Christoph Budziszewski authored on16/03/2009 16:03:31
Showing1 changed files
... ...
@@ -68,4 +68,6 @@ for timeIndex = 1:timeLineEnd-timeLineStart+1
68 68
     decode.decodePerformance = [decode.decodePerformance; cross_value];
69 69
     
70 70
 end
71
+
72
+disp('decode done');
71 73
 end
Browse code

moved stuff, fixing plotDecode

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

Christoph Budziszewski authored on16/03/2009 14:41:06
Showing1 changed files
... ...
@@ -1,8 +1,12 @@
1 1
 %% subject loop
2 2
 function decode = xsvm_subject_loop(header,subjectdata,svmopts)
3 3
 
4
+addpath 'libsvm-mat-2.88-1';
5
+
4 6
 nSubjects = numel(subjectdata);
5 7
 
8
+RANDOMIZE_DATAPOINTS = 0;
9
+
6 10
 decode = struct;
7 11
 decode.decodePerformance = [];
8 12
 decode.rawTimeCourse     = [];
... ...
@@ -11,6 +15,7 @@ disp(sprintf('computinig additional datastructs for %u subjects',nSubjects));
11 15
 
12 16
 timeline = header.timeline;
13 17
 
18
+% TimePointMatrix
14 19
 for subjectDataID = 1:nSubjects
15 20
     currentSubject = subjectdata{subjectDataID};
16 21
     timePointArgs.pst           = currentSubject.pst;
... ...
@@ -18,16 +23,18 @@ for subjectDataID = 1:nSubjects
18 23
     timePointArgs.eventList     = header.classDef.eventMatrix;
19 24
 
20 25
     timePointMatrix{subjectDataID} = buildTimePointMatrix(timeline,timePointArgs);
26
+    
27
+    decode.rawTimeCourse = [decode.rawTimeCourse currentSubject.pst];
21 28
 end
22 29
 
30
+% timeframe x-subject validation
23 31
 timeLineStart   = timeline.frameShiftStart;
24 32
 timeLineEnd     = timeline.frameShiftEnd;
25 33
 
26
-addpath 'libsvm-mat-2.88-1';
27
-
28 34
 display(sprintf('%u -fold cross validation for %u timeslices.\n',nSubjects,size(1:timeLineEnd-timeLineStart+1,2)));
29
-disp(sprintf('Press ANY-Key to continue.\n Use Retrun if your Keyboard lacks the ANY-Key.'));
30
-pause
35
+% disp(sprintf('Press ANY-Key to continue.\n Use Retrun if your Keyboard lacks the ANY-Key.'));
36
+% pause
37
+
31 38
 for timeIndex = 1:timeLineEnd-timeLineStart+1
32 39
     cross_value = [];
33 40
     for validationSubjectID = 1:nSubjects
... ...
@@ -46,35 +53,19 @@ for timeIndex = 1:timeLineEnd-timeLineStart+1
46 53
             end
47 54
         end
48 55
         
49
-%         display(sprintf('Time %u: validation subject: %u, validation set size %g, training set size %g with %u subjects',...
50
-%             timeIndex, validationSubjectID, numel(svm_validation_label), numel(svm_train_label),nSubjects-1));
51
-        
56
+        if RANDOMIZE_DATAPOINTS
57
+            rndindex  = randperm(length(svm_train_label));
58
+            svm_train_data   = svm_train_data(rndindex,:);
59
+            svm_train_label  = svm_train_label(rndindex);
60
+        end
61
+
52 62
         svmmodel = svmtrain(svm_train_label,svm_train_data,svmopts);
53 63
         
54 64
         [plabel accuracy dvalue] = svmpredict(svm_validation_label,svm_validation_data,svmmodel,'');
55 65
         cross_value = [cross_value accuracy(1)];
56 66
         
57 67
     end
58
-    decode.decodePerformance = [decode.decodePerformance mean(cross_value)];
59
-%     decode.rawTimeCourse = [decode.rawTimeCourse cross_value];
60
-    
61
-%         decode.(namehelper)         = calculateDecodePerformance(header,currentSubject,svmopts);
62
-% 
63
-%         display('... done');
64
-%         display('restoring warnings');
65
-%         warning(warning_state);
66
-% 
67
-%         decode.decodePerformance    = [decode.decodePerformance decode.(namehelper).decodePerformance];
68
-%         decode.rawTimeCourse        = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];
69
-
70
-%         assignin('base','decode',decode);
71
-
72
-        %         if RANDOMIZE_DATAPOINTS
73
-        %         rndindex  = randperm(length(svmlabel));
74
-        %         svmdata   = svmdata(rndindex,:);
75
-        %         svmlabel  = svmlabel(rndindex);
76
-        %         end
77
-
68
+    decode.decodePerformance = [decode.decodePerformance; cross_value];
78 69
     
79 70
 end
80 71
 end
Browse code

nSubject-fold cross validation. visualization still missing.

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

Christoph Budziszewski authored on16/03/2009 13:50:49
Showing1 changed files
... ...
@@ -7,9 +7,7 @@ decode = struct;
7 7
 decode.decodePerformance = [];
8 8
 decode.rawTimeCourse     = [];
9 9
 
10
-disp(sprintf('we have %g subjects. Press ANY-Key to continue.\n Use Retrun if your Keyboard lacks the ANY-Key.',nSubjects));
11
-pause
12
-
10
+disp(sprintf('computinig additional datastructs for %u subjects',nSubjects));
13 11
 
14 12
 timeline = header.timeline;
15 13
 
... ...
@@ -27,13 +25,16 @@ timeLineEnd     = timeline.frameShiftEnd;
27 25
 
28 26
 addpath 'libsvm-mat-2.88-1';
29 27
 
28
+display(sprintf('%u -fold cross validation for %u timeslices.\n',nSubjects,size(1:timeLineEnd-timeLineStart+1,2)));
29
+disp(sprintf('Press ANY-Key to continue.\n Use Retrun if your Keyboard lacks the ANY-Key.'));
30
+pause
30 31
 for timeIndex = 1:timeLineEnd-timeLineStart+1
31
-    svm_train_label = [];
32
-    svm_train_data  = [];
33
-    svm_validation_label = [];
34
-    svm_validation_data  = [];
35
-
32
+    cross_value = [];
36 33
     for validationSubjectID = 1:nSubjects
34
+        svm_train_label = [];
35
+        svm_train_data  = [];
36
+        svm_validation_label = [];
37
+        svm_validation_data  = [];
37 38
         for subjectDataID = 1:nSubjects
38 39
             svmstruct = calculateSVMTables(timePointMatrix{subjectDataID},timeIndex);
39 40
             if subjectDataID == validationSubjectID
... ...
@@ -45,12 +46,18 @@ for timeIndex = 1:timeLineEnd-timeLineStart+1
45 46
             end
46 47
         end
47 48
         
49
+%         display(sprintf('Time %u: validation subject: %u, validation set size %g, training set size %g with %u subjects',...
50
+%             timeIndex, validationSubjectID, numel(svm_validation_label), numel(svm_train_label),nSubjects-1));
51
+        
48 52
         svmmodel = svmtrain(svm_train_label,svm_train_data,svmopts);
49 53
         
50 54
         [plabel accuracy dvalue] = svmpredict(svm_validation_label,svm_validation_data,svmmodel,'');
55
+        cross_value = [cross_value accuracy(1)];
51 56
         
52
-        accuracy(1)
53
-
57
+    end
58
+    decode.decodePerformance = [decode.decodePerformance mean(cross_value)];
59
+%     decode.rawTimeCourse = [decode.rawTimeCourse cross_value];
60
+    
54 61
 %         decode.(namehelper)         = calculateDecodePerformance(header,currentSubject,svmopts);
55 62
 % 
56 63
 %         display('... done');
... ...
@@ -68,6 +75,6 @@ for timeIndex = 1:timeLineEnd-timeLineStart+1
68 75
         %         svmlabel  = svmlabel(rndindex);
69 76
         %         end
70 77
 
71
-    end
78
+    
72 79
 end
73 80
 end
Browse code

more x-svm classification

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

Christoph Budziszewski authored on12/03/2009 17:15:24
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,73 @@
1
+%% subject loop
2
+function decode = xsvm_subject_loop(header,subjectdata,svmopts)
3
+
4
+nSubjects = numel(subjectdata);
5
+
6
+decode = struct;
7
+decode.decodePerformance = [];
8
+decode.rawTimeCourse     = [];
9
+
10
+disp(sprintf('we have %g subjects. Press ANY-Key to continue.\n Use Retrun if your Keyboard lacks the ANY-Key.',nSubjects));
11
+pause
12
+
13
+
14
+timeline = header.timeline;
15
+
16
+for subjectDataID = 1:nSubjects
17
+    currentSubject = subjectdata{subjectDataID};
18
+    timePointArgs.pst           = currentSubject.pst;
19
+    timePointArgs.labelMap      = LabelMap(header.classDef.labelCells,header.classDef.conditionCells);
20
+    timePointArgs.eventList     = header.classDef.eventMatrix;
21
+
22
+    timePointMatrix{subjectDataID} = buildTimePointMatrix(timeline,timePointArgs);
23
+end
24
+
25
+timeLineStart   = timeline.frameShiftStart;
26
+timeLineEnd     = timeline.frameShiftEnd;
27
+
28
+addpath 'libsvm-mat-2.88-1';
29
+
30
+for timeIndex = 1:timeLineEnd-timeLineStart+1
31
+    svm_train_label = [];
32
+    svm_train_data  = [];
33
+    svm_validation_label = [];
34
+    svm_validation_data  = [];
35
+
36
+    for validationSubjectID = 1:nSubjects
37
+        for subjectDataID = 1:nSubjects
38
+            svmstruct = calculateSVMTables(timePointMatrix{subjectDataID},timeIndex);
39
+            if subjectDataID == validationSubjectID
40
+                svm_validation_label = svmstruct.svmlabel;
41
+                svm_validation_data  = svmstruct.svmdata;
42
+            else
43
+                svm_train_label = [svm_train_label; svmstruct.svmlabel];
44
+                svm_train_data  = [svm_train_data;  svmstruct.svmdata];
45
+            end
46
+        end
47
+        
48
+        svmmodel = svmtrain(svm_train_label,svm_train_data,svmopts);
49
+        
50
+        [plabel accuracy dvalue] = svmpredict(svm_validation_label,svm_validation_data,svmmodel,'');
51
+        
52
+        accuracy(1)
53
+
54
+%         decode.(namehelper)         = calculateDecodePerformance(header,currentSubject,svmopts);
55
+% 
56
+%         display('... done');
57
+%         display('restoring warnings');
58
+%         warning(warning_state);
59
+% 
60
+%         decode.decodePerformance    = [decode.decodePerformance decode.(namehelper).decodePerformance];
61
+%         decode.rawTimeCourse        = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];
62
+
63
+%         assignin('base','decode',decode);
64
+
65
+        %         if RANDOMIZE_DATAPOINTS
66
+        %         rndindex  = randperm(length(svmlabel));
67
+        %         svmdata   = svmdata(rndindex,:);
68
+        %         svmlabel  = svmlabel(rndindex);
69
+        %         end
70
+
71
+    end
72
+end
73
+end