Browse code

gui layout finished

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

Christoph Budziszewski authored on17/12/2008 16:12:53
Showing3 changed files
... ...
@@ -1,19 +1,29 @@
1
-function classify(action)
1
+function classify(varargin)
2 2
 
3
-if ~exist('action','var')
4
-    action='no action';
3
+switch nargin
4
+    case 0
5
+        action = 'decode';
6
+        SubjectID = 'JZ006';
7
+    case 1
8
+        action = 'decode';
9
+        paramModel = varargin{1};
10
+    otherwise
11
+        error('spmtoolbox:SVMCrossVal:arginError','Please Specify action and parameter model');
5 12
 end
6 13
 
14
+    
15
+
7 16
     switch(action)
8 17
     case 'clear'
9 18
         evalin('base','clear map lm SPM classList dataTimeLine decodeTable labelTimeLine svmopts trialProtocol voxelList xTimeEnd xTimeStart xTimeWindow');
10 19
       
11 20
     case 'decode'
12
-    
13
-
14
-
21
+        tmp_sidx =  get(paramModel.subjectSelector,'Value');
22
+        tmp_cellList = getSubjectCellList(paramModel.subjectMap);
23
+        SubjectID = cell2mat(tmp_cellList(tmp_sidx));
24
+        
15 25
         display('loading SPM.mat');
16
-        SubjectID = 'JZ006';
26
+%         SubjectID = 'JZ006';
17 27
 %         SubjectID = 'AI020';
18 28
 %         SubjectID = 'HG027';
19 29
         spm = load(fullfile('D:\Analyze\Choice\24pilot',SubjectID,'results\SPM.mat'));
... ...
@@ -56,7 +66,7 @@ end
56 66
         calculateParams.des             = spm.SPM;
57 67
         calculateParams.frameShiftStart = -20;
58 68
         calculateParams.frameShiftEnd   = 15;
59
-        calculateParams.decodeDuration  = 1;
69
+        calculateParams.decodeDuration  = 0;
60 70
         calculateParams.svmargs         = '-t 0 -s 0 -v 6';
61 71
         calculateParams.sessionList     = 1:3;
62 72
         calculateParams.voxelList       = voxelList;
... ...
@@ -93,46 +103,8 @@ end
93 103
 %         plotDecodePerformance(params.psthStart,params.psthEnd,params.nClasses,decode.decodeTable,params.frameShiftStart,params.frameShiftEnd,decode.rawTimeCourse);
94 104
         plotDecodePerformance(plotParams);
95 105
 
96
-        case 'gen'
97
-            center = '[-39 -33 67]';
98
-            sessionList = '1:3';
99
-            conditionList = '1:2';
100
-            radius = 3;
101
-            normalize = 1;
102
-
103
-            cmd=sprintf(...
104
-                '[label data] = generateDataMatrix(generateVoxelList(%s,%d), generateTrialProtocol(%s,%s),%d);',...
105
-                center,radius,sessionList,conditionList,normalize);
106
-
107
-            %     assignin('base','label',label);
108
-            %     assignin('base','data',data);
109
-
110
-    case 'norm'
111
-        cmd = ['for i=1:size(data,2)'...
112
-            'data(:,i)=data(:,i)/std(data(:,i));'...
113
-        'end;'];
114
-        
115
-    case 'xtrain'
116
-        svmargs = '-t 0'; %linear kernel
117
-        svmargs = [svmargs '-v 4'];
118
-        
119
-        cmd=sprintf('model = svmtrain(label,data,''%s'')',svmargs);
120
-        
121
-    case 'train'
122
-        svmargs = '-t 0'; %linear kernel
123
-%         svmargs = [svmargs '-v 4'];
124
-        
125
-        cmd=sprintf('model = svmtrain(label,data,%s)',svmargs);
126
-       
127
-    case 'pred'
128
-        cmd = '[predicted_label, accuracy, decision_values] = svmpredict(label, data, model);';
129
-        
130 106
     otherwise
