Browse code

subject loop is function

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

Christoph Budziszewski authored on 28/01/2009 14:52:30
Showing 3 changed files
... ...
@@ -1,30 +1,23 @@
1
-function plotDecodePerformance(varargin)
1
+function plotDecodePerformance(timeline,inputStruct)
2 2
 
3 3
 global CROSSVAL_METHOD_DEF;
4 4
 
5 5
 PSTH_AXIS_MIN = -1;
6 6
 PSTH_AXIS_MAX = 1;
7 7
 
8
-switch nargin
9
-    
10
-    case 1
11
-        inputStruct       = cell2mat(varargin(1));
8
+        psthStart         = timeline.psthStart;
9
+        psthEnd           = timeline.psthEnd;
10
+        frameStart        = timeline.frameShiftStart;
11
+        frameEnd          = timeline.frameShiftEnd;
12 12
 
13
-        psthStart         = inputStruct.psthStart;
14
-        psthEnd           = inputStruct.psthEnd;
15 13
         nClasses          = inputStruct.nClasses;
16 14
         decodePerformance = inputStruct.decodePerformance;
17
-        frameStart        = inputStruct.frameShiftStart;
18
-        frameEnd          = inputStruct.frameShiftEnd;
19 15
         psth              = inputStruct.rawTimeCourse;
20 16
         SubjectID         = inputStruct.SubjectID;
21 17
         smoothed          = inputStruct.smoothed;
22 18
         PLOT_METHOD       = inputStruct.CROSSVAL_METHOD;
23 19
 %         CROSSVAL_METHOD_DEF = inputStruct.CROSSVAL_METHOD_DEF;
24 20
 
25
-    otherwise
26
-        error('spmtoolbox:SVMCrossVal:plotDecodePerformance:WrongArgument','Wrong Arguments');
27
-end
28 21
 
29 22
     f = figure;
30 23
     subplot(2,1,1);
... ...
@@ -1,5 +1,5 @@
1 1
 % function [decodePerformance rawTimecourse ] = calculateDecodePerformance(des,timeLineStart, timeLineEnd, decodeDuration, svmargs, conditionList, sessionList, voxelList, classList, labelMap,normalize)
2
-function outputStruct = calculateDecodePerformance(inputStruct,SubjectID)
2
+function outputStruct = calculateDecodePerformance(timeline,inputStruct,SubjectID)
3 3
 
4 4
 global CROSSVAL_METHOD_DEF;
5 5
 
... ...
@@ -14,21 +14,23 @@ outputStruct = struct;
14 14
 
15 15
 namehelper      = strcat('s',SubjectID);
16 16
 des             = inputStruct.(namehelper).des;
17
-timeLineStart   = inputStruct.frameShiftStart;
18
-timeLineEnd     = inputStruct.frameShiftEnd;
19
-decodeDuration  = inputStruct.decodeDuration;
20 17
 svmargs         = inputStruct.svmargs;
21 18
 sessionList     = inputStruct.sessionList;
22 19
 voxelList       = inputStruct.(namehelper).voxelList;
23 20
 % classList       = inputStruct.classList;
24 21
 % labelMap        = inputStruct.labelMap;
25 22
 smoothed        = inputStruct.smoothed;
26
-globalStart     = inputStruct.psthStart;
27
-globalEnd       = inputStruct.psthEnd;
28
-baselineStart   = inputStruct.baselineStart;
29
-baselineEnd     = inputStruct.baselineEnd;
30 23
 eventList       = inputStruct.eventList;
31 24
 
25
+timeLineStart   = timeline.frameShiftStart;
26
+timeLineEnd     = timeline.frameShiftEnd;
27
+decodeDuration  = timeline.decodeDuration;
28
+globalStart     = timeline.psthStart;
29
+globalEnd       = timeline.psthEnd;
30
+baselineStart   = timeline.baselineStart;
31
+baselineEnd     = timeline.baselineEnd;
32
+
33
+
32 34
 minPerformance = inf;
33 35
 maxPerformance = -inf;
34 36
         
