spm_SVMCrossVal.m
2095645b
 function spm_SVMCrossVal
 
 
 %  Initialize and hide the GUI as it is being constructed.
     frameWidth=450;
644333a8
     frameHeight=600;
2095645b
     frame = figure('Visible','off','Position',[0,0,frameWidth,frameHeight]);
     movegui(frame,'west'); % get this thing visible on smaller displays.
     
     set(frame,'Name','SVMCrossVal Decode Performance 4 SPM');
     set(frame,'NumberTitle','off');
     set(frame,'MenuBar','none');
     set(frame,'Color',get(0,'defaultUicontrolBackgroundColor'));
     set(frame,'Resize','off');
     set(frame,'Units','normalize');
644333a8
     
     
     model.subjectMap = SubjectRoiMapping;
     nElementRows = 24;
     optionLineHeight = 1.0/nElementRows;
     controlElementHeight=optionLineHeight*(1.0/1.5)*frameHeight;
84376774
     pSubject     = uipanel(frame,'Title','Subject',          'Position',[0 optionLineHeight*19 frameWidth optionLineHeight*5]);
     pPSTH        = uipanel(frame,'Title','PSTH Options',     'Position',[0 optionLineHeight*14 frameWidth optionLineHeight*5]); 
     pCLASS       = uipanel(frame,'Title','Class Definitions','Position',[0 optionLineHeight*9  frameWidth optionLineHeight*5]); 
     pVOXEL       = uipanel(frame,'Title','Voxel Selector',   'Position',[0 optionLineHeight*3  frameWidth optionLineHeight*6]); 
644333a8
     pSVM         = uipanel(frame,'Title','SVM Options',      'Position',[0 optionLineHeight*1  frameWidth optionLineHeight*2]); 
     btnRunButton = uicontrol(frame,'Tag','run','String','run decode-performance visualiser','Position',[2 optionLineHeight*0  frameWidth controlElementHeight*1.6]);
2095645b
 
 
644333a8
     % Subject
     firstColumn  =  5.00;
     firstRow     =  1.00 * controlElementHeight;
2095645b
     
84376774
     model.subjectSelector = uicontrol(pSubject,'Style','listbox',...
                     'Min',1, 'Max',3,...
644333a8
                     'String',getSubjectCellList(model.subjectMap),...
84376774
                     'Value',5,...  % default selected item
                     'Position',[firstColumn firstRow 0.66*frameWidth controlElementHeight*6]);
644333a8
     set(model.subjectSelector,'BackgroundColor','w');
291ee33d
     
     model.txtSmoothed = createTextField(pSubject,[0.68*frameWidth firstRow  0.25*frameWidth controlElementHeight],'0');
644333a8
 
     % PSTH
     firstColumn  = 5.00;
2095645b
     secondColumn = 0.33*frameWidth;
     thirdColumn  = 0.66*frameWidth;
644333a8
 %     fourthColumn = 0.84*frameWidth;
2095645b
     
     firstRow    = 5.5*controlElementHeight;
     secondRow   = 4.5*controlElementHeight;
     thirdRow    = 3.5*controlElementHeight;
644333a8
     fourthRow   = 2.5*controlElementHeight;
     fifthRow    = 1.0*controlElementHeight;
2095645b
     
644333a8
     lStart      = createLabel(pPSTH, [secondColumn firstRow  0.33*frameWidth controlElementHeight],'Start [sec]');
     lEnd        = createLabel(pPSTH, [thirdColumn  firstRow  0.33*frameWidth controlElementHeight],'End [sec]');
     lPSTH       = createLabel(pPSTH, [firstColumn  secondRow 0.33*frameWidth controlElementHeight],'PSTH Range');
     lBaseline   = createLabel(pPSTH, [firstColumn  thirdRow  0.33*frameWidth controlElementHeight],'Baseline');
     lFrameShift = createLabel(pPSTH, [firstColumn  fourthRow 0.33*frameWidth controlElementHeight],'SVM Frame Shift');
     lFramsSize  = createLabel(pPSTH, [firstColumn  fifthRow  0.33*frameWidth controlElementHeight],'SVM Frame Size');
2095645b
     
     
644333a8
     model.txtBaselineStart   = createTextField(pPSTH,[secondColumn thirdRow  0.25*frameWidth controlElementHeight],'-22.0');
     model.txtBaselineEnd     = createTextField(pPSTH,[thirdColumn  thirdRow  0.25*frameWidth controlElementHeight],'-20.0');
     model.txtPSTHStart       = createTextField(pPSTH,[secondColumn secondRow 0.25*frameWidth controlElementHeight],'-25.0');
     model.txtPSTHEnd         = createTextField(pPSTH,[thirdColumn  secondRow 0.25*frameWidth controlElementHeight],' 20.0');