131
-        display('give action command: clear load gen (norm) xtrain train pred');
107
+        display('give action command: clear decode');
132 108
     end
133 109
     
134
-    if exist('cmd','var') 
135
-        evalin('base',cmd);
136
-    end
137
-
138 110
 end
139 111
\ No newline at end of file
... ...
@@ -44,12 +44,14 @@ end
44 44
     
45 45
     subplot(2,1,2)    
46 46
     hold on;
47
-    plot(frameStart:frameEnd, decodePerformance ,'b');
47
+    
48 48
     chanceLevel = 100/nClasses;
49 49
     goodPredictionLevel = chanceLevel*1.5;
50 50
     plot([psthStart psthEnd],[chanceLevel chanceLevel],'r');
51 51
     plot([psthStart psthEnd],[goodPredictionLevel goodPredictionLevel],'g');
52 52
     axis([psthStart psthEnd 0 100])
53
+    
54
+    plot(frameStart:frameEnd, decodePerformance ,'b');
53 55
 
54 56
     hold off;
55 57
 
... ...
@@ -3,7 +3,7 @@ function spm_SVMCrossVal
3 3
 
4 4
 %  Initialize and hide the GUI as it is being constructed.
5 5
     frameWidth=450;
6
-    frameHeight=450;
6
+    frameHeight=600;
7 7
     frame = figure('Visible','off','Position',[0,0,frameWidth,frameHeight]);
8 8
     movegui(frame,'west'); % get this thing visible on smaller displays.
9 9
     
... ...
@@ -13,143 +13,98 @@ function spm_SVMCrossVal
13 13
     set(frame,'Color',get(0,'defaultUicontrolBackgroundColor'));
14 14
     set(frame,'Resize','off');
15 15
     set(frame,'Units','normalize');
16
+    
17
+    
18
+    model.subjectMap = SubjectRoiMapping;
19
+    nElementRows = 24;
20
+    optionLineHeight = 1.0/nElementRows;
21
+    controlElementHeight=optionLineHeight*(1.0/1.5)*frameHeight;
22
+    pSubject     = uipanel(frame,'Title','Subject',          'Position',[0 optionLineHeight*22 frameWidth optionLineHeight*2]);
23
+    pPSTH        = uipanel(frame,'Title','PSTH Options',     'Position',[0 optionLineHeight*17 frameWidth optionLineHeight*5]); 
24
+    pCLASS       = uipanel(frame,'Title','Class Definitions','Position',[0 optionLineHeight*11 frameWidth optionLineHeight*6]); 
25
+    pVOXEL       = uipanel(frame,'Title','Voxel Selector',   'Position',[0 optionLineHeight*3  frameWidth optionLineHeight*8]); 
26
+    pSVM         = uipanel(frame,'Title','SVM Options',      'Position',[0 optionLineHeight*1  frameWidth optionLineHeight*2]); 
27
+    btnRunButton = uicontrol(frame,'Tag','run','String','run decode-performance visualiser','Position',[2 optionLineHeight*0  frameWidth controlElementHeight*1.6]);
16 28
 
17 29
 
18
-    optionLineHeight = 1.0/16.0;
19
-    controlElementHeight=optionLineHeight*(1.0/1.5)*frameHeight;
20
-    pMain        = uipanel(frame,'Title','Main Panel',             'Position',[0 optionLineHeight*10 frameWidth optionLineHeight*6]); 
21
-    pAdvanced    = uipanel(frame,'Title','Advanced Options',       'Position',[0 optionLineHeight*5  frameWidth optionLineHeight*5]); 
22
-    pDisplay     = uipanel(frame,'Title','Display Options',        'Position',[0 optionLineHeight*1  frameWidth optionLineHeight*4]); 
23
-    btnRunButton = uicontrol(frame,'Tag','run','String','Run PSTH','Position',[0 optionLineHeight*0  frameWidth frameHeight/16]);
30
+    % Subject
31
+    firstColumn  =  5.00;
32
+    firstRow     =  1.00 * controlElementHeight;
24 33
     
