-
Notifications
You must be signed in to change notification settings - Fork 0
/
MasterWrapper.m~
156 lines (115 loc) · 5.15 KB
/
MasterWrapper.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
% Walkthrough of the steps that led to the results in the paper
% 'Differential temporal dynamics of visual imagery and perception' by N.
% Dijkstra, P. Mostert, F. de Lange, S.E. Bosch & M.A.J. van Gerven
%
% For clarity, only from after preprocessing and preparation of source
% info, for full details see paper
%% Some parameters and settings
addpath('/vol/ccnlab-scratch1/naddij/shareIMAMEG/Analyses')
root = '/vol/ccnlab-scratch1/naddij/shareIMAMEG/Data';
analyses = '/vol/ccnlab-scratch1/naddij/shareIMAMEG/Analyses';
subjects = {'S01','S03','S04','S06','S07','S08','S09','S11','S14','S15','S16','S17','S18','S19','S20','S21','S22','S23','S24','S25','S26','S27','S28','S29','S30'};
nSubjects = length(subjects);
for sub = 1:nSubjects
% get the subject info
subjectID = subjects{sub}';
subjectDir = fullfile(root,subjectID);
dataDir = fullfile(subjectDir,'CleanData');
%% Multivariate analyses
addpath(fullfile(analyses,'MultivariateAnalyses'))
cfg = [];
cfg.root = root;
cfg.nFold = 5; % number of folds for cross-validation
cfg.channels = 'MEG';
cfg.decfg.gamma = 0.05;
cfg.decfg.samplemethod = 'downsample'; % to balance trial numbers
cfg.decfg.nMeanS = 9; % average over x samples, for smoothing
% calculate the temporal generalization matrices
cfg.outputDir = fullfile(subjectDir,'DecodingTG');
% for perception
cfg.dataFiles{1} = fullfile(dataDir,'dataFP'); % training data
cfg.dataFiles{2} = fullfile(dataDir,'dataFP'); % test data
cfg.conIdx{1,1} = [101:108,201:208]; % the markers for each class
cfg.conIdx{1,2} = [109:116,209:216];
cfg.conIdx{2,1} = cfg.conIdx{1,1};
cfg.conIdx{2,2} = cfg.conIdx{1,2};
DecodingCross(cfg)
% for imagery
cfg.dataFiles{1} = fullfile(dataDir,'dataIM');
cfg.dataFiles{2} = fullfile(dataDir,'dataIM'); % test data
cfg.conIdx{1,1} = [121:128,221:228];
cfg.conIdx{1,2} = [129:136,229:236];
cfg.conIdx{2,1} = cfg.conIdx{1,1};
cfg.conIdx{2,2} = cfg.conIdx{1,2};
DecodingCross(cfg)
% calculate the cross-decoding matrices
cfg.outputDir = fullfile(subjectDir,'DecodingCROSS');
% form perception to imagery
cfg.dataFiles{1} = fullfile(dataDir,'dataFP'); % training data
cfg.dataFiles{2} = fullfile(dataDir,'dataIM'); % test data
cfg.conIdx{1,1} = [101:108,201:208];
cfg.conIdx{1,2} = [109:116,209:216];
cfg.conIdx{2,1} = [121:128,221:228];
cfg.conIdx{2,2} = [129:136,229:236];
DecodingCross(cfg)
% from imagery to perception
cfg.dataFiles{1} = fullfile(dataDir,'dataIM'); % training data
cfg.dataFiles{2} = fullfile(dataDir,'dataFP'); % test data
cfg.conIdx{1,1} = [121:128,221:228];
cfg.conIdx{1,2} = [129:136,229:236];
cfg.conIdx{2,1} = [101:108,201:208];
cfg.conIdx{2,2} = [109:116,209:216];
DecodingCross(cfg)
%% Vividness correlation
% takes the output from the classifier and correlates it with vividness
cfg = [];
cfg.dataDir = subjectDir;
cfg.dataName = '/DecodingCROSS/dataFP to dataIM.mat';
DecoderVividnessOutput(cfg)
%% Source reconstruction
addpath(fullfile(analyses,'SourceReconstruction'))
% calculate source activity difference ERF
cfg = [];
cfg.movie = 'no';
cfg.dataDir = dataDir;
cfg.output = fullfile(subjectDir,'SourceReconstruction');
cfg.subjectID = subjectID;
cfg.time = [];%[0 1];
cfg.lpfilter = 'yes';
cfg.dataName = 'dataIM';
cfg.conIdx{1} = [101:108,121:128,221:228]; cfg.conIdx{2} = [109:116,129:136,229:236];
SourcerecConDiff(cfg)
cfg.dataName = 'dataFP';
cfg.time = [];
SourcerecConDiff(cfg)
% seperate grid points into atlas regions for later averaging
cfg = [];
cfg.plot = 'no';
cfg.diff = 'yes'; % look at the difference or average over conditions
cfg.dataSet = 'dataIM';
cfg.subjectID = subjectID;
cfg.sourceRecDir = fullfile(subjectDir,'SourceReconstruction');
cfg.root = root;
SourcerecAtlas(cfg)
cfg.dataSet = 'dataFP';
SourcerecAtlas(cfg)
end
%% Group analyses decoding results
% perception temporal generalization
cfg.dataName = 'dataFP';
cfg.dirName = 'DecodingTG';
cfg.root = root;
cfg.nPerm = 1000; % number of permutations
cfg.alpha = 0.05;
cfg.subjects = subjects;
load(fullfile(root,subjects{1},cfg.dirName,cfg.dataName),'time') % steal a time variabel
cfg.time = time;
DecodingGA(cfg);
% imagery temporal generalization
cfg.dataName = 'dataFP';
load(fullfile(root,subjects{1},cfg.dirName,cfg.dataName),'time') % steal a time variabel
cfg.time = time;
DecodingGA(cfg);
% cross-decoding from perception to imagery
% cross-decoding from imagery to perception
%% Make figures