... ...
@@ -11,25 +11,30 @@ switch nargin
11 11
     otherwise
12 12
         error('spmtoolbox:SVMCrossVal:arginError','Please Specify action and parameter model');
13 13
 end
14
+
15
+        % timeline params (claculate and plot)
16
+        timelineParams = struct;
17
+        
18
+        timelineParams.frameShiftStart = getDouble(paramModel.txtFrameShiftStart);  % -20;
19
+        timelineParams.frameShiftEnd   = getDouble(paramModel.txtFrameShiftEnd); %15;
20
+        timelineParams.decodeDuration  = getDouble(paramModel.txtFrameShiftDur);
21
+        timelineParams.psthStart       = getDouble(paramModel.txtPSTHStart); % -25;
22
+        timelineParams.psthEnd         = getDouble(paramModel.txtPSTHEnd); % 20;
23
+        timelineParams.baselineStart   = getDouble(paramModel.txtBaselineStart); % -22;
24
+        timelineParams.baselineEnd     = getDouble(paramModel.txtBaselineEnd); % -20;       
14 25
        
15 26
         % common params
16 27
         calculateParams  = struct;
17 28
         
18 29
 %         calculateParams.CROSSVAL_METHOD_DEF = CROSSVAL_METHOD_DEF;
19 30
         calculateParams.CROSSVAL_METHOD     = CROSSVAL_METHOD_DEF.svmcrossval;
31
+        calculateParams.PROJECT_BASE_PATH   = PROJECT_BASE_PATH;
32
+        calculateParams.PROJECT_RESULT_PATH = PROJECT_RESULT_PATH;
20 33
         
21 34
         calculateParams.RANDOMIZE       = 0;
22 35
         
23 36
         calculateParams.smoothed        = getChkValue(paramModel.chkSmoothed);
24 37
 
25
-        calculateParams.frameShiftStart = getDouble(paramModel.txtFrameShiftStart);  % -20;
26
-        calculateParams.frameShiftEnd   = getDouble(paramModel.txtFrameShiftEnd); %15;
27
-        calculateParams.decodeDuration  = getDouble(paramModel.txtFrameShiftDur);
28
-        calculateParams.psthStart       = getDouble(paramModel.txtPSTHStart); % -25;
29
-        calculateParams.psthEnd         = getDouble(paramModel.txtPSTHEnd); % 20;
30
-        calculateParams.baselineStart   = getDouble(paramModel.txtBaselineStart); % -22;
31
-        calculateParams.baselineEnd     = getDouble(paramModel.txtBaselineEnd); % -20;
32
-
33 38
         calculateParams.svmargs         = get(paramModel.txtSVMopts,'String');
34 39
         calculateParams.sessionList     = 1:3;
35 40
 
... ...
@@ -42,38 +47,9 @@ end
42 47
 %         calculateParams.eventList       = getPSTEventMatrix(calculateParams.labelMap);
43 48
         
44 49
         subjectSelection = getSubjectIDString(paramModel);
45
-        decode = struct;
46
-        decode.decodePerformance = [];
47
-        decode.rawTimeCourse     = [];
50
+        calculateParams.subjectSelection = subjectSelection;
48 51
         
49
-        for subjectCell = subjectSelection
50
-            SubjectID = cell2mat(subjectCell);
51
-            namehelper = strcat('s',SubjectID); %Vars can not start with numbers.
52
-
53
-            display('loading SPM.mat ...');
54
-            spm = load(fullfile(PROJECT_BASE_PATH,SubjectID,PROJECT_RESULT_PATH));
55
-            display('... done.');
56
-
57
-            % calculate
58
-            calculateParams.(namehelper).des             = spm.SPM;
59
-            calculateParams.(namehelper).voxelList       = parseVoxelList(paramModel,SubjectID);
60
-            assignin('base','calculateParams',calculateParams);
61
-
62
-            display(sprintf('calculating cross-validation performance time-shift for Subject %s. Please Wait. ...',SubjectID));
63
-            display('switching off all warnings');
64
-            warning_state               = warning('off','all');
65
-            display('calculating ...');
66
-            decode.(namehelper)         = calculateDecodePerformance(calculateParams,SubjectID);
67
-            
68
-            display('... done');
69
-            display('restoring warnings');
70
-            warning(warning_state);
71
-            
72
-            decode.decodePerformance    = [decode.decodePerformance decode.(namehelper).decodePerformance];
73
-            decode.rawTimeCourse        = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];
74
-
75
-            assignin('base','decode',decode);
76
-        end
52
+        decode = claculateMultiSubjectDecodePerformance(timelineParams,calculateParams);
77 53
 
