aa0fb379218f6b86818442412779930261a7d51a
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

1) %% subject loop
2) function decode = som_subject_batch(header,subjectdata,somOpts)
3) 
Christoph Budziszewski spm2 compatibility, start c...

Christoph Budziszewski authored 14 years ago

4) addpath(fullfile(getTbxPath,'somtoolbox2'));
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

5) 
Christoph Budziszewski added some batch files, wor...

Christoph Budziszewski authored 14 years ago

6) RANDOMIZE_DATAPOINTS = somOpts.rnd;
7) NAN_AS_ZERO = somOpts.nantozero;
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

8) 
9) decode = struct;
10) decode.decodePerformance = [];
11) decode.rawTimeCourse     = [];
12) 
13) nSubjects = numel(subjectdata);
14) disp(sprintf('batch processing %u subjects',nSubjects));
15) 
16) timeline = header.timeline;
17) timeline.frameShiftStart = header.frameShift.frameShiftStart;
18) timeline.frameShiftEnd   = header.frameShift.frameShiftEnd;
19) timeline.decodeDuration  = header.frameShift.decodeDuration;
20) 
21) 
22) timeLineStart   = timeline.frameShiftStart;
23) timeLineEnd     = timeline.frameShiftEnd;
24) 
25) % TimePointMatrix
26) for subjectDataID = 1:nSubjects
27)     currentSubject = subjectdata{subjectDataID};
28)     timePointArgs.pst           = currentSubject.pst;
29)     timePointArgs.labelMap      = LabelMap(header.classDef.labelCells,header.classDef.conditionCells);
30)     timePointArgs.eventList     = header.classDef.eventMatrix;
31) 
32)     timePointMatrix{subjectDataID} = buildTimePointMatrix(timeline,timePointArgs);
33) 
34)     decode.rawTimeCourse = [decode.rawTimeCourse currentSubject.pst];
35) 
36) 
37)     display(sprintf('%u -fold cross validation for %u timeslices.\n',somOpts.nfold,size(1:timeLineEnd-timeLineStart+1,2)));
38) 
Christoph Budziszewski all features implemented.

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 14 years ago

66)             if NAN_AS_ZERO
67)                 svm_train_data(isnan(svm_train_data))=0;
68)                 svm_validation_data(isnan(svm_validation_data))=0;
69)                 display('NaN to 0');
70)             end
71)             
72)             if isempty(svm_train_data)
73)                 performance = 0;
74)             else
75)                 [sD sM] = som_train(svm_train_label, svm_train_data, somOpts);
76)                 performance = som_decode(sM, svm_validation_data,svm_validation_label);
77)             end
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

78) 
79)             cross_value = [cross_value, performance];
80)         end
Christoph Budziszewski all features implemented.

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

82)     end
Christoph Budziszewski all features implemented.

Christoph Budziszewski authored 15 years ago

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