-
Notifications
You must be signed in to change notification settings - Fork 1
/
meg_psd_model_screening.m
175 lines (146 loc) · 5.63 KB
/
meg_psd_model_screening.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
function meg_psd_model_screening(a, MD, expK, C)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function loads simulations (MEG_sensor_PSD_Fitting.mat) and geenrates plots
% 1) Input:
%
% a: bifurcation parameter
% MD: range of delays in ms
% expK: range of couplings (expK)
% C: structural connectome, nodes_parcellation_nsubj (i.e. AAL90n32s)
%
%
% Output: Model disparity plot (Squared Euclidean Distance). Best fitting
% points visualised both for each subject and their mean
%
% Example: meg_psd_model_screening(-5,0:1:20,-1:0.1:1.7, 'AAL90n32s')
% Code by Francesca Castaldo, 2022 [email protected]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Add the toolbox to your own path
% addpath(genpath('C:\Users\fcast\OneDrive - University College London\Cabral_Castaldo\Code\Hopf_Delay_Toolbox\Hopf_Delay_Toolbox_2ndVersion'))
% if a==-5
% if C=='AAL90n32s'
% cd('C:\Users\fcast\OneDrive - University College London\CLUSTER\PROJECT[AAL]\New_Simu\32AAL\a_neg5')
% load ('MEG_sensor_PSD_Fitting.mat');
% K=10.^(expK);
% disp(['Running for' num2str(a) '90AAL32'])
% elseif C=='AAL90n985s'
% cd('C:\Users\fcast\OneDrive - University College London\CLUSTER\PROJECT[AAL]\New_Simu\985AAL\a_neg5')
% load ('MEG_sensor_PSD_Fitting.mat');
% K=10.^(expK);
% disp(['Running for' num2str(a) '90AAL985'])
% elseif C=='SHEAF200n32s'
% cd('C:\Users\fcast\OneDrive - University College London\CLUSTER\PROJECT[SHEAFER]\Simulations')
% load ('MEG_sensor_PSD_Fitting.mat');
% K=10.^(expK);
% disp(['Running for' num2str(a) '200SHEAF32'])
% end
%
% elseif a==-0.2
% if C=='AAL90n32s'
% cd('C:\Users\fcast\OneDrive - University College London\CLUSTER\PROJECT[AAL]\New_Simu\32AAL\a_neg02')
% load ('MEG_sensor_PSD_Fitting.mat');
% K=10.^(expK);
% disp(['Running for' num2str(a) '90AAL32'])
% end
%
% elseif a==-0.05
% if C=='AAL90n32s'
% cd('C:\Users\fcast\OneDrive - University College London\CLUSTER\PROJECT[AAL]\New_Simu\32AAL\a_neg005\Simulations')
% load ('MEG_sensor_PSD_Fitting.mat');
% K=10.^(expK);
% disp(['Running for' num2str(a) '90AAL32'])
% end
% end
% Demo Data:
if a==-5
load ('MEG_sensor_PSD_Fitting.mat');
end
K=10.^(expK);
%% Fit for each subject
for s=1:89
Dist_MEG= squeeze(Error_MEG_PSD_Sub(:,:,s));
[~, index_best_fit]= min(Dist_MEG(:));
best_fit_subj(s)=index_best_fit;
[k_s(s),D_s(s)]=ind2sub(size(Dist_MEG),index_best_fit);
disp(['Best fit to sub' num2str(s) ' for delay= ' num2str(MD(D_s(s))*1000) 'ms and k=1E' num2str(expK(k_s(s))) ' index ' num2str(index_best_fit)])
end
x=unique(best_fit_subj);
N=numel(x);
count = zeros(N,1);
for ii = 1:N
count(ii) = sum(best_fit_subj==x(ii));
end
disp([ x(:) count ]);
figure ('color','w')
colormap(jet)
imagesc(MD*1E3,log10(K),Error_MEG_PSD)%,'AlphaData',~isnan(Error_MEG_PSD)
title('Distance MEG PSD','FontSize',14,'FontName','Helvetica')
ylabel('Global Coupling K','FontSize',14,'FontName','Helvetica')
xlabel('Mean delay (ms)','FontSize',14,'FontName','Helvetica')
yticklabels({'0.1','','1','','10',''});
axis xy
colorbar
h = colorbar;
ylabel(h, 'Squared Euclidean Distance','FontSize',11,'FontName','Helvetica')
hold on
% plot(MD(D_s)*1000,expK(k_s),'*w');
for s=1:89
plot(MD(D_s(s))*1000,expK(k_s(s)),'*w');
legend('Best fit of individual MEG PSD')
end
%% Fit the subject mean
Dist_MEG_mean=Error_MEG_PSD;
[~, index_best_fit_mean]= min(Dist_MEG_mean(:));
% best_fit_meansubj(g,d)=index_best_fit_mean;
[k_s_mean,D_s_mean]=ind2sub(size(Dist_MEG_mean),index_best_fit_mean);
disp(['Best fit for delay= ' num2str(MD(D_s_mean)*1000) 'ms and k=1E' num2str(expK(k_s_mean)) ' index ' num2str(index_best_fit_mean)])
figure ('color','w')
colormap(jet)
imagesc(MD*1E3,log10(K),Error_MEG_PSD)%,'AlphaData',~isnan(Error_MEG_PSD)
title('Distance MEG PSD','FontSize',14,'FontName','Helvetica')
ylabel('Global Coupling K','FontSize',14,'FontName','Helvetica')
xlabel('Mean delay (ms)','FontSize',14,'FontName','Helvetica')
yticklabels({'0.1','','1','','10',''});
axis xy
colorbar
h = colorbar;
ylabel(h, 'Squared Euclidean Distance','FontSize',11,'FontName','Helvetica')
hold on
plot(MD(D_s_mean)*1000,expK(k_s_mean),'*w');
legend('Best fit of mean MEG PSD')
%% Correlation
% for s=1:89
% Corr_MEG= squeeze(Corr_MEG_PSD_Sub(:,:,s));
% [~, index_best_fit]= max(Corr_MEG(:));
%
% best_fit_subj(s)=index_best_fit;
% [k_s(s),D_s(s)]=ind2sub(size(Corr_MEG),index_best_fit);
% % D_s(s)=find(sum(squeeze(Corr_MEG_PSD_Sub(:,:,s))==max(max(squeeze(Corr_MEG_PSD_Sub(:,:,s))))));
% % k_s(s)=find(sum(squeeze(Corr_MEG_PSD_Sub(:,:,s))==max(max(squeeze(Corr_MEG_PSD_Sub(:,:,s)))),2));
% disp(['Best fit to sub' num2str(s) ' for delay= ' num2str(MD(D_s(s))*1000) 'ms and k=1E' num2str(expK(k_s(s)))])
% end
% x=unique(best_fit_subj);
% N=numel(x);
%
% count = zeros(N,1);
% for ii = 1:N
% count(ii) = sum(best_fit_subj==x(ii));
% end
%
% disp([ x(:) count ]);
% figure ('color','w')
% colormap(jet)
% imagesc(MD*(1E3),log10(K),Fit_MEG_PSD)
% title('Fit MEG PSD','FontSize',14,'FontName','Helvetica')
% ylabel('Global Coupling K','FontSize',14,'FontName','Helvetica')
% xlabel('Mean delay (ms)','FontSize',14,'FontName','Helvetica')
% yticklabels({'0.1','','1','','10',''});
% axis xy
% colorbar
% h = colorbar;
% ylabel(h, 'Correlation','FontSize',11,'FontName','Helvetica')
% hold on
%
% plot(MD(D_s)*1000,expK(k_s),'*w');
% legend('Best fit of individual MEG PSD', 'Location', 'northoutside')
%