private/classify.m
644333a8
 function classify(varargin)
2095645b
 
e370a509
 global CROSSVAL_METHOD_DEF;
1d0d6061
 
644333a8
 switch nargin
     case 1
         paramModel = varargin{1};
6157c8a0
         %PROJECT_BASE_PATH = 'D:\Analyze\Stimolos';
         PROJECT_BASE_PATH = 'D:\Analyze\Choice\24pilot';
6985c69e
         PROJECT_RESULT_PATH = 'results\SPM.mat';
644333a8
     otherwise
         error('spmtoolbox:SVMCrossVal:arginError','Please Specify action and parameter model');
2095645b
 end
6595def8
 
         % timeline params (claculate and plot)
         timelineParams = struct;
         
         timelineParams.frameShiftStart = getDouble(paramModel.txtFrameShiftStart);  % -20;
         timelineParams.frameShiftEnd   = getDouble(paramModel.txtFrameShiftEnd); %15;
         timelineParams.decodeDuration  = getDouble(paramModel.txtFrameShiftDur);
         timelineParams.psthStart       = getDouble(paramModel.txtPSTHStart); % -25;
         timelineParams.psthEnd         = getDouble(paramModel.txtPSTHEnd); % 20;
         timelineParams.baselineStart   = getDouble(paramModel.txtBaselineStart); % -22;
         timelineParams.baselineEnd     = getDouble(paramModel.txtBaselineEnd); % -20;       
fd18aa84
        
84376774
         % common params
2095645b
         calculateParams  = struct;
1d0d6061
         
e370a509
 %         calculateParams.CROSSVAL_METHOD_DEF = CROSSVAL_METHOD_DEF;
1d0d6061
         calculateParams.CROSSVAL_METHOD     = CROSSVAL_METHOD_DEF.svmcrossval;
6595def8
         calculateParams.PROJECT_BASE_PATH   = PROJECT_BASE_PATH;
         calculateParams.PROJECT_RESULT_PATH = PROJECT_RESULT_PATH;
1d0d6061
         
         calculateParams.RANDOMIZE       = 0;
         
fd18aa84
         calculateParams.smoothed        = getChkValue(paramModel.chkSmoothed);
84376774
 
b8f957c5
         calculateParams.svmargs         = get(paramModel.txtSVMopts,'String');
2095645b
         calculateParams.sessionList     = 1:3;
b8f957c5
 
c1c9c7d7
         classStruct = parseClassDef(paramModel);
         
         
6985c69e
         calculateParams.labelMap        = LabelMap(classStruct.labelCells , classStruct.conditionCells, 'auto'); % LabelMap({'<','>','<+<','>+>','<+>','>+<'},{-2,-1,1,2,3,4}); 0 is autolabel
         calculateParams.classList       = getClasses(calculateParams.labelMap);
         calculateParams.eventList       = classStruct.eventMatrix; %[9,11,13; 10,12,14];
 %         calculateParams.eventList       = getPSTEventMatrix(calculateParams.labelMap);
         
84376774
         subjectSelection = getSubjectIDString(paramModel);
6595def8
         calculateParams.subjectSelection = subjectSelection;
2095645b
         
6595def8
         decode = claculateMultiSubjectDecodePerformance(timelineParams,calculateParams);
2095645b
 
         display('Finished calculations.');
84376774
         display('Plotting...');
2095645b
 
9478fa59
         plotParams                   = struct;
06612a42
         
e370a509
 %         plotParams.CROSSVAL_METHOD_DEF = CROSSVAL_METHOD_DEF;
06612a42
         plotParams.CROSSVAL_METHOD     = calculateParams.CROSSVAL_METHOD;
         
9478fa59
         plotParams.nClasses          = length(calculateParams.classList);
6595def8
 
2095645b
         plotParams.decodePerformance = decode.decodePerformance;
         plotParams.rawTimeCourse     = decode.rawTimeCourse;
6595def8
         plotParams.SubjectID         = subjectSelection;
84376774
         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);
6595def8
         plotDecodePerformance(timelineParams,plotParams);
84376774
             
6985c69e
         display('all done.');
6595def8
 end
     
 
 %% subject loop
 function decode = claculateMultiSubjectDecodePerformance(timelineParams,calculateParams)
 decode = struct;
 decode.decodePerformance = [];
 decode.rawTimeCourse     = [];
 
 for subjectCell = subjectSelection
     SubjectID = cell2mat(subjectCell);
     namehelper = strcat('s',SubjectID); %Vars can not start with numbers.
 
     display('loading SPM.mat ...');
     spm = load(fullfile(calculateParams.PROJECT_BASE_PATH,SubjectID,calculateParams.PROJECT_RESULT_PATH));
     display('... done.');
 
     % calculate
     calculateParams.(namehelper).des             = spm.SPM;
     calculateParams.(namehelper).voxelList       = parseVoxelList(paramModel,SubjectID);
     assignin('base','calculateParams',calculateParams);
 
     display(sprintf('calculating cross-validation performance time-shift for Subject %s. Please Wait. ...',SubjectID));
     display('switching off all warnings');
     warning_state               = warning('off','all');
     display('calculating ...');
     decode.(namehelper)         = calculateDecodePerformance(timelineParams,calculateParams,SubjectID);
 
     display('... done');
     display('restoring warnings');
     warning(warning_state);
 
     decode.decodePerformance    = [decode.decodePerformance decode.(namehelper).decodePerformance];
     decode.rawTimeCourse        = [decode.rawTimeCourse decode.(namehelper).rawTimeCourse];
 
     assignin('base','decode',decode);
 end
 
 end