-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalytic_equilibria_finder.m
327 lines (296 loc) · 7.46 KB
/
Analytic_equilibria_finder.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
% script to find an equilibrium J given a C_hat and other parameters
%parameters
p.function_path='./functions/'; %folder containing functions necessary for simulation
addpath(p.function_path) %adding folder containing functions
p.N=60;
p.T_batch_size=2; %sec
p.stim_del=10; %delay for stimulation (ms)
p.net_del=2; %2 (ms) mean of network synaptic delay
p.net_del_sig=0; %(ms) spread of network delays
p.dendrite_del=2; %5 (ms)
p.dendrite_ff_del=2; %(ms)
p.w_min=0;
p.w_max=0.02;%0.1;%0.02; %0.01
p.net_connect_prob=.3; %prob of connection in network
p.net_w_init=(p.w_max-p.w_min)/2;%0.01;%0.015;%0.01, 0.015;
p.gamma=0.1; %learning rule param
p.eta=1e-6; %learning rate
p.expansion_order=1; %n
p.dt=0.5; %ms
%STDP parameters
%Gilson V
d.c_p=30;
d.tau_p=8.5;
d.c_d=20;
d.tau_d=17;
%For exp
% de.c_p=150;
% de.tau_p=20;
% de.c_d=200;
% de.tau_d=40;
%defining STDP rule
W_rule=@(delta_t,j)STDPJ(delta_t,j,p.w_max,p.gamma,d);
% W_rule=@(delta_t,j)STDPJ_exp(delta_t,j,p.w_max,p.gamma,de);
%%
%Generating C_hat
dt=p.dt; %ms
lags_xc=-300:p.dt:300;
%!!!!!!!!!!!!!!!!!!!!
%Gaussian-shaped C_hat
tau=50;
baseline_ext_xc=0.17;
peak_ext_xc=2.3;
mean_rate=sqrt(baseline_ext_xc/1000*p.dt)/p.dt*1000;
expected_count=mean_rate*p.T_batch_size;
% %---------
C_hat=zeros(3,3,length(lags_xc));
for pre=1:3
for post=1:3
if pre==post
y=gaussmf(lags_xc,[tau,0])*peak_ext_xc/(1+baseline_ext_xc)+baseline_ext_xc;
% y=baseline_ext_xc;
else
y=baseline_ext_xc;
end
C_hat(post,pre,:)=y;
end
end
%!!!!!!!!!!!!!!!!!!!!
%------
%%
%defining expansion rule
expansion=@(J,A)...
C_hat2C(expected_count,C_hat,lags_xc,J,A,p.net_del+p.dendrite_ff_del,...
p.net_del_sig,p.stim_del,p.expansion_order);
%Initial mean matrix
J_init=(p.w_max-p.w_min)/2*ones(3);
J=J_init*p.net_connect_prob*p.N/3;
%%
%NORMAL
%BBCI matrix
A=[0,0,0;0,0,0;0,0,0];
%Calling main function
display 'Computing Normal Equilibria'
[Jeq,C]=C_hat2Jeq(@(J)expansion(J,A),W_rule,J_init,lags_xc,p);
%BBCI
%BBCI matrix
A=[0,0,0;1,0,0;0,0,0];
%Calling main function
display 'Computing BBCI Equilibria'
[Jeq_dag,C_dag]=C_hat2Jeq(@(J)expansion(J,A),W_rule,J_init,lags_xc,p);
%% plots
%Cross-correlations
ma=max(max(max(C_dag)));
figure('Position', [100, 100, 1049, 895]);
for post=1:3
for pre=1:3
subplot(3,3,sub2ind([3,3],post,pre))
set(gca,'FontSize',13)
plot(lags_xc,squeeze(C_hat(post,pre,:)),'k')
hold on
plot(lags_xc,squeeze(C(post,pre,:)),'b')
plot(lags_xc,squeeze(C_dag(post,pre,:)),'r')
plot([0,0],[0,ma],'k--')
hold off
title([num2str(pre) '-->' num2str(post)])
xlabel 'ISI(ms)'
ylabel 'mean count'
axis([lags_xc(1) lags_xc(end) 0 10])
end
end
subplot(3,3,1)
legend('drive','normal','BBCI')
%%
%--------
%*************
%MISC
p.cols={'k','r','b'}; %colors for group-related plots
%input 9 colors to plot connections
p.group_cols=zeros(3,3,3);
p.group_cols(1,1,:)=[0,0,0]; %black for group 1
p.group_cols(2,2,:)=[1,0,0]; %red for group 2
p.group_cols(3,3,:)=[0,0,1]; %blue for group 3
p.group_cols(2,1,:)=[0.5,0,0];
p.group_cols(1,2,:)=[0.5,0.5,0];
p.group_cols(3,1,:)=[0,0,0.5];
p.group_cols(1,3,:)=[0,0.5,0.5];
p.group_cols(3,2,:)=[1,0,0.5];
p.group_cols(2,3,:)=[0.5,0,1];
%*************
%Equlibrium matrix
figure;
%Plot mean matrix
subplot(2,2,1)
set(gca,'FontSize',13)
h=bar3(Jeq);
%-- Group Colors
cnt = 0;
for jj = 1:length(h)
xd = get(h(jj),'xdata');
yd = get(h(jj),'ydata');
zd = get(h(jj),'zdata');
delete(h(jj))
idx = [0;find(all(isnan(xd),2))];
if jj == 1
S = zeros(length(h)*(length(idx)-1),1);
end
for ii = 1:length(idx)-1
cnt = cnt + 1;
S(cnt) = surface(xd(idx(ii)+1:idx(ii+1)-1,:),...
yd(idx(ii)+1:idx(ii+1)-1,:),...
zd(idx(ii)+1:idx(ii+1)-1,:),...
'facecolor',p.group_cols(ii,jj,:));
end
end
rotate3d
%--
axis([0.5 3.5 0.5 3.5 p.w_min p.w_max])
xlabel 'pre'
ylabel 'post'
title 'Before'
view(-30,60)
subplot(2,2,2)
set(gca,'FontSize',13)
h=bar3(Jeq_dag);
%-- Group Colors
cnt = 0;
for jj = 1:length(h)
xd = get(h(jj),'xdata');
yd = get(h(jj),'ydata');
zd = get(h(jj),'zdata');
delete(h(jj))
idx = [0;find(all(isnan(xd),2))];
if jj == 1
S = zeros(length(h)*(length(idx)-1),1);
end
for ii = 1:length(idx)-1
cnt = cnt + 1;
S(cnt) = surface(xd(idx(ii)+1:idx(ii+1)-1,:),...
yd(idx(ii)+1:idx(ii+1)-1,:),...
zd(idx(ii)+1:idx(ii+1)-1,:),...
'facecolor',p.group_cols(ii,jj,:));
end
end
rotate3d
%--
axis([0.5 3.5 0.5 3.5 p.w_min p.w_max])
xlabel 'pre'
ylabel 'post'
title 'After'
view(-30,60)
% subplot(2,2,3)
% set(gca,'FontSize',10)
% title 'before'
% tix=cell(9,1);
% alpha={'a','b','c'};
% hold all
% counter=1;
% for pre=1:3
% for post=1:3
% bar(counter,Jeq(post,pre),'FaceColor',p.group_cols(post,pre,:));
% tix{counter+1}=[alpha{pre} '-->' alpha{post}];
% counter=counter+1;
% end
% end
% hold off
% axis([0 10 p.w_min p.w_max])
% set(gca,'XTickLabel',tix)
% subplot(2,2,4)
% title 'after'
% set(gca,'FontSize',10)
% tix=cell(9,1);
% alpha={'a','b','c'};
% hold all
% counter=1;
% for pre=1:3
% for post=1:3
% bar(counter,Jeq_dag(post,pre),'FaceColor',p.group_cols(post,pre,:));
% tix{counter+1}=[alpha{pre} '-->' alpha{post}];
% counter=counter+1;
% end
% end
% hold off
% axis([0 10 p.w_min p.w_max])
% set(gca,'XTickLabel',tix)
%changes
GA=(Jeq_dag-Jeq)/p.w_max;
subplot(2,2,[3,4])
tix=cell(9,1);
alpha={'a','b','c'};
hold all
counter=1;
for pre=1:3
for post=1:3
bar(counter,GA(post,pre),'FaceColor',p.group_cols(post,pre,:));
tix{counter+1}=[];
counter=counter+1;
end
end
hold off
axis([0 10 -0.2 1])
set(gca,'XTickLabel',tix,'FontSize',13)
title('Normalized changes')
%% plot equilibrium dynamic curves
j_range=p.w_min:0.0001:p.w_max;
F=zeros(3,3,length(j_range));
F_dag=zeros(3,3,length(j_range));
for pre=1:3
for post=1:3
y=squeeze(C(post,pre,:));
y_dag=squeeze(C_dag(post,pre,:));
for j=1:length(j_range)
F(post,pre,j)=sum(y'.*W_rule(lags_xc-p.dendrite_del+p.net_del,j_range(j)))*dt;
F_dag(post,pre,j)=sum(y_dag'.*W_rule(lags_xc-p.dendrite_del+p.net_del,j_range(j)))*dt;
end
end
end
%plot of dynamic curves and equ changes
figure;
subplot(2,2,1)
title 'before'
set(gca,'FontSize',10)
tix=cell(9,1);
alpha={'a','b','c'};
hold all
for pre=1:3
for post=1:3
plot(j_range,squeeze(F(post,pre,:)),'Color',p.group_cols(post,pre,:))
plot(Jeq(post,pre),0,'.','Color',p.group_cols(post,pre,:))
end
end
plot(j_range,0*j_range,'k--')
hold off
set(gca,'XTickLabel',tix)
subplot(2,2,2)
title 'after'
set(gca,'FontSize',10)
tix=cell(9,1);
alpha={'a','b','c'};
hold all
for pre=1:3
for post=1:3
plot(j_range,squeeze(F_dag(post,pre,:)),'Color',p.group_cols(post,pre,:))
plot(Jeq_dag(post,pre),0,'.','Color',p.group_cols(post,pre,:))
end
end
plot(j_range,0*j_range,'k--')
hold off
set(gca,'XTickLabel',tix)
%changes
GA=(Jeq_dag-Jeq)/p.w_max;
subplot(2,2,[3,4])
set(gca,'FontSize',10)
tix=cell(9,1);
alpha={'a','b','c'};
hold all
counter=1;
for pre=1:3
for post=1:3
bar(counter,GA(post,pre),'FaceColor',p.group_cols(post,pre,:));
tix{counter+1}=[alpha{pre} '-->' alpha{post}];
counter=counter+1;
end
end
hold off
% axis([0 10 -0.5 0.5])
set(gca,'XTickLabel',tix)