78 54
         display('Finished calculations.');
79 55
         display('Plotting...');
... ...
@@ -83,26 +59,54 @@ end
83 59
 %         plotParams.CROSSVAL_METHOD_DEF = CROSSVAL_METHOD_DEF;
84 60
         plotParams.CROSSVAL_METHOD     = calculateParams.CROSSVAL_METHOD;
85 61
         
86
-        plotParams.psthStart         = calculateParams.psthStart;
87
-        plotParams.psthEnd           = calculateParams.psthEnd;
88 62
         plotParams.nClasses          = length(calculateParams.classList);
89
-        
90
-        plotParams.frameShiftStart   = calculateParams.frameShiftStart;
91
-        plotParams.frameShiftEnd     = calculateParams.frameShiftEnd;
63
+
92 64
         plotParams.decodePerformance = decode.decodePerformance;
93 65
         plotParams.rawTimeCourse     = decode.rawTimeCourse;
94
-        
95
-%         if numel(subjectSelection) == 1
96
-%           plotParams.SubjectID         = SubjectID;
97
-%         else
98
-          plotParams.SubjectID         = subjectSelection;
99
-%         end
100
-
66
+        plotParams.SubjectID         = subjectSelection;
101 67
         plotParams.smoothed          = boolToYesNoString(calculateParams.smoothed);
102 68
 
103 69
         assignin('base','plotParams',plotParams);
104 70
 %         plotDecodePerformance(params.psthStart,params.psthEnd,params.nClasses,decode.decodeTable,params.frameShiftStart,params.frameShiftEnd,decode.rawTimeCourse);
105
-        plotDecodePerformance(plotParams);
71
+        plotDecodePerformance(timelineParams,plotParams);
106 72
             
107 73
         display('all done.');
108
-    end
109 74
\ No newline at end of file
75
+end
76
+    
77
+
78
+%% subject loop
79
+function decode = claculateMultiSubjectDecodePerformance(timelineParams,calculateParams)
80
+decode = struct;
81
+decode.decodePerformance = [];
82
+decode.rawTimeCourse     = [];
83
+
84
+for subjectCell = subjectSelection
85
+    SubjectID = cell2mat(subjectCell);
86
+    namehelper = strcat('s',SubjectID); %Vars can not start with numbers.
87
+
88
+    display('loading SPM.mat ...');
89
+    spm = load(fullfile(calculateParams.PROJECT_BASE_PATH,SubjectID,calculateParams.PROJECT_RESULT_PATH));
90
+    display('... done.');
91
+
92
+    % calculate
93
+    calculateParams.(namehelper).des             = spm.SPM;
94
+    calculateParams.(namehelper).voxelList       = parseVoxelList(paramModel,SubjectID);
95
+    assignin('base','calculateParams',calculateParams);
96
+
97
+    display(sprintf('calculating cross-validation performance time-shift for Subject %s. Please Wait. ...',SubjectID));
98
+    display('switching off all warnings');
99
+    warning_state               = warning('off','all');
100
+    display('calculating ...');
101
+    decode.(namehelper)         = calculateDecodePerformance(timelineParams,calculateParams,SubjectID);
102
+
103
+    display('... done');
104
+    display('restoring warnings');
105
+    warning(warning_state);
106
+
107
+    decode.decodePerformance    = [decode.decodePerformance decode.(namehelper).decodePerformance];
108
+    decode.rawTimeCourse        = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];
109
+
110
+    assignin('base','decode',decode);
111
+end
112
+
113
+end
110 114
\ No newline at end of file