-
Notifications
You must be signed in to change notification settings - Fork 4
/
multi_layer_examples.m
108 lines (84 loc) · 2.38 KB
/
multi_layer_examples.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
clearvars
close all
clc
% visualize the modularity matrix?
viz = 1 ;
%% example 1. time-varying fc (using with uniform null model)
% load data
load ./data/fmri_ts_data_singlesubject.mat
[numframes,n] = size(ts);
% window size for sliding window analysis
windowsize = 46;
% total number of non-overlapping windows
numwindows = numframes/windowsize;
% structural resolution parameter
gamma = 0.1;
% interlayer coupling parameter
omega = 0.5;
b = zeros(n*numwindows);
for iwindow = 1:numwindows
idx = (1:windowsize) + (iwindow - 1)*windowsize;
rho = corr(ts(idx,:));
jdx = (1:n) + (iwindow - 1)*n;
b(jdx,jdx) = rho - gamma;
b(jdx,jdx) = b(jdx,jdx).*~eye(n);
end
b = b + omega*spdiags(ones(n*numwindows,2),[-n,n],n*numwindows,n*numwindows);
if viz
imagesc(b)
title('time-varying fc modularity matrix')
waitforbuttonpress
close
end
%% example 2. multisubject categorical (using fc with uniform null model)
% load fc for five subjects
load ./data/sc_fc_data_multisubject.mat
% structural resolution parameter
gamma = 0.1;
% interlayer coupling parameter
omega = 0.1;
[n,~,nsub] = size(fc);
b = zeros(n*nsub);
for isub = 1:nsub
idx = (1:n) + (isub - 1)*n;
b(idx,idx) = fc(:,:,isub) - gamma;
b(idx,idx) = b(idx,idx).*~eye(n);
end
all2all = n*[(-nsub+1):-1,1:(nsub-1)];
b = b + omega*spdiags(ones(n*nsub,2*nsub-2),all2all,n*nsub,n*nsub);
if viz
imagesc(b)
title('multisubject categorical modularity matrix')
waitforbuttonpress
close
end
%% example 3. multisubject/multimodal coupling
% load fc + sc for five subjects
load ./data/sc_fc_data_multisubject.mat
% structural resolution parameter
gamma_fc = 0.3;
gamma_sc = 0;
% interlayer coupling parameter
omega = 1;
% structure-function coupling
eta = 0.05;
[n,~,nsub] = size(fc);
bfc = zeros(n*nsub);
bsc = zeros(n*nsub);
for isub = 1:nsub
idx = (1:n) + (isub - 1)*n;
bfc(idx,idx) = fc(:,:,isub) - gamma_fc;
bfc(idx,idx) = bfc(idx,idx).*~eye(n);
bsc(idx,idx) = corr(sc(:,:,isub)) - gamma_sc;
bsc(idx,idx) = bsc(idx,idx).*~eye(n);
end
all2all = n*[(-nsub+1):-1,1:(nsub-1)];
bsc = bsc + omega*spdiags(ones(n*nsub,2*nsub-2),all2all,n*nsub,n*nsub);
bfc = bfc + omega*spdiags(ones(n*nsub,2*nsub-2),all2all,n*nsub,n*nsub);
b = [bsc, eta*eye(nsub*n); eta*eye(nsub*n), bfc];
if viz
imagesc(b)
title('multisubject/multimodal modularity matrix')
waitforbuttonpress
close
end