25
-    %Main
26
-     firstColumn  = 0.00*frameWidth;
27
-     secondColumn = 0.33*frameWidth;
28
-     thirdColumn  = 0.66*frameWidth;
29
-     
30
-     firstRow  = 6.3*controlElementHeight;
31
-     secondRow = 5.3*controlElementHeight;
32
-     thirdRow  = 4.3*controlElementHeight;
33
-     fourthRow = 3.3*controlElementHeight;
34
-     fifthRow  = 2.3*controlElementHeight;
35
-     sixthRow  = 1.0*controlElementHeight;
36
-     
37
-     createLabel(pMain, [firstColumn firstRow  0.33*frameWidth controlElementHeight],'Position'); %     lPosition 
38
-     createLabel(pMain, [firstColumn secondRow 0.33*frameWidth controlElementHeight],'Voxel Sphere Radius' );%lRadius
39
-     lEvents            = createLabel(pMain, [firstColumn thirdRow  0.33*frameWidth controlElementHeight],'Event List' );
40
-     lSessions          = createLabel(pMain, [firstColumn fourthRow 0.33*frameWidth controlElementHeight],'Session List'  );
41
-     lNormalize         = createLabel(pMain, [firstColumn fifthRow  0.33*frameWidth controlElementHeight],'Normalization Method' );
42
-     lParametric        = createLabel(pMain, [firstColumn sixthRow  0.25*frameWidth controlElementHeight],'Parametric Modulation');
43
-     lParametricFactor  = createLabel(pMain, [(secondColumn+0.33*frameWidth*0.2) sixthRow 0.33*frameWidth*0.8 controlElementHeight],'Modulation Factor');
44
-
45
-     model.txtPosition  = createTextField(pMain, [secondColumn firstRow  0.33*frameWidth controlElementHeight],'0 0 0');
46
-     btnParseHReg       = createButton(pMain,    [thirdColumn  firstRow  0.33*frameWidth controlElementHeight],'hReg', 'parse hReg',model.txtPosition);
47
-
48
-     model.txtRadius    = createTextField(pMain, [secondColumn secondRow 0.33*frameWidth controlElementHeight],'3');
49
-
50
-     model.txtEvents    = createTextField(pMain, [secondColumn thirdRow  0.33*frameWidth controlElementHeight],'');
51
-     btnEvents          = createButton(pMain,    [thirdColumn  thirdRow  0.33*frameWidth controlElementHeight],'events', 'show Event List',model.txtEvents);
52
-        set(btnEvents,'Enable','off');
53
-
54
-     model.txtSessions  = createTextField(pMain, [secondColumn fourthRow 0.33*frameWidth controlElementHeight],'');
55
-
56
-     model.normalization = createDropDown(pMain, [secondColumn fifthRow  0.33*frameWidth controlElementHeight],...
57
-                           defaults.tools.psth4spm.normalizeSelectionModel);
58
-
59
-     model.chkParametric = uicontrol(pMain,'Position',[secondColumn sixthRow 0.33*frameWidth*0.2 controlElementHeight],'Style','checkbox');
60
-     model.txtParametricMappingFactor = createTextField(pMain,     [thirdColumn  sixthRow 0.33*frameWidth controlElementHeight],'1.0');
61
-        set(model.txtParametricMappingFactor,'Enable','off');
62
-        set(model.chkParametric,'Callback',{@cbToggleEnableTarget,model.txtParametricMappingFactor});
63
-
64
-     %Advanced
65
-    firstColumn  = 0.00*frameWidth;
34
+    model.subjectSelector = uicontrol(pSubject,'Style','popupmenu',...
35
+                    'String',getSubjectCellList(model.subjectMap),...
36
+                    'Value',5,...
37
+                    'Position',[firstColumn firstRow 0.66*frameWidth controlElementHeight]);
38
+    set(model.subjectSelector,'BackgroundColor','w');
39
+
40
+    % PSTH
41
+    firstColumn  = 5.00;
66 42
     secondColumn = 0.33*frameWidth;