b8f957c5
     model.txtFrameShiftStart = createTextField(pPSTH,[secondColumn fourthRow 0.25*frameWidth controlElementHeight],'-20.0');
     model.txtFrameShiftEnd   = createTextField(pPSTH,[thirdColumn  fourthRow 0.25*frameWidth controlElementHeight],' 15.0');
     model.txtFrameShiftDur   = createTextField(pPSTH,[secondColumn fifthRow  0.25*frameWidth controlElementHeight],' 0');
644333a8
 
                 
     %Classes
     nClassRows = 6;
     firstColumn  = 5.00;
2095645b
     
644333a8
     firstRow    = (nClassRows-0.5)*controlElementHeight;
     secondRow   = (nClassRows-4.5)*controlElementHeight;
 
     lClassDef = createLabel(pCLASS, [firstColumn firstRow  0.66*frameWidth controlElementHeight],'<Label>,<[Event,Event,..]>,<SVM-Value>;');
     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;'));
     set(model.txtClassDef,'HorizontalAlignment','left');
     set(model.txtClassDef,'Max',20);
     set(model.txtClassDef,'Min',0);
c1c9c7d7
     set(model.txtClassDef, 'FontName', 'FixedWidth')
2095645b
     
644333a8
     %Voxel
     nVoxelRows = 8;
     firstColumn  = 5.00;
2095645b
     
644333a8
     firstRow    = (nVoxelRows-0.5)*controlElementHeight;
     secondRow   = (nVoxelRows-7.5)*controlElementHeight;
 
     lVoxelDef = createLabel(pVOXEL, [firstColumn firstRow  0.66*frameWidth controlElementHeight],'<ROI Name>,<ROI Modifier>;');
     model.txtVoxelDef = createTextField(pVOXEL,[firstColumn secondRow 0.98*frameWidth 6*controlElementHeight],...
c1c9c7d7
         sprintf('M1 l,\t[ 0, 0, 0];\nM1 l,\t[ 1, 0, 0];\nM1 l,\t[ 0, 1, 0];\nM1 l,\t[ 0, 0, 1];\n'));
644333a8
     set(model.txtVoxelDef,'HorizontalAlignment','left');
     set(model.txtVoxelDef,'Max',20);
     set(model.txtVoxelDef,'Min',0);
c1c9c7d7
     set(model.txtVoxelDef, 'FontName', 'FixedWidth')
644333a8
                 
     % SVM
     firstColumn  =  5.00;
     firstRow     =  1.00 * controlElementHeight;
 
     model.txtSVMopts = createTextField(pSVM,[firstColumn firstRow  0.66*frameWidth controlElementHeight],'-t 0 -s 0 -v 6');
291ee33d
     set(model.txtSVMopts,'Enable','on'); %inactive
644333a8
     set(model.txtSVMopts,'HorizontalAlignment','left');
 
     set(btnRunButton,'Callback',{@cbRunSVM,model}); % set here, because of model.    
2095645b
     set(frame,'Visible','on');
 end
644333a8
     
2095645b
 function label = createLabel(parent,  pos, labelText)
     label = uicontrol(parent,'Style','text','String',labelText,'Position',pos);
     set(label,'HorizontalAlignment','left');
     set(label,'Units','characters');
 %     set(label,'BackgroundColor','r');
 end
 
 function btn = createButton(parent,pos,tag,labelText,cbArgs)
     btn = uicontrol(parent,'Position',pos,'String',labelText,'tag',tag);
      set(btn,'Callback',{@cbParseVariable,cbArgs});
 %     set(btn,'BackgroundColor','b');
 end
 
 function txt = createTextField(parent,pos,model)
     txt = uicontrol(parent,'Style','edit','String',model,'Position',pos);
     set(txt,'BackgroundColor','w');
 end
 
 function drpField = createDropDown(parent,pos,selectionModel)
  drpField = uicontrol(parent,'Style','popupmenu','Position',pos);
   set(drpField,'String',selectionModel.Strings);
   set(drpField,'BackgroundColor','w');
 end
 
644333a8
 function sane = isSane(model)
     sane = 1;
 end
 
 
 function cbRunSVM(src,evnt,model)
2095645b
 
644333a8
     display('RUN');
2095645b
 
     % TODO test parameter values
     
     if isSane(model)
         set(0,'userdata',model);
 %         set(src,'Enable','off');
291ee33d
 %         assignin('base','guiParams',model);
644333a8
         classify(model)
2095645b
 %         set(src,'Enable','on');
     else
         %todo error beep!
         error('spmtoolbox:SVMCrossVal:paramcheck','please verify all parameters');
     end
                                         
 end
 
 
84376774
 function save(model)
 
 end
 
 function model = load()
 end
 
2095645b