0c4a44fe4969e5555e233cb043ff428c07f03525
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

1) %% subject loop
2) function decode = som_subject_batch(header,subjectdata,somOpts)
3) 
4) addpath 'somtoolbox2';
5) 
6) RANDOMIZE_DATAPOINTS = 1;
7) 
8) decode = struct;
9) decode.decodePerformance = [];
10) decode.rawTimeCourse     = [];
11) 
12) nSubjects = numel(subjectdata);
13) disp(sprintf('batch processing %u subjects',nSubjects));
14) 
15) timeline = header.timeline;
16) timeline.frameShiftStart = header.frameShift.frameShiftStart;
17) timeline.frameShiftEnd   = header.frameShift.frameShiftEnd;
18) timeline.decodeDuration  = header.frameShift.decodeDuration;
19) 
20) 
21) timeLineStart   = timeline.frameShiftStart;
22) timeLineEnd     = timeline.frameShiftEnd;
23) 
24) % TimePointMatrix
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);
32) 
33)     decode.rawTimeCourse = [decode.rawTimeCourse currentSubject.pst];
34) 
35) 
36)     display(sprintf('%u -fold cross validation for %u timeslices.\n',somOpts.nfold,size(1:timeLineEnd-timeLineStart+1,2)));
37) 
Christoph Budziszewski all features implemented.

Christoph Budziszewski authored 15 years ago

38)     decode_timeline = [];
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

39)     for timeIndex = 1:timeLineEnd-timeLineStart+1
40)         svmstruct = calculateSVMTables(timePointMatrix{subjectDataID},timeIndex);
41)         nElements = length(svmstruct.svmlabel);
42) 
43)         if RANDOMIZE_DATAPOINTS
44)             rndindex  = randperm(nElements);
45)             svmstruct.svmdata   = svmstruct.svmdata(rndindex,:);
46)             svmstruct.svmlabel  = svmstruct.svmlabel(rndindex);
47)         end
48) 
49)         chunksize = nElements / somOpts.nfold;
50)         
51)         cross_value = 0;
52)         for iFold = 1:somOpts.nfold
53)             chunkstart = (iFold-1)*chunksize+1;
54)             chunkend   = min(iFold*chunksize,nElements);
55) 
56)             svm_train_label = svmstruct.svmlabel;
57)             svm_train_data  = svmstruct.svmdata;
58) 
59)             svm_validation_label = svmstruct.svmlabel(chunkstart:chunkend);
60)             svm_validation_data  = svmstruct.svmdata(chunkstart:chunkend,:);
61) 
62)             svm_train_label(chunkstart:chunkend) = []; %del test set
63)             svm_train_data(chunkstart:chunkend,:) = [];% del test set
64) 
65)             [sD sM] = som_train(svm_train_label, svm_train_data, somOpts);
66) 
67)             performance = som_decode(sM, svm_validation_data,svm_validation_label);
68) 
69)             cross_value = [cross_value, performance];
70)         end
Christoph Budziszewski all features implemented.

Christoph Budziszewski authored 15 years ago

71)         decode_timeline = [decode_timeline; mean(cross_value)];
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

72)     end
Christoph Budziszewski all features implemented.

Christoph Budziszewski authored 15 years ago

73)     decode.decodePerformance = [decode.decodePerformance decode_timeline];