-
Notifications
You must be signed in to change notification settings - Fork 0
/
bam_constants.m
286 lines (234 loc) · 8.06 KB
/
bam_constants.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
%%% Paul Adkisson
%%% Define Constants for Biophysical Attractor Model (BAM)
function bam_constants(sim_path, sim_type, start_trial, end_trial, pulse_coherences, ...
control_coherences, galvanic_coherences, pulse_amps, dc_amps)
%% Simulation Parameters
tic;
mkdir(sim_path)
dt = 0.05e-3; %ms
if sim_type=="ps_val" || sim_type=="gs_val"
t_span = 1;
else
t_span = 4;
end
t = 0:dt:t_span;
%% Network Parameters
if sim_type=="discon"
percent_size = 0.15;
f = 0.5;
p = 2; % Number of different types of stimuli
N_E = floor(1600 * percent_size);
N_I = 0;
w_plus = 0;
w_minus = 0;
w = 0;
elseif sim_type=="con"
percent_size = 0.5;
f = 0.15;
p = 2; % Number of different types of stimuli
N_E = floor(1600 * percent_size);
N_I = floor(400 * percent_size);
w_plus = 1.7; % Strength of "strong" synapses in the BAM network
w_minus = 1 - f*(w_plus - 1)/(1-f); %Strength of "weak" synapses in BAM
w = 1; %Strength of normal synapses in BAM
elseif sim_type=="ps_val"
true_amps = [0, 50, 75, 100, 150, 200, 300]*(-1e-6);
num_amps = length(true_amps);
N_E = 100*num_amps;
N_I = 0;
f = 1;
p = 1;
w_plus = 0;
w_minus = 0;
w = 0;
elseif sim_type=="gs_val"
true_amps = (-200:5:600).*(-1e-6);
num_amps = length(true_amps);
num_reps = 5;
N_E = num_amps*num_reps;
N_I = 0;
f = 1;
p = 1;
w_plus = 0;
w_minus = 0;
w = 0;
elseif sim_type == "p1_int"
percent_size = 0.075;
f = 1;
p = 1; % Number of different types of stimuli
N_E = floor(1600 * percent_size);
N_I = floor(400 * percent_size);
w_plus = 0;
w_minus = 0;
w = 1;
elseif sim_type == "p1_rec"
percent_size = 0.075;
f = 1;
p = 1; % Number of different types of stimuli
N_E = floor(1600 * percent_size);
N_I = 0;
w_plus = 0.05;
w_minus = 0;
w = 0;
end
N = N_E + N_I;
num_selective = floor(p*f*N_E);
num_group = floor(f*N_E);
GenerateBAM(N_E, N_I, f, p, w_plus, w_minus, w, sim_path);
GenerateConductances(N_E, N_I, sim_path)
pop_type = ones(N, 1);
pop_type(N_E+1:end) = 2; % population_type = 1 for pyr, 2 for int
%% Input Parameters
fr_bg = 2400;
% Synaptic Conductance = [pyramidal, interneuron]
G_ampa_ext = [2.1, 1.62]*1e-9; %nS
coherences = union(union(pulse_coherences, galvanic_coherences), control_coherences, 'sorted');
max_fr_task = 80;
m = 0; %modulation strength
f0 = 40; %modulation frequency
if sim_type=="ps_val" || sim_type=="gs_val"
t_task = 0;
t_taskoff = t_span;
fr_bgs = 1800:100:3600;
end_trial = length(fr_bgs);
GeneratePopSpikes(sim_path, fr_bgs, coherences, N, t, ...
start_trial, end_trial);
else
t_task = 1;
t_taskoff = 3;
GenerateSpikes(fr_bg, m, f0, max_fr_task, coherences, f, p, N_E, N_I, ...
t_task, t_taskoff, t, start_trial, end_trial, sim_path);
end
%% LIF Parameters
% Parameter = [pyramidal, interneuron]
C = [0.5, 0.2]*1e-9; %nF
gL = [25, 20]*1e-9; %nS
EL = -70e-3; %mV
Vs = -50e-3; %mV
Vr = -55e-3;
tau_r = [2, 1]*1e-3; %ms
syn_delay = 0.5e-3; %ms
refract_ind = floor(tau_r/dt);
delay_ind = floor(syn_delay/dt);
tau_AMPA = 2e-3; %ms
tau_NMDA_1 = 2e-3; %ms
tau_NMDA_2 = 100e-3; %ms
tau_GABA = 5e-3; %ms
alpha = 500; %Hz
%% Microstimulation Parameters
stim_duration = 300e-6; %us / phase
stim_ind = floor(stim_duration*2 / dt);
stim_freq = 200; %Hz
depol_block_thresh = 1135*1e-12;
stim_amps = [pulse_amps, dc_amps];
perc_affected = 0.5; %Percent of neurons affected by microstimulation
num_affected = floor(perc_affected*num_group);
min_r = 10e-6; %Minimum distance of 10um
max_r = 2e-3; %Maximum distance of 2mm (Levitt et al.)
thresh_cor = 0.211; %Threshold correction factor for pulses
plot_ustim = false;
if sim_type=="ps_val"
true_freqs = 0:4:floor((N/num_amps-1)*4); %Hz
num_freqs = length(true_freqs);
stim_freqs = zeros(N, 1);
for j = 1:num_freqs
freq = true_freqs(j);
stim_freqs(j:floor(N/num_amps):end) = freq;
end
ps_stim_amps = zeros(N, 1);
for i = 1:num_amps
true_amp = true_amps(i);
if i == 1
start_idx = 1;
else
start_idx = floor(N/num_amps*(i-1)) + 1;
end
end_idx = floor(N/num_amps*i);
ps_stim_amps(start_idx:end_idx) = true_amp*ones(floor(N/num_amps), 1);
end
%Note pulse_amps is a dummy variable to ensure compatibility with main
GeneratePopMicroStim(t, t_task, t_taskoff, stim_duration, stim_freqs, ...
gL(1), ps_stim_amps, pulse_amps, N, sim_path, plot_ustim);
elseif sim_type=="gs_val"
gs_stim_amps = zeros(N, 1);
for i = 1:num_amps
true_amp = true_amps(i);
start_idx = num_reps*(i-1) + 1;
end_idx = num_reps*i;
gs_stim_amps(start_idx:end_idx) = true_amp;
end
GeneratePopMicroStim(t, t_task, t_taskoff, stim_duration, [], ...
gL(1), gs_stim_amps, dc_amps(1), N, sim_path, plot_ustim);
else
GenerateMicroStim(t, t_task, t_taskoff, stim_duration, stim_freq, ...
min_r, max_r, num_affected, thresh_cor, gL(1), ...
pulse_amps, dc_amps, N, sim_path, plot_ustim)
end
%% Firing Rate Parameters
win_size = 5e-3;
win_index = floor(win_size / dt);
avg_win_size = 50e-3;
avg_win_index = floor(avg_win_size / dt);
%% t_b
t_b = [0 0 0
4.5000 0 25.0000
9.0000 0 25.0000
13.5000 0 25.0000
18.0000 0 25.0000
22.5000 0 25.0000
27.0000 0 25.0000
31.5000 0 20.0000
36.0000 0 20.0000
40.5000 0 20.0000
45.0000 0 20.0000
49.5000 0 14.5000
54.0000 0 13.40
58.5000 0 12.6
63.0000 0 10.250
67.5000 0 8.6000
72.0000 0 7.0000
76.5000 0 6.1000
81.0000 0 5.8000
85.5000 0 5.5000
90.0000 0 5.4000
96.0000 0 4.8000
108.0000 0 4.7600
120.0000 0 4.7500
132.0000 0 4.7100
144.0000 0 4.7100
156.0000 0 4.7300
168.0000 0 4.7300
180.0000 0 4.7300
192.0000 0 4.7300
204.0000 0 4.7300
216.0000 0 5.1502
228.0000 0 5.1852
240.0000 0 5.5000
252.0000 0 6.2000
264.0000 0 7.0000
276.0000 0 7.7000
288.0000 0 8.3000
300.0000 0 16.2580
312.0000 0 31.6985
324.0000 0 68.5536
336.0000 0 156.5234
348.0000 0 366.4995
360.0000 0 867.6938
500.0000 0 867.6938];
load('params_tPP_tPS_tSP_from_10_27_20.mat')
best_tref_per_c = best_tref_per_c(1:size(t_b, 1), :);
t_pp = best_tref_per_c(:, 2)*1e-3;
t_pp = [t_pp; t_pp(end)];
t_ps = best_tref_per_c(:, 1)*1e-3;
t_ps = [t_ps; t_ps(end)];
t_sp = best_tref_per_c(:, 3)*1e-3;
t_sp = [t_sp; t_sp(end)];
z_thia = 0.002; %Thia's z=2mm
elec_r_thia = mirror_est(z_thia);
I_b = [t_b(:, 1)*1e-6*-elec_r_thia; 1]; %ensure interpolation always works
[min_pp, min_pp_idx] = min(t_pp(2:end));
%% Save
save_path = strcat(sim_path, "/bam_constants.mat");
save(save_path)
toc
end