forked from iricchi/Brain_GLMM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomp_parad_task.m
executable file
·227 lines (178 loc) · 4.58 KB
/
comp_parad_task.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
%%
% This script is used to generate the task paradigm
% used as ground truth to assess the performances and
% validate the algorithm.
%%
clear all
close all
clc
path = genpath('/Users/iricchi/Documents/MIP_LabImmersion');
addpath(path)
%load HCP_Experimental_Task_paradigms.mat
load HCP_Paradigms_updated.mat
Ns = 50; % Num of subjects
ave = 1;
ave_t = 0;
cor = 1; % correlation
%% Build the matrix of the paradigm
% Working Memory3
WM = task_paradigm.WM;
% Move the first 10 zeros at the end
%WM_ = [WM_(end-9:end),WM_(1:end-10)];
% repeat it twice because the task repeats per subj
%WM = [WM_'; WM_'];
WM_mat = zeros(length(WM), 9); % 5 because we have 0 = no task
% 1= body , 2= faces ...
for i = 1:9
WM_mat(:,i) = WM == i-1;
end
% Motor task
Mot_ = task_paradigm.Motor;
% Move the first 10 zeros at the end
Mot_ = [Mot_(end-9:end),Mot_(1:end-10)];
% repeat it twice because the task repeats per subj
M = [Mot_'; Mot_'];
M_mat = zeros(length(M), 6); % 6 because we have 0 = no task
% 1= body , 2= faces ...
for i = 1:6
M_mat(:,i) = M == i-1;
end
% Relational Memory
RM = task_paradigm.Relational;
% Move the first 10 zeros at the end
% RM_ = [RM_(end-9:end),RM_(1:end-10)];
% repeat it twice because the task repeats per subj
%RM = [RM_'; RM_'];
RM_mat = zeros(length(RM), 3); % 4 because we have 0 = no task
% 1= body , 2= faces ...
for i = 1:3
RM_mat(:,i) = RM == i-1;
end
% Language
L_ = task_paradigms.Language;
L = [L_';L_'];
L_mat = zeros(length(L),9);
for i = 1:9
L_mat(:,i) = L == i-1;
end
% Emotion
E_ = task_paradigms.Emotion;
E_ = [E_(end-9:end),E_(1:end-10)];
E = [E_'; E_'];
E_mat = zeros(length(E), 3);
for i =1:3
E_mat(:,i) = E== i-1;
end
% Social
S_ = task_paradigms.Social;
S_ = [S_(end-9:end),S_(1:end-10)];
S = [S_'; S_'];
S_mat = zeros(length(S), 5);
for i =1:5
S_mat(:,i) = S== i-1;
end
S_mat = S_mat(:, [1,3,5]);
%% plot
figure()
imagesc(WM_mat)
names = {'no task'; 'body'; 'faces'; 'places'; 'tools'};
set(gca,'xtick',[1:9],'xticklabel',names)
ylabel('x_m')
title('Task Paradigm: working memory')
figure()
imagesc(M_mat)
names = {'no task'; 'left foot'; 'right foot'; 'left hand'; 'right hand'; 'tongue'};
set(gca,'xtick',[1:6],'xticklabel',names)
ylabel('x_m')
title('Task Paradigm: Motor')
figure()
imagesc(RM_mat)
names = {'no task'; 'relation'; 'match'};
set(gca,'xtick',[1:3],'xticklabel',names)
ylabel('x_m')
title('Task Paradigm: Relational memory')
figure()
imagesc(L_mat)
names = {'no task'; 'math'; 'present math'; 'present story'; 'question math';...
'question story';'response math'; 'response story'; 'story'};
set(gca,'xtick',[1:9],'xticklabel',names)
ylabel('x_m')
title('Task Paradigm: Language')
figure()
imagesc(E_mat)
names = {'no task'; 'fear'; 'neutral'};
set(gca,'xtick',[1:3],'xticklabel',names)
ylabel('x_m')
title('Task Paradigm: Emotion')
figure()
imagesc(S_mat)
names = {'no task'; 'mental'; 'random'};
set(gca,'xtick',[1:3],'xticklabel',names)
ylabel('x_m')
title('Task Paradigm: Social')
%% Plot gammas
load DataFromServer/Ls_WM_GL.mat
load DataFromServer/mus_WM_GL.mat % to visulize brain_vis
load DataFromServer/gamma_hats_WM_GL.mat
k = 4; %num of clusters
figure()
imagesc(gamma_hats)
xticks(linspace(1,k,k))
xlabel('K')
ylabel('x_m')
title('gamma values')
%% BIG matrix with repetition of paradigm Ns times, Ns = num of subjects
prompt = 'Which task to use: ';
task = input(prompt, 's');
switch task
case 'M'
T = M_mat;
case 'R'
T = RM_mat;
case 'W'
T = WM_mat;
case 'L'
T = L_mat;
otherwise
disp('Error! Choose between M, R, W')
end
BigMat = zeros(size(T,1), size(T,2));
for i = 1:Ns
BigMat((i-1)*length(T)+1:i*length(T),:) = T;
end
% plot
figure()
imagesc(BigMat)
title('50 subjects paradigm')
%% Avarage out the gammas
if (ave==1)
k = size(gamma_hats,2);
val = length(gamma_hats)/Ns;
gammas = zeros(val,k);
ind = zeros(Ns,val);
ind(1,1) = 1;
for i=2:Ns
ind(i,1) = ind(i-1,1)+val;
end
for i = 2:val
ind(:,i) = ind(:,i-1)+1 ;
end
for i = 1:val
gammas(i,:) = mean(gamma_hats(ind(:,i),:));
end
figure()
imagesc(gammas)
xticks(linspace(1,k,k))
xlabel('K')
ylabel('x_m')
title('Average gammas')
end
%% Plot correlation btw mean gammas and paradigm
if(cor ==1)
[C, p] = corr(gammas,T);
Cp = C;
Cp(p>0.05) = 0;
figure()
imagesc(Cp)
title('Correlation mean gammas and paradigm')
end