classify.m
644333a8
 function classify(varargin)
2095645b
 
84376774
 PROJECT_BASE_PATH = 'D:\Analyze\Choice\24pilot';
 PROJECT_RESULT_PATH = 'results\SPM.mat';
 
644333a8
 switch nargin
     case 1
         action = 'decode';
         paramModel = varargin{1};
     otherwise
         error('spmtoolbox:SVMCrossVal:arginError','Please Specify action and parameter model');
2095645b
 end
 
644333a8
     
 
2095645b
     switch(action)
     case 'clear'
         evalin('base','clear map lm SPM classList dataTimeLine decodeTable labelTimeLine svmopts trialProtocol voxelList xTimeEnd xTimeStart xTimeWindow');
       
     case 'decode'
b8f957c5
         
         
84376774
         % common params
2095645b
         calculateParams  = struct;
291ee33d
         calculateParams.smoothed        = getDouble(paramModel.txtSmoothed);
84376774
 
b8f957c5
         calculateParams.frameShiftStart = getDouble(paramModel.txtFrameShiftStart);  % -20;
         calculateParams.frameShiftEnd   = getDouble(paramModel.txtFrameShiftEnd); %15;
         calculateParams.decodeDuration  = getDouble(paramModel.txtFrameShiftDur);
         calculateParams.psthStart       = getDouble(paramModel.txtPSTHStart); % -25;
         calculateParams.psthEnd         = getDouble(paramModel.txtPSTHEnd); % 20;
         calculateParams.baselineStart   = getDouble(paramModel.txtBaselineStart); % -22;
         calculateParams.baselineEnd     = getDouble(paramModel.txtBaselineEnd); % -20;
 
         calculateParams.svmargs         = get(paramModel.txtSVMopts,'String');
2095645b
         calculateParams.sessionList     = 1:3;
b8f957c5
 
c1c9c7d7
         classStruct = parseClassDef(paramModel);
         
         calculateParams.classList       = classStruct.label; %{'<','>'};
         calculateParams.labelMap        = LabelMap(classStruct.label , classStruct.value); % LabelMap({'<','>','<+<','>+>','<+>','>+<'},{-2,-1,1,2,3,4});
         calculateParams.eventList       = classStruct.event; %[9,11,13; 10,12,14];
84376774
 
         params = struct;
         params.nClasses = 2;
c1c9c7d7
         
2095645b
         
84376774
         subjectSelection = getSubjectIDString(paramModel);
         decode = struct;
         decode.decodePerformance = [];
         decode.rawTimeCourse     = [];
2095645b
         
84376774
         for subjectCell = subjectSelection
             SubjectID = cell2mat(subjectCell);
 
             display('loading SPM.mat');
             spm = load(fullfile(PROJECT_BASE_PATH,SubjectID,PROJECT_RESULT_PATH));
 %             display('done.');
 
             %% calculate
             display(sprintf('calculating cross-validation performance time-shift for Subject %s',SubjectID));
 
             calculateParams.(SubjectID).des             = spm.SPM;
             calculateParams.(SubjectID).voxelList       = parseVoxelList(paramModel,SubjectID);
             
             assignin('base','calculateParams',calculateParams);
             
     %         [decodeTable rawTimeCourse] = calculateDecodePerformance(spm,params.frameShiftStart,params.frameShiftEnd,params.xTimeWindow,params.svmopts,1:4,params.sessionList,params.voxelList,params.classList,params.labelMap,params.normalize);
             display('switching off all warnings');
             warning_state = warning('off','all');
             
             decode.(SubjectID) = calculateDecodePerformance(calculateParams,SubjectID);
             display('restoring warnings');
             warning(warning_state);
             
             decode.decodePerformance = [decode.decodePerformance decode.(SubjectID).decodePerformance];
             decode.rawTimeCourse = [decode.rawTimeCourse decode.(SubjectID).rawTimeCourse];
   
             
 %             display(sprintf('Min CrossVal Accuracy: %g%% \t Max CrossVal Accuracy: %g%%',decode.minPerformance,decode.maxPerformance));
 
             assignin('base','decode',decode);
         end
2095645b
 
         display('Finished calculations.');
84376774
         display('Plotting...');
2095645b
 
         plotParams = struct;
         plotParams.psthStart = calculateParams.psthStart;
         plotParams.psthEnd   = calculateParams.psthEnd;
         plotParams.nClasses  = length(calculateParams.classList);
84376774
         
2095645b
         plotParams.frameShiftStart   = calculateParams.frameShiftStart;
         plotParams.frameShiftEnd     = calculateParams.frameShiftEnd;
         plotParams.decodePerformance = decode.decodePerformance;
         plotParams.rawTimeCourse     = decode.rawTimeCourse;
         
84376774
         if numel(subjectSelection) == 1
           plotParams.SubjectID         = SubjectID;
         else
           plotParams.SubjectID         = 'Multiple';
         end
 
         plotParams.smoothed          = boolToYesNoString(calculateParams.smoothed);
          
 
2095645b
         assignin('base','plotParams',plotParams);
 %         plotDecodePerformance(params.psthStart,params.psthEnd,params.nClasses,decode.decodeTable,params.frameShiftStart,params.frameShiftEnd,decode.rawTimeCourse);
         plotDecodePerformance(plotParams);
84376774
             
         display('done.');
2095645b
 
     otherwise
84376774
         display('give action command: clear, decode');
2095645b
     end
84376774
     end