forked from macshine/integration
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguimera_model.m
More file actions
175 lines (145 loc) · 5.57 KB
/
guimera_model.m
File metadata and controls
175 lines (145 loc) · 5.57 KB
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
%% code for running a simple simulation of within- and between-module connectivity
%
%
% Plan: create a 4-module network and then populate a proportion of connections
% either within (P_in) or between (P_out) the modules. Then, calculate a
% range of different graph theoretical measures to determine how each
% relates to different topological patterns.
%% probabilities from 0 - 1
P_out = 0:.01:1;
P_in = 0:.01:1;
%% 4 modules, each with 30 nodes
mat_id = [1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;2;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;3;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4;4];
%% predefine variables
nNodes = size(mat_id,1);
mat_out = zeros(nNodes);
nProbs = size(P_out,2);
cig = zeros(nNodes,nProbs,nProbs);
qg = zeros(nProbs,nProbs);
deg = zeros(nNodes,nProbs,nProbs);
bg = zeros(nNodes,nProbs,nProbs);
wg = zeros(nNodes,nProbs,nProbs);
cmg = zeros(nNodes,nNodes,nProbs,nProbs);
ag = zeros(nProbs,nProbs);
gg = zeros(nProbs,nProbs);
lg = zeros(nNodes,nProbs,nProbs);
mat_grp = zeros(nNodes,nNodes,nProbs,nProbs);
nMod = size(unique(mat_id),1);
nSize = nNodes/nMod;
%% loop through probabilities and run graph theoretical analyses
for x = 1:nProbs
for y = 1:nProbs
% for each probability combination (i.e., out and in), fill in that
% proportion of connections within and between each of the modules
for j = 1:nNodes
mat_out(j,:) = rand(1,nNodes)< P_out(1,y);
temp = mat_id==mat_id(j,1);
mat_out(j,temp==1) = rand(1,nSize)< P_in(1,x);
end
% save each matrix in a larger file for later
mat_grp(:,:,x,y) = mat_out;
%% requires brain connectivity toolbox (https://sites.google.com/site/bctnet/)
% nodal degree -- the number of connections that each node has
deg(:,x,y) = degrees_und(mat_out);
% modularity -- estimating the presence of communities
[cig(:,x,y),qg(x,y)] = community_louvain(mat_out,1);
% quantify the similarity between cig and mat_id using mutual information
[~,cimi(x,y)] = partition_distance(cig(:,x,y),mat_id);
% cartography -- between ('bg') and within ('wg') module connectivity
bg(:,x,y) = participation_coef(mat_out,cig(:,x,y));
wg(:,x,y) = module_degree_zscore(mat_out,cig(:,x,y));
% communicability -- the number of options connecting point A to B
cmg(:,:,x,y) = expm(mat_out);
% assortavity -- does like connect with like?
ag(x,y) = assortativity_bin(mat_out,0);
% efficiency -- inverse of characteristic path length
gg(x,y) = efficiency_bin(mat_out);
lg(:,x,y) = efficiency_bin(mat_out,1);
end
sprintf('%d',x) % gives you a counter so you know how long is left in the simulation
end
%% make pretty figures
xticklabels = 0:.1:1;
xticks = linspace(1, 101, numel(xticklabels));
yticklabels = 0:0.1:1;
yticks = linspace(1, 101, numel(yticklabels));
% degree
figure(1)
imagesc(squeeze(mean(deg,1)))
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Degree')
colorbar
set(gcf,'color','w')
% modularity
figure(2)
imagesc(qg)
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Modularity')
colorbar
set(gcf,'color','w')
% similarity between cig and mat_id
figure(3)
imagesc(cimi)
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Module recovery')
colorbar
set(gcf,'color','w')
% participation
figure(4)
imagesc(squeeze(mean(bg,1)))
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Participation Coefficient')
colorbar
set(gcf,'color','w')
% module degree Z-score
figure(5)
imagesc(squeeze(mean(wg,1)))
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Module Degree Z-score')
colorbar
set(gcf,'color','w')
% communicability
figure(6)
imagesc(log10(squeeze(mean(mean(cmg,1),2)))) % otherwise the data is too skewed to see
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Communicability')
colorbar
set(gcf,'color','w')
% assortativity
figure(7)
imagesc(squeeze(mean(ag,1)))
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Assortativity')
colorbar
set(gcf,'color','w')
% global efficiency
figure(8)
imagesc(gg)
set(gca, 'XTick', xticks, 'XTickLabel', xticklabels)
set(gca, 'YTick', yticks, 'YTickLabel', yticklabels)
ylabel('Probability of Within-Module Connection')
xlabel('Probability of Between-Module Connection')
title('Global Efficiency')
colorbar
set(gcf,'color','w')