67 43
     thirdColumn  = 0.66*frameWidth;
68
-    fourthColumn = 0.84*frameWidth;
44
+%     fourthColumn = 0.84*frameWidth;
69 45
     
70 46
     firstRow    = 5.5*controlElementHeight;
71 47
     secondRow   = 4.5*controlElementHeight;
72 48
     thirdRow    = 3.5*controlElementHeight;
73
-    fourthRow   = 2*controlElementHeight;
74
-    
75
-    lStart  = createLabel(pAdvanced, [secondColumn firstRow 0.33*frameWidth controlElementHeight],'Start [sec]');
76
-    lEnd    = createLabel(pAdvanced, [thirdColumn  firstRow 0.33*frameWidth controlElementHeight],'End [sec]');
77
-    lBaseline = createLabel(pAdvanced,[firstColumn secondRow 0.33*frameWidth controlElementHeight],'Baseline');
78
-    lTimeRange = createLabel(pAdvanced,[firstColumn thirdRow 0.33*frameWidth controlElementHeight],'Time Range (X-Axis)');
79
-    lTemporalResolutionMultiplyer = createLabel(pAdvanced, [firstColumn fourthRow 0.33*frameWidth controlElementHeight],'TR Factor');
80
-    
49
+    fourthRow   = 2.5*controlElementHeight;
50
+    fifthRow    = 1.0*controlElementHeight;
81 51
     
82
-    model.txtBaselineStart = createTextField(pAdvanced,[secondColumn secondRow 0.25*frameWidth controlElementHeight],'-3.0');
83
-    model.txtBaselineEnd = createTextField(pAdvanced,[thirdColumn secondRow 0.25*frameWidth controlElementHeight],'-1.0');
84
-    model.txtTimeRangeStart = createTextField(pAdvanced,[secondColumn thirdRow 0.25*frameWidth controlElementHeight],'-5.0');
85
-    model.txtTimeRangeEnd = createTextField(pAdvanced,[thirdColumn thirdRow 0.25*frameWidth controlElementHeight],'45.0');
52
+    lStart      = createLabel(pPSTH, [secondColumn firstRow  0.33*frameWidth controlElementHeight],'Start [sec]');
53
+    lEnd        = createLabel(pPSTH, [thirdColumn  firstRow  0.33*frameWidth controlElementHeight],'End [sec]');
54
+    lPSTH       = createLabel(pPSTH, [firstColumn  secondRow 0.33*frameWidth controlElementHeight],'PSTH Range');
55
+    lBaseline   = createLabel(pPSTH, [firstColumn  thirdRow  0.33*frameWidth controlElementHeight],'Baseline');
56
+    lFrameShift = createLabel(pPSTH, [firstColumn  fourthRow 0.33*frameWidth controlElementHeight],'SVM Frame Shift');
57
+    lFramsSize  = createLabel(pPSTH, [firstColumn  fifthRow  0.33*frameWidth controlElementHeight],'SVM Frame Size');
86 58
     
87
-
88
-    model.txtTemporalResolution = createTextField(pAdvanced,[thirdColumn fourthRow 0.18*frameWidth controlElementHeight],'');
89
-        set(model.txtTemporalResolution,'Enable','inactive');
90
-    try
91
-        tr = evalin('base','SPM.xsDes.Interscan_interval(1:end-3)');
92
-        set(model.txtTemporalResolution,'String',tr);
93
-    catch
94
-        btnParseTemporalResolution = createButton(pAdvanced,[fourthColumn fourthRow 0.15*frameWidth controlElementHeight],'TR','parse TR',model.txtTemporalResolution);
95
-    end
96
-    model.txtTemporalResolutionFactor = createTextField(pAdvanced,[secondColumn fourthRow 0.25*frameWidth controlElementHeight],'0.5');
97
-   
98
-    %Display
99
-    firstColumn  = 0.00*frameWidth;
100
-    secondColumn = 0.33*frameWidth;
101
-    thirdColumn  = 0.66*frameWidth;
102
-    
103
-    firstRow    = 4*controlElementHeight;
104
-    secondRow   = 3*controlElementHeight;
105
-    thirdRow    = 2*controlElementHeight;
106
-    fourthRow   = 0.5*controlElementHeight;
107 59
     
