master
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

1) function decode = som_subject_batch(header,subjectdata,somOpts)
Christoph Budziszewski new labels, some cleanup

Christoph Budziszewski authored 14 years ago

2) global NODALYZE_SOMTOOLBOX;
3) addpath(fullfile(getTbxPath,NODALYZE_SOMTOOLBOX));
Christoph Budziszewski SOM Single run

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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) 
Christoph Budziszewski added some batch files, wor...

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

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

Christoph Budziszewski authored 15 years ago

81)     end
Christoph Budziszewski all features implemented.

Christoph Budziszewski authored 15 years ago

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