-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrain_multisubj_classifier.m
98 lines (75 loc) · 3.07 KB
/
train_multisubj_classifier.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function [min, range, training_data, training_labels]=train_multisubj_classifier(runN, cfg)
if nargin<2
cfg=[];
end
if ~isfield(cfg, 'maskpath')
cfg.maskpath='C:\Users\eust_abbondanza\Documents\MATLAB\attend';
end
if ~isfield(cfg, 'dataPath')
cfg.dataPath='C:\Documents\realtime\';
end
if ~isfield(cfg, 'protocolpath')
cfg.protocolpath='C:\Users\eust_abbondanza\Documents\ATTEND_DATA\IM\';
end
if ~isfield(cfg, 'allSubjPath')
cfg.allSubjPath='C:\Documents\Realtime\';
end
%mask_name=fullfile(cfg.maskpath, 'rwOSC.625.nii'); % mask is in the model folder
%%%various masks
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Occipital_Mid_R_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Occipital_Mid_L_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Occipital_Inf_R_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Occipital_Inf_L_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Temporal_Mid_R_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Temporal_Mid_L_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Temporal_Inf_R_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Temporal_Inf_L_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Temporal_Sup_R_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Temporal_Sup_L_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Fusiform_R_roi.nii');
%mask_name=fullfile(cfg.maskpath, 'rwMNI_Fusiform_L_roi.nii');
maskvol_hdr=spm_vol(cfg.mask_name);
maskvol_vol=spm_read_vols(maskvol_hdr);
%size(maskvol_vol)
training_labels=[];
sess_data=[];
%%%%%%%%%%%%%%%
%debug_number=10;
for subj=1:length(cfg.MultiSubjectID)
%%%%%%%%%%%%%%%%%
subject=cfg.MultiSubjectID{subj};
subjectID=subject(9:12);
subjectPath=fullfile(cfg.allSubjPath, subject);
for session=runN-1 %1:rN-1
[onsets, sess_labels]=create_training_ds(subjectID, session, cfg);
run_path=sprintf('%s\\Ser%04d', subjectPath, session);%debug
%%%%%%%%%% run_path=sprintf('%sRun%i', cfg.dataPath, session);
%%%%%%%%%%%%%%%
% sess_labels=sess_labels(1:debug_number)';
sess_labels=sess_labels';
%%%%%%%%%%%%%%%%%%
training_labels=vertcat(training_labels, sess_labels');
%%%%%%%%%
for n=1:length(onsets) %debug_number %
%myfile=sprintf('Analyze%05d.hdr', onsets(n));
myfile=sprintf('wprepScan_%i.nii', onsets(n));
fname=fullfile(run_path, myfile);
vol_hdr=spm_vol(fname);
vol_vol=spm_read_vols(vol_hdr);
vol_vol=vol_vol(maskvol_vol>cfg.maskThreshold);%reshape(vol_vol, 1, numel(vol_vol));
% size(vol_vol)
sess_data=vertcat(sess_data, vol_vol');
% training_data=scaledata(training_data, 0, 1);
end
end
end
%size(training_labels)
%size(training_data)
[min, range, training_data]=myscaledata(sess_data, 0, 1);
% training_data(1:28, 150)
% training_data(1:28, 250)
% training_data(1:28, 350)
% if cfg.saveClassifier==1
% save_classifier(training_data, training_labels, cfg);
% end
return