108
-    lAxisUpper      = createLabel(pDisplay, [firstColumn firstRow 0.33*frameWidth controlElementHeight],'Y-Axis Upper Bound');
109
-    lAxisLower      = createLabel(pDisplay, [firstColumn secondRow 0.33*frameWidth controlElementHeight],'Y-Axis Lower Bound');
110
-    lColorScheme    = createLabel(pDisplay, [firstColumn thirdRow 0.33*frameWidth controlElementHeight],'Color Scheme');
111
-    lShowLegend     = createLabel(pDisplay, [secondColumn+0.33*frameWidth*0.2 fourthRow 0.33*frameWidth controlElementHeight],'Show Legend');
112
-    lShowFiltered   = createLabel(pDisplay, [thirdColumn+0.33*frameWidth*0.2 fourthRow 0.33*frameWidth controlElementHeight],'Show Filtered');
60
+    model.txtBaselineStart   = createTextField(pPSTH,[secondColumn thirdRow  0.25*frameWidth controlElementHeight],'-22.0');
61
+    model.txtBaselineEnd     = createTextField(pPSTH,[thirdColumn  thirdRow  0.25*frameWidth controlElementHeight],'-20.0');
62
+    model.txtPSTHStart       = createTextField(pPSTH,[secondColumn secondRow 0.25*frameWidth controlElementHeight],'-25.0');
63
+    model.txtPSTHEnd         = createTextField(pPSTH,[thirdColumn  secondRow 0.25*frameWidth controlElementHeight],' 20.0');
64
+    model.txtFramsShiftStart = createTextField(pPSTH,[secondColumn fourthRow 0.25*frameWidth controlElementHeight],'-20.0');
65
+    model.txtFramsShiftEnd   = createTextField(pPSTH,[thirdColumn  fourthRow 0.25*frameWidth controlElementHeight],' 15.0');
66
+    model.txtFramsShiftDur   = createTextField(pPSTH,[secondColumn fifthRow  0.25*frameWidth controlElementHeight],' 0');
67
+
68
+                
69
+    %Classes
70
+    nClassRows = 6;
71
+    firstColumn  = 5.00;
113 72
     
114
-    model.txtYAxisUpper = createTextField(pDisplay,[secondColumn firstRow 0.33*frameWidth controlElementHeight],'0');
115
-    model.txtYAxisLower = createTextField(pDisplay,[secondColumn secondRow 0.33*frameWidth controlElementHeight],'0');
73
+    firstRow    = (nClassRows-0.5)*controlElementHeight;
74
+    secondRow   = (nClassRows-4.5)*controlElementHeight;
75
+
76
+    lClassDef = createLabel(pCLASS, [firstColumn firstRow  0.66*frameWidth controlElementHeight],'<Label>,<[Event,Event,..]>,<SVM-Value>;');
77
+    model.txtClassDef = createTextField(pCLASS,[firstColumn secondRow 0.98*frameWidth 4*controlElementHeight],sprintf('<,\t[ 9,11,13],\t-2 ;\n>,\t[10,12,14],\t-1;'));
78
+    set(model.txtClassDef,'HorizontalAlignment','left');
79
+    set(model.txtClassDef,'Max',20);
80
+    set(model.txtClassDef,'Min',0);
116 81
     
117
-    model.colorScheme = createDropDown(pDisplay,[secondColumn thirdRow 0.33*frameWidth controlElementHeight],defaults.tools.psth4spm.colorschemeSelectionModel);
82
+    %Voxel
83
+    nVoxelRows = 8;
84
+    firstColumn  = 5.00;
118 85
     
