-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo_simulation.m
257 lines (198 loc) · 9.66 KB
/
demo_simulation.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
% demo_simulation.m
%
% Matlab code to demonstrate simulation of the models
%
% Note that this demo sweeps the time and w parameters with a short period
% and a coarse resolution, respectively, to reduce computational load and
% produce sample outputs quickly (< 5 minutes). These parameters must be changed for a
% proper analysis. See WARNING notes below to see what needs to be changed.
%% LOAD SOME CONNECTOME MATRICES
load('data/connectome_human.mat')
load('data/connectome_chimp.mat')
load('data/connectome_macaque.mat')
load('data/connectome_marmoset.mat')
%% DEMO FOR REDUCED WONG-WANG MODEL
% =========================================================================
% generating and analyzing time series
% =========================================================================
% load predefined reduced Wong-Wang model parameters
param = utils.loadParameters_reducedWongWang_func;
% define connectome matrix A
type = 'human';
param.A = eval(sprintf('connectome_%s', type)); % replace with your own connectivity matrix
param.N = size(param.A, 2);
% normalize connectivity matrix with respect to maximum weight
normalization = 'maximum';
param.A = utils.norm_matrix(param.A, normalization);
% define simulation time
tpre = 100; % burn time to remove transient
tpost = 50; % steady-state time (WARNING: it is advisable to increase this to reach ergodicity)
param.tmax = tpre + param.tstep + tpost;
param.tspan = [0, param.tmax];
param.T = 0:param.tstep:param.tmax;
% simulate model using predefined initial conditions (y0 = 0.001)
sol = models.reducedWongWang(param);
% obtain steady-state synaptic gating and firing rate time series per region
time_steady_ind = dsearchn(param.T', tpre)+1; % index of start of steady state
S_steady = sol.y(:,time_steady_ind:end); % synaptic gating
H_steady = utils.calc_firingRate_reducedWongWang(param, S_steady); % firing rate
% redefine time vector to remove burn time
T_steady = (0:size(S_steady,2)-1)*param.tstep;
% calculate some stats of S per region
maxlag = 5;
[acf, lags, tau] = utils.calc_timescales(S_steady, maxlag, param.tstep); % timescale
% mean synaptic gating
% plot steady-state synaptic gating and firing rate time series
figure('Name', 'Reduced Wong-Wang model - Time series');
subplot(1,2,1)
plot(T_steady, S_steady)
xlabel('time (s)', 'interpreter', 'latex')
ylabel('regional synaptic response, $S$', 'interpreter', 'latex')
subplot(1,2,2)
plot(T_steady, H_steady)
xlabel('time (s)', 'interpreter', 'latex')
ylabel('regional firing rate, $H$', 'interpreter', 'latex')
% plot some regional stats
figure('Name', 'Reduced Wong-Wang model - Regional statistics');
yyaxis left
plot(1:param.N, mean(S_steady,2), '.-')
xlabel('region', 'interpreter', 'latex')
ylabel('mean regional synaptic response, $\overline{S}$', 'interpreter', 'latex')
yyaxis right
plot(1:param.N, tau, '.-')
xlabel('region', 'interpreter', 'latex')
ylabel('neural timescale, $\tau$', 'interpreter', 'latex')
% =========================================================================
% calculating and analyzing synaptic gating tuning curve
% =========================================================================
% define vector of recurrent connection strengths and number of trials
w_vec = 0.05:0.02:1; % WARNING: make sure to increase resolution for a proper analysis
num_trials = 1;
% calculate tuning curve per region
[Smean, Hmean, Hmax] = utils.calc_tuning_reducedWongWang(param, w_vec, tpre, num_trials);
% calculate some stats of Smean
S_transition = 0.3; % transition value of Smean
stats = utils.calc_response_stats(w_vec, Smean, S_transition);
% plot synaptic gating tuning curve and dynamic range per region
figure('Name', 'Reduced Wong-Wang model - Tuning curve and dynamic range');
subplot(1,2,1)
plot(w_vec, Smean)
xlabel('global recurrent strength, $w$', 'interpreter', 'latex')
ylabel('mean regional synaptic response, $\overline{S}$', 'interpreter', 'latex')
subplot(1,2,2)
plot(1:param.N, stats.dynamic_range, 'k.-')
xlabel('region', 'interpreter', 'latex')
ylabel('dynamic range', 'interpreter', 'latex')
%% DEMO FOR WILSON-COWAN MODEL
% =========================================================================
% generating time series
% =========================================================================
% load predefined Wilson-Cowan model parameters
param = utils.loadParameters_WilsonCowan_func;
% define connectome matrix A
type = 'human';
param.A = eval(sprintf('connectome_%s', type)); % replace with your own connectivity matrix
param.N = size(param.A, 2);
% normalize connectivity matrix with respect to maximum weight
normalization = 'maximum';
param.A = utils.norm_matrix(param.A, normalization);
% define simulation time
tpre = 5; % burn time to remove transient
tpost = 0.2; % steady-state time (WARNING: it is advisable to increase this to reach ergodicity)
param.tmax = tpre + param.tstep + tpost;
param.tspan = [0, param.tmax];
param.T = 0:param.tstep:param.tmax;
% simulate model using predefined initial conditions (y0 = 0.001)
sol = models.WilsonCowan(param);
% obtain steady-state synaptic gating and firing rate time series per region
time_steady_ind = dsearchn(param.T', tpre)+1; % index of start of steady state
S_E_steady = sol.y_E(:,time_steady_ind:end); % excitatory firing rate
S_I_steady = sol.y_I(:,time_steady_ind:end); % inhibitoryfiring rate
% redefine time vector to remove burn time
T_steady = (0:size(S_E_steady,2)-1)*param.tstep;
% plot steady-state excitatory firing rate and some stats
figure('Name', 'Wilson-Cowan model - Time series');
plot(T_steady, S_E_steady)
xlabel('time (s)', 'interpreter', 'latex')
ylabel('excitatory firing rate, $S_E$', 'interpreter', 'latex')
% =========================================================================
% calculating and analyzing excitatory firing rate tuning curve
% =========================================================================
% define vector of excitatory to excitatory connection strengths and number of trials
wEE_vec = 1:0.075:30; % WARNING: make sure to increase resolution for a proper analysis
num_trials = 1;
% calculate tuning curve per region
[SEmean, SImean] = utils.calc_tuning_WilsonCowan(param, wEE_vec, tpre, num_trials);
% calculate some stats of SEmean
S_transition = 0.15; % transition value of SEmean
stats = utils.calc_response_stats(wEE_vec, SEmean, S_transition);
% plot synaptic gating tuning curve and dynamic range per region
figure('Name', 'Wilson-Cowan model - Tuning curve and dynamic range');
subplot(1,2,1)
plot(wEE_vec, SEmean)
xlabel({'global excitatory'; 'recurrent strength, $w_{EE}$'}, 'interpreter', 'latex')
ylabel({'excitatory'; 'firing rate, $S_E$'}, 'interpreter', 'latex')
subplot(1,2,2)
plot(1:param.N, stats.dynamic_range, 'k.-')
xlabel('region', 'interpreter', 'latex')
ylabel('dynamic range', 'interpreter', 'latex')
%% DEMO FOR DRIFT DIFFUSION MODEL
% =========================================================================
% generating time series
% =========================================================================
% load predefined drift diffusion model parameters
param = utils.loadParameters_driftDiffusion_func;
% define connectome matrix A
type = 'human';
param.A = eval(sprintf('connectome_%s', type)); % replace with your own connectivity matrix
param.N = size(param.A, 2);
% normalize connectivity matrix with respect to maximum weight
normalization = 'maximum';
param.A = utils.norm_matrix(param.A, normalization);
% define simulation time
param.tmax = 2;
param.tspan = [0, param.tmax];
param.T = 0:param.tstep:param.tmax;
% simulate model using predefined initial conditions (y0 = 0)
sol = models.driftDiffusion(param);
% plot decision time series
figure('Name', 'Drift diffusion model - Time series');
hold on;
plot(param.T, sol.y)
plot(param.T, param.thres*(ones(size(param.T))), 'k-', 'linewidth', 2);
plot(param.T, -param.thres*(ones(size(param.T))), 'k-', 'linewidth', 2);
hold off;
xlabel('time (s)', 'interpreter', 'latex')
ylabel('regional decision evidence', 'interpreter', 'latex')
%% DEMO FOR DRIFT DIFFUSION MODEL WITH SELF-COUPLING TERM
% =========================================================================
% generating time series
% =========================================================================
% load predefined drift diffusion model parameters
param = utils.loadParameters_driftDiffusion_func;
% self-coupling term (lambda)
% positive = excitation
% negative = inhibition
lambda = -1;
% define connectome matrix A
type = 'human';
param.A = eval(sprintf('connectome_%s', type)); % replace with your own connectivity matrix
param.N = size(param.A, 2);
% normalize connectivity matrix with respect to maximum weight
normalization = 'maximum';
param.A = utils.norm_matrix(param.A, normalization);
% define simulation time
param.tmax = 2;
param.tspan = [0, param.tmax];
param.T = 0:param.tstep:param.tmax;
% simulate model using predefined initial conditions (y0 = 0)
sol = models.driftDiffusion(param, lambda);
% plot decision time series
figure('Name', 'Drift diffusion model - Time series');
hold on;
plot(param.T, sol.y)
plot(param.T, param.thres*(ones(size(param.T))), 'k-', 'linewidth', 2);
plot(param.T, -param.thres*(ones(size(param.T))), 'k-', 'linewidth', 2);
hold off;
xlabel('time (s)', 'interpreter', 'latex')
ylabel('regional decision evidence', 'interpreter', 'latex')