7984c76d06b6a9ac6174e73a6528bee841ab95f3
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

1) %% subject loop
2) function decode = xsvm_subject_loop(header,subjectdata,svmopts)
3) 
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

4) addpath 'libsvm-mat-2.88-1';
5) 
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

6) nSubjects = numel(subjectdata);
Christoph Budziszewski task-models implementet.

Christoph Budziszewski authored 15 years ago

7) if(nSubjects < 2) 
8)     error('SVMCrossVal:xsvmSubjectLoop:tooFewSubjects','You need at least 2 Subjects in this Across-Subject analysis!');
9) end
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

10) 
Christoph Budziszewski added randomize datapoints...

Christoph Budziszewski authored 15 years ago

11) RANDOMIZE_DATAPOINTS = 1;
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

12) 
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

13) decode = struct;
14) decode.decodePerformance = [];
15) decode.rawTimeCourse     = [];
16) 
Christoph Budziszewski nSubject-fold cross validat...

Christoph Budziszewski authored 15 years ago

17) disp(sprintf('computinig additional datastructs for %u subjects',nSubjects));
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

18) 
19) timeline = header.timeline;
Christoph Budziszewski first plot button. not work...

Christoph Budziszewski authored 15 years ago

20) timeline.frameShiftStart = header.frameShift.frameShiftStart;
21) timeline.frameShiftEnd   = header.frameShift.frameShiftEnd;
22) timeline.decodeDuration  = header.frameShift.decodeDuration;
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

23) 
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

24) % TimePointMatrix
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

25) for subjectDataID = 1:nSubjects
26)     currentSubject = subjectdata{subjectDataID};
27)     timePointArgs.pst           = currentSubject.pst;
28)     timePointArgs.labelMap      = LabelMap(header.classDef.labelCells,header.classDef.conditionCells);
29)     timePointArgs.eventList     = header.classDef.eventMatrix;
30) 
31)     timePointMatrix{subjectDataID} = buildTimePointMatrix(timeline,timePointArgs);
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

32)     
33)     decode.rawTimeCourse = [decode.rawTimeCourse currentSubject.pst];
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

34) end
35) 
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

36) % timeframe x-subject validation
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

37) timeLineStart   = timeline.frameShiftStart;
38) timeLineEnd     = timeline.frameShiftEnd;
39) 
Christoph Budziszewski nSubject-fold cross validat...

Christoph Budziszewski authored 15 years ago

40) display(sprintf('%u -fold cross validation for %u timeslices.\n',nSubjects,size(1:timeLineEnd-timeLineStart+1,2)));
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

41) % disp(sprintf('Press ANY-Key to continue.\n Use Retrun if your Keyboard lacks the ANY-Key.'));
42) % pause
43) 
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

44) for timeIndex = 1:timeLineEnd-timeLineStart+1
Christoph Budziszewski nSubject-fold cross validat...

Christoph Budziszewski authored 15 years ago

45)     cross_value = [];
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

46)     for validationSubjectID = 1:nSubjects
Christoph Budziszewski nSubject-fold cross validat...

Christoph Budziszewski authored 15 years ago

47)         svm_train_label = [];
48)         svm_train_data  = [];
49)         svm_validation_label = [];
50)         svm_validation_data  = [];
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

51)         for subjectDataID = 1:nSubjects
52)             svmstruct = calculateSVMTables(timePointMatrix{subjectDataID},timeIndex);
53)             if subjectDataID == validationSubjectID
54)                 svm_validation_label = svmstruct.svmlabel;
55)                 svm_validation_data  = svmstruct.svmdata;
56)             else
57)                 svm_train_label = [svm_train_label; svmstruct.svmlabel];
58)                 svm_train_data  = [svm_train_data;  svmstruct.svmdata];
59)             end
60)         end
61)         
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

62)         if RANDOMIZE_DATAPOINTS
63)             rndindex  = randperm(length(svm_train_label));
64)             svm_train_data   = svm_train_data(rndindex,:);
65)             svm_train_label  = svm_train_label(rndindex);
66)         end
67) 
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

68)         svmmodel = svmtrain(svm_train_label,svm_train_data,svmopts);
69)         
70)         [plabel accuracy dvalue] = svmpredict(svm_validation_label,svm_validation_data,svmmodel,'');
Christoph Budziszewski nSubject-fold cross validat...

Christoph Budziszewski authored 15 years ago

71)         cross_value = [cross_value accuracy(1)];
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

72)         
Christoph Budziszewski nSubject-fold cross validat...

Christoph Budziszewski authored 15 years ago

73)     end
Christoph Budziszewski moved stuff, fixing plotDecode

Christoph Budziszewski authored 15 years ago

74)     decode.decodePerformance = [decode.decodePerformance; cross_value];
Christoph Budziszewski nSubject-fold cross validat...

Christoph Budziszewski authored 15 years ago

75)     
Christoph Budziszewski more x-svm classification

Christoph Budziszewski authored 15 years ago

76) end
Christoph Budziszewski GUI Task Switch: selfmade T...

Christoph Budziszewski authored 15 years ago

77) 
78) disp('decode done');