119
-    model.chkShowLegend = uicontrol(pDisplay,'Position',[secondColumn fourthRow 0.33*frameWidth*0.1 controlElementHeight],'Style','checkbox','Value',1);
120
-    model.chkShowUnfiltered = uicontrol(pDisplay,'Position',[thirdColumn fourthRow 0.33*frameWidth*0.1 controlElementHeight],'Style','checkbox','Value',1);
121
-
122
-    set(btnRunButton,'Callback',{@cbRunPSTH,model});
86
+    firstRow    = (nVoxelRows-0.5)*controlElementHeight;
87
+    secondRow   = (nVoxelRows-7.5)*controlElementHeight;
88
+
89
+    lVoxelDef = createLabel(pVOXEL, [firstColumn firstRow  0.66*frameWidth controlElementHeight],'<ROI Name>,<ROI Modifier>;');
90
+    model.txtVoxelDef = createTextField(pVOXEL,[firstColumn secondRow 0.98*frameWidth 6*controlElementHeight],...
91
+        sprintf('M1 l,\t[ 0, 0, 0];\nM1 l,\t[ 1, 0, 0];\nM1 l,\t[ 0, 1, 0];\nM1 l,\t[ 1, 0, 1];\n'));
92
+    set(model.txtVoxelDef,'HorizontalAlignment','left');
93
+    set(model.txtVoxelDef,'Max',20);
94
+    set(model.txtVoxelDef,'Min',0);
95
+                
96
+    % SVM
97
+    firstColumn  =  5.00;
98
+    firstRow     =  1.00 * controlElementHeight;
99
+
100
+    model.txtSVMopts = createTextField(pSVM,[firstColumn firstRow  0.66*frameWidth controlElementHeight],'-t 0 -s 0 -v 6');
101
+    set(model.txtSVMopts,'Enable','inactive');
102
+    set(model.txtSVMopts,'HorizontalAlignment','left');
103
+
104
+    set(btnRunButton,'Callback',{@cbRunSVM,model}); % set here, because of model.    
123 105
     set(frame,'Visible','on');
124 106
 end
125
-
126
-% this is a function callback
127
-function cbToggleEnableTarget(src,eventData,target)
128
-    if(strcmp(get(target,'Enable'),'off'))
129
-%         display('is off. set on');
130
-        set(target,'Enable','on');
131
-    else
132
-%         display('is on, set off');
133
-        set(target,'Enable','off');
134
-    end
135
-end
136
-
137
-function cbParseVariable(src,evnt,target)
138
-% display('button pressed');
139
-    switch(get(src,'Tag'))
140
-        case 'hReg'
141
-            pos = num2str(evalin('base','spm_XYZreg(''GetCoords'',hReg)')');
142
-            set(target,'String',pos);
143
-        case 'TR'
144
-            tr = evalin('base','SPM.xsDes.Interscan_interval(1:end-3)');
145
-            set(target,'String',tr);
146
-%             set(src,'Enable','off');
147
-            set(target,'Visible','on');
148
-        otherwise 
149
-            display(['no parse Rule for Button Tagged' get(src,'Tag')]);
150
-    end
151
-end
152
-
107
+    
153 108
 function label = createLabel(parent,  pos, labelText)
154 109
     label = uicontrol(parent,'Style','text','String',labelText,'Position',pos);
155 110
     set(label,'HorizontalAlignment','left');
... ...
@@ -174,15 +129,21 @@ function drpField = createDropDown(parent,pos,selectionModel)
174 129
   set(drpField,'BackgroundColor','w');
175 130
 end
176 131
 
132
+function sane = isSane(model)
133
+    sane = 1;
134
+end
135
+
136
+
137
+function cbRunSVM(src,evnt,model)
177 138
 
178
-function cbRunPSTH(src,evnt,model)
139
+    display('RUN');
179 140
 
180 141
     % TODO test parameter values
181 142
     
182 143
     if isSane(model)
183 144
         set(0,'userdata',model);
184 145
 %         set(src,'Enable','off');
185
-        evalin('base','runPSTH4SPM(SPM)');
146
+        classify(model)
186 147
 %         set(src,'Enable','on');
187 148
     else
188 149
         %todo error beep!