forked from lrvarshney/elegans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspectral_both.m
190 lines (143 loc) · 5.34 KB
/
spectral_both.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
%SPECTRAL_BOTH.
% Copyright 2006-2009. Lav R. Varshney
%
% This software is provided without warranty.
% Related article:
%
% L. R. Varshney, B. L. Chen, E. Paniagua, D. H. Hall, and D. B.
% Chklovskii, "Structural properties of the Caenorhabditis elegans
% neuronal network," 2009, in preparation.
%gap junction network
Gg = datareader('gap','weighted');
[index_ig,index_jg] = ind2sub(size(Gg),find(triu(Gg)));
%chemical network
Gc = datareader('chem','weighted');
[index_ic,index_jc] = ind2sub(size(Gc),find(Gc));
%the GABAergic synapse listing
GABAergic = GABA;
%treat GABAergic synapses in chemical network as inhibitory
Gc(find(GABAergic),:) = -Gc(find(GABAergic),:);
%get the strong giant component
[S,C] = graphconncomp(Gc+Gg);
gc = mode(C);
AA = full(Gc(find(C==gc),find(C==gc)));
BB = full(Gg(find(C==gc),find(C==gc)));
%matrix associated with the linear system
L_orig = BB - diag(sum(BB)) + AA';
%gap junction ensemble parameters
p_g = 0.01;
%chemical ensemble parameters
p_c = 0.005;
%size of ensemble
nnn = 100;
for ii = 1:nnn
%%%GAP
%consider the upper triangle only
GammaWg = full(triu(Gg));
%go through each actual synaptic contact in the upper triangle;
%with probability p, move it to some random place in the upper triangle
for index = 1:length(index_ig)
%amount to reduce
reduc = sum(rand(1,Gg(index_ig(index),index_jg(index)))<p_g);
%reduce this one by reduc
GammaWg(index_ig(index),index_jg(index)) = GammaWg(index_ig(index),index_jg(index)) - reduc;
%add on reduc elsewhere in the upper triangle
for kk = 1:reduc
loc = ceil(length(Gg)*rand(1,2));
%can use min/max to force upper triangle because both
%permutations are equiprobable in an iid random vector
GammaWg(min(loc),max(loc)) = GammaWg(min(loc),max(loc)) + 1;
end
end
%symmetrize it
GammaWg = triu(GammaWg) + triu(GammaWg)';
%%%CHEM
GammaWc = full(Gc);
%go through each actual synaptic contact;
%with probability p, move it to some random place
for index = 1:length(index_ic)
%amount to reduce
reduc = sum(rand(1,Gc(index_ic(index),index_jc(index)))<p_c);
%reduce this one by reduc
GammaWc(index_ic(index),index_jc(index)) = GammaWc(index_ic(index),index_jc(index)) - reduc;
%add on reduc elsewhere
loc_i = ceil(length(Gc)*rand(1,reduc));
loc_j = ceil(length(Gc)*rand(1,reduc));
for loc_index = 1:length(loc_i)
GammaWc(loc_i(loc_index),loc_j(loc_index)) = GammaWc(loc_i(loc_index),loc_j(loc_index)) + 1;
end
end
%(GABAergic synapses in chemical network are already marked as inhibitory)
%get the strong giant component for the original graph
AA = full(GammaWc(find(C==gc),find(C==gc)));
BB = full(GammaWg(find(C==gc),find(C==gc)));
%matrix of edited graph associated with the linear system
L = BB - diag(sum(BB)) + AA';
%the eigenvalues and eigenvectors of the edited graph
[V,E] = eig(L);
eigenvalues{ii} = diag(E);
%compute the spectral norm of the additive change matrix
epsilon(ii) = norm(L-L_orig);
end
%mean and standard deviation of the spectral norm of additive change matrix
mean(epsilon)
std(epsilon)
%epsilon for pseudospectrum calculations
radius = 4;
%use the eigtool to look at the pseudospectrum
opts.npts=200;
opts.levels=[log10(radius)]; %choose the epsilon
opts.ax=[-130 36 -22 22];
opts.proj_lev=Inf;
opts.colour=1;
opts.thick_lines=0;
opts.scale_equal=0;
opts.grid=0;
opts.dim=0;
opts.no_ews=1;
opts.no_psa=0;
opts.fov=0;
opts.colourbar=0;
opts.imag_axis=0;
opts.unit_circle=0;
opts.direct=1;
opts.print_plot=1;
%plot the pseudospectrum
eigtool(L_orig,opts);
%the eigenvalues and eigenvectors of the original graph
[V,E] = eig(L_orig);
%plot epsilon disks around original spectrum
hold on
for ii = 1:length(E)
rectangle('Position',[real(E(ii,ii))-radius,imag(E(ii,ii))-radius,radius*2,radius*2],'Curvature',[1,1],'FaceColor',[.8 1 1],'EdgeColor',[.8 1 1]);
end
%plot the eigenvalues for the perturbed matrices in the complex plane
for jj = 1:nnn
Ep = eigenvalues{jj};
plot(real(Ep),imag(Ep),'b.')
end
%plot the eigenvalues for the original matrix in the complex plane
plot(real(diag(E)),imag(diag(E)),'r.')
%Now consider the case where send_joints are treated as only partials
%chemical network
load A_sendjoint
%the GABAergic synapse listing
GABAergic = GABA;
%treat GABAergic synapses in send_joint chemical network as inhibitory
Ac(find(GABAergic),:) = -Ac(find(GABAergic),:);
%get the strong giant component
[S,C] = graphconncomp(Ac+Gg);
gc = mode(C);
AA_sendjoint = full(Ac(find(C==gc),find(C==gc)));
BB = full(Gg(find(C==gc),find(C==gc)));
%matrix associated with the linear system
L_sendjoint = BB - diag(sum(BB)) + AA_sendjoint';
%the eigenvalues and eigenvectors of the send_joint graph
[V_sendjoint,E_sendjoint] = eig(L_sendjoint);
%plot the eigenvalues for the original matrix in the complex plane
plot(real(diag(E_sendjoint)),imag(diag(E_sendjoint)),'g.','MarkerSize',3)
%%%
hold off
xlabel('Re(\lambda)','FontSize',12)
ylabel('Im(\lambda)','FontSize',12)
set(gca,'FontSize',10);