def non_linear_calcium(u, v, w0, seed): """ Same as ~cbsp.population_1.linear_calcium(u, v, w0, seed) for the non linear calcium model. """ # Calcium tau_Ca = 0.01893044 Cpre = 0.86467 Cpost = 2.30815 xi = (2 * (Cpost + Cpre) - Cpost) / Cpre - 1 # Plasticity thetaD = 1 thetaP = 4.99780 drate = 111.82515 prate = 894.23695 sigma = 2.8284 tau = 707.02258 sqrttau = np.sqrt(tau) # Optional, for current approximation tau_m = 5.e-3 c_N = 0.4 R = 50e6 Iconst = c_N * tau_m / R np.random.seed(seed) time = np.linspace(0., cbsp.SIMULATION_TIME, int(cbsp.SIMULATION_TIME / cbsp.TIMESTEP) + 1) N = 1000 cpre = np.zeros(N) cpost = np.zeros(N) c = np.zeros(N) w = np.zeros(N) w[:] = w0 w_rec_pop = np.zeros((N, len(time))) u_rec_pop = np.zeros((N, len(time))) v_rec = np.zeros_like(time) I_rec = np.zeros_like(time) c_rec_pop = np.zeros((N, len(time))) for i, t in enumerate(time): u_sp = utils.spike_train(N, u, cbsp.TIMESTEP) v_sp = utils.spike_train(1, v, cbsp.TIMESTEP) n = utils.standard_normal(N, cbsp.TIMESTEP) Hp = utils.heaviside(c - thetaP) Hd = utils.heaviside(c - thetaD) cpre = cpre - cbsp.TIMESTEP * cpre / tau_Ca + Cpre * u_sp cpost = cpost - cbsp.TIMESTEP * cpost / tau_Ca + Cpost * v_sp + xi * v_sp * cpre c = cpre + cpost w = w + cbsp.TIMESTEP / tau * (prate * (1 - w) * Hp - drate * w * Hd + np.sqrt(Hp + Hd) * sigma * sqrttau * n) w_rec_pop[:, i] = w u_rec_pop[:, i] = u_sp v_rec[i] = v_sp.item() I_rec[i] = Iconst * np.dot(w, u_sp) c_rec_pop[:, i] = c return w_rec_pop, time, (u_rec_pop, v_rec, I_rec, c_rec_pop)
def linear_calcium_mat(u1, w1, u2, w2, seed): """Integrates the spike-timing dependent synaptic strength. Args: u1 (float): presynaptic firing rate of the first population. w1 (float): initial synapse strength of the first population. u2 (float): presynaptic firing rate of the second population. w2 (float): initial synapse strength of the second population. seed (int): random state. Returns: tuple: ((w1, w2), t, (u1, u2, v, I, c1, c2)) with array: w1, change of synapse strengths in the first population. Shape (#synapses, #timesteps). array: w2, change of synapse strengths in the second population. Shape (#synapses, #timesteps). array: t, time. array: u1, presynaptic spike trains in the first population. Shape (#synapses, #timesteps). array: u2, presynaptic spike trains in the second population. Shape (#synapses, #timesteps). array: v, postsynaptic spike train. Shape (#timesteps). array: I, postsynaptic current. Shape (#timesteps). array: c1, calcium traces in the first population. Shape (#synapses, #timesteps). array: c2, calcium traces in the second population. Shape (#synapses, #timesteps). """ # Calcium tau_Ca = 0.02227212 Cpre = 0.84410 Cpost = 1.62138 # Plasticity thetaD = 1 thetaP = 2.009289 drate = 137.7586 prate = 597.08922 sigma = 2.8284 tau = 520.76129 sqrttau = np.sqrt(tau) # MAT model tau_m, tau_1, tau_2 = 5.e-3, 10.e-3, 200.e-3 trefr = 2.e-3 c_N = 0.2 R = 50e6 alpha1, alpha2, w_mat = 30.e-3, 2.e-3, 20.e-3 Iconst = c_N * tau_m / R time = np.linspace(0., cbsp.SIMULATION_TIME, int(cbsp.SIMULATION_TIME / cbsp.TIMESTEP) + 1) N1 = 1000 N2 = 1000 V = 0. theta1, theta2 = 0., 0. Theta = 0. trest = 0. I = 0. v_sp = 0. np.random.seed(seed) c = np.zeros(N1 + N2) w = np.zeros(N1 + N2) u_sp = np.zeros(N1 + N2) w[:N1] = w1 # np.random.normal(w0, w0_std, N) w[N1:] = w2 w1_rec_pop = np.zeros((N1, len(time))) w2_rec_pop = np.zeros((N2, len(time))) u1_rec_pop = np.zeros((N1, len(time))) u2_rec_pop = np.zeros((N2, len(time))) v_rec = np.zeros_like(time) I_rec = np.zeros_like(time) c1_rec_pop = np.zeros((N1, len(time))) c2_rec_pop = np.zeros((N2, len(time))) for i, t in enumerate(time): # import pdb; pdb.set_trace() u_sp[:N1] = utils.spike_train(N1, u1, cbsp.TIMESTEP) u_sp[N2:] = utils.spike_train(N2, u2, cbsp.TIMESTEP) n = utils.standard_normal(N1 + N2, cbsp.TIMESTEP) Hp = utils.heaviside(c - thetaP) Hd = utils.heaviside(c - thetaD) c = c - cbsp.TIMESTEP * c / tau_Ca + Cpre * u_sp + Cpost * v_sp w = w + cbsp.TIMESTEP / tau * (prate * (1 - w) * Hp - drate * w * Hd + np.sqrt(Hp + Hd) * sigma * sqrttau * n) I = Iconst * np.dot(w, u_sp) V = V + cbsp.TIMESTEP * (-V / tau_m + R / tau_m * I) theta1 = theta1 + cbsp.TIMESTEP * (-theta1 / tau_1) + alpha1 * v_sp theta2 = theta2 + cbsp.TIMESTEP * (-theta2 / tau_2) + alpha2 * v_sp Theta = theta1 + theta2 + w_mat if V > Theta and t > trest: v_sp = 1. trest = t + trefr else: v_sp = 0. w1_rec_pop[:, i] = w[:N1] u1_rec_pop[:, i] = u_sp[:N1] w2_rec_pop[:, i] = w[N1:] u2_rec_pop[:, i] = u_sp[N1:] v_rec[i] = v_sp I_rec[i] = I c1_rec_pop[:, i] = c[:N1] c2_rec_pop[:, i] = c[N1:] return (w1_rec_pop, w2_rec_pop), time, (u1_rec_pop, u2_rec_pop, v_rec, I_rec, c1_rec_pop, c2_rec_pop)
def linear_calcium_aeif(u1, w1, u2, w2, seed): """ Same as ~cbsp.population_3.linear_calcium_mat(u1, w1, u2, w2, seed) for the AEIF model. """ # Calcium tau_Ca = 0.02227212 Cpre = 0.84410 Cpost = 1.62138 # Plasticity thetaD = 1 thetaP = 2.009289 drate = 137.7586 prate = 597.08922 sigma = 2.8284 tau = 520.76129 sqrttau = np.sqrt(tau) # AEIF model (ranamed w->z) C = 2.81e-10 # 2.81e-9 # pF g_L = 30e-9 # nS E_L = -70.6e-3 # mV V_T = -50.4e-3 # mV D_T = 2e-3 # mV tau_z = 0.144 # s a = 4e-9 # nS b = 0.0805e-9 # nA R = 1 / g_L tau_v = R * C c_N = 0.085 # 17 # 0.0375 Iconst = c_N * tau_v / R time = np.linspace(0., cbsp.SIMULATION_TIME, int(cbsp.SIMULATION_TIME / cbsp.TIMESTEP) + 1) N1 = 1000 N2 = 1000 V = E_L z = 0. I = 0. v_sp = 0. np.random.seed(seed) c = np.zeros(N1 + N2) w = np.zeros(N1 + N2) u_sp = np.zeros(N1 + N2) w[:N1] = w1 # np.random.normal(w0, w0_std, N) w[N1:] = w2 w1_rec_pop = np.zeros((N1, len(time))) w2_rec_pop = np.zeros((N2, len(time))) u1_rec_pop = np.zeros((N1, len(time))) u2_rec_pop = np.zeros((N2, len(time))) v_rec = np.zeros_like(time) I_rec = np.zeros_like(time) c1_rec_pop = np.zeros((N1, len(time))) c2_rec_pop = np.zeros((N2, len(time))) for i, t in enumerate(time): u_sp[:N1] = utils.spike_train(N1, u1, cbsp.TIMESTEP) u_sp[N1:] = utils.spike_train(N2, u2, cbsp.TIMESTEP) n = utils.standard_normal(N1 + N2, cbsp.TIMESTEP) Hp = utils.heaviside(c - thetaP) Hd = utils.heaviside(c - thetaD) c = c - cbsp.TIMESTEP * c / tau_Ca + Cpre * u_sp + Cpost * v_sp w = w + cbsp.TIMESTEP / tau * (prate * (1 - w) * Hp - drate * w * Hd + np.sqrt(Hp + Hd) * sigma * sqrttau * n) I = Iconst * np.dot(w, u_sp) V = V + cbsp.TIMESTEP / tau_v * (-V + E_L + D_T * np.exp( (V - V_T) / D_T) - R * z + R * I) z = z + cbsp.TIMESTEP / tau_z * (a * (V - E_L) - z) if V > V_T: v_sp = 1. V = V - (V_T - E_L) z = z + b else: v_sp = 0. w1_rec_pop[:, i] = w[:N1] u1_rec_pop[:, i] = u_sp[:N1] w2_rec_pop[:, i] = w[N1:] u2_rec_pop[:, i] = u_sp[N1:] v_rec[i] = v_sp I_rec[i] = I c1_rec_pop[:, i] = c[:N1] c2_rec_pop[:, i] = c[N1:] return (w1_rec_pop, w2_rec_pop), time, (u1_rec_pop, u2_rec_pop, v_rec, I_rec, c1_rec_pop, c2_rec_pop)
def non_linear_calcium_mat(u1, w1, u2, w2, seed): """ Same as ~cbsp.population_3.linear_calcium_mat(u1, w1, u2, w2, seed) for the non linear calcium model. """ # Calcium tau_Ca = 0.01893044 Cpre = 0.86467 Cpost = 2.30815 xi = (2 * (Cpost + Cpre) - Cpost) / Cpre - 1 # Plasticity thetaD = 1 thetaP = 4.99780 drate = 111.82515 prate = 894.23695 sigma = 2.8284 tau = 707.02258 sqrttau = np.sqrt(tau) # MAT model tau_m, tau_1, tau_2 = 5.e-3, 10.e-3, 200.e-3 trefr = 2.e-3 c_N = 0.2 R = 50e6 alpha1, alpha2, w_mat = 30.e-3, 2.e-3, 20.e-3 Iconst = c_N * tau_m / R time = np.linspace(0., cbsp.SIMULATION_TIME, int(cbsp.SIMULATION_TIME / cbsp.TIMESTEP) + 1) N1 = 1000 N2 = 1000 V = 0. theta1, theta2 = 0., 0. Theta = 0. trest = 0. I = 0. v_sp = 0. np.random.seed(seed) cpre = np.zeros(N1 + N2) cpost = np.zeros(N1 + N2) c = np.zeros(N1 + N2) w = np.zeros(N1 + N2) u_sp = np.zeros(N1 + N2) w[:N1] = w1 # np.random.normal(w0, w0_std, N) w[N1:] = w2 w1_rec_pop = np.zeros((N1, len(time))) w2_rec_pop = np.zeros((N2, len(time))) u1_rec_pop = np.zeros((N1, len(time))) u2_rec_pop = np.zeros((N2, len(time))) v_rec = np.zeros_like(time) I_rec = np.zeros_like(time) c1_rec_pop = np.zeros((N1, len(time))) c2_rec_pop = np.zeros((N2, len(time))) for i, t in enumerate(time): # import pdb; pdb.set_trace() u_sp[:N1] = utils.spike_train(N1, u1, cbsp.TIMESTEP) u_sp[N2:] = utils.spike_train(N2, u2, cbsp.TIMESTEP) n = utils.standard_normal(N1 + N2, cbsp.TIMESTEP) Hp = utils.heaviside(c - thetaP) Hd = utils.heaviside(c - thetaD) cpre = cpre - cbsp.TIMESTEP * cpre / tau_Ca + Cpre * u_sp cpost = cpost - cbsp.TIMESTEP * cpost / tau_Ca + Cpost * v_sp + xi * v_sp * cpre c = cpre + cpost w = w + cbsp.TIMESTEP / tau * (prate * (1 - w) * Hp - drate * w * Hd + np.sqrt(Hp + Hd) * sigma * sqrttau * n) I = Iconst * np.dot(w, u_sp) V = V + cbsp.TIMESTEP * (-V / tau_m + R / tau_m * I) theta1 = theta1 + cbsp.TIMESTEP * (-theta1 / tau_1) + alpha1 * v_sp theta2 = theta2 + cbsp.TIMESTEP * (-theta2 / tau_2) + alpha2 * v_sp Theta = theta1 + theta2 + w_mat if V > Theta and t > trest: v_sp = 1. trest = t + trefr else: v_sp = 0. w1_rec_pop[:, i] = w[:N1] u1_rec_pop[:, i] = u_sp[:N1] w2_rec_pop[:, i] = w[N1:] u2_rec_pop[:, i] = u_sp[N1:] v_rec[i] = v_sp I_rec[i] = I c1_rec_pop[:, i] = c[:N1] c2_rec_pop[:, i] = c[N1:] return (w1_rec_pop, w2_rec_pop), time, (u1_rec_pop, u2_rec_pop, v_rec, I_rec, c1_rec_pop, c2_rec_pop)
def linear_calcium_mat(u, w0, seed): """Integrates the spike-timing dependent synaptic strength. Args: u (float): presynaptic firing rate. w0 (float): initial synapse strength. seed (int): random state. Returns: tuple: (w, t, (u, v, I, c)) with array: w, change of synapse strengths. Shape (#synapses, #timesteps). array: t, time. array: u, presynaptic spike trains. Shape (#synapses, #timesteps). array: v, postsynaptic spike train. Shape (#timesteps). array: I, postsynaptic current. Shape (#timesteps). array: c, calcium traces. Shape (#synapses, #timesteps). """ # Calcium tau_Ca = 0.02227212 Cpre = 0.84410 Cpost = 1.62138 # Plasticity thetaD = 1 thetaP = 2.009289 drate = 137.7586 prate = 597.08922 sigma = 2.8284 tau = 520.76129 sqrttau = np.sqrt(tau) # MAT model tau_m, tau_1, tau_2 = 5.e-3, 10.e-3, 200.e-3 trefr = 2.e-3 c_N = 0.4 R = 50e6 alpha1, alpha2, w_mat = 30.e-3, 2.e-3, 20.e-3 Iconst = c_N * tau_m / R time = np.linspace(0., cbsp.SIMULATION_TIME, int(cbsp.SIMULATION_TIME / cbsp.TIMESTEP) + 1) N = 1000 V = 0. theta1, theta2 = 0., 0. Theta = 0. trest = 0. I = 0. v_sp = 0. np.random.seed(seed) c = np.zeros(N) w = np.zeros(N) w[:] = w0 # np.random.normal(w0, w0_std, N) w_rec_pop = np.zeros((N, len(time))) u_rec_pop = np.zeros((N, len(time))) v_rec = np.zeros_like(time) I_rec = np.zeros_like(time) c_rec_pop = np.zeros((N, len(time))) for i, t in enumerate(time): u_sp = utils.spike_train(N, u, cbsp.TIMESTEP) n = utils.standard_normal(N, cbsp.TIMESTEP) Hp = utils.heaviside(c - thetaP) Hd = utils.heaviside(c - thetaD) c = c - cbsp.TIMESTEP * c / tau_Ca + Cpre * u_sp + Cpost * v_sp w = w + cbsp.TIMESTEP / tau * (prate * (1 - w) * Hp - drate * w * Hd + np.sqrt(Hp + Hd) * sigma * sqrttau * n) I = Iconst * np.dot(w, u_sp) V = V + cbsp.TIMESTEP * (-V / tau_m + R / tau_m * I) theta1 = theta1 + cbsp.TIMESTEP * (-theta1 / tau_1) + alpha1 * v_sp theta2 = theta2 + cbsp.TIMESTEP * (-theta2 / tau_2) + alpha2 * v_sp Theta = theta1 + theta2 + w_mat if V > Theta and t > trest: v_sp = 1. trest = t + trefr else: v_sp = 0. w_rec_pop[:, i] = w u_rec_pop[:, i] = u_sp v_rec[i] = v_sp I_rec[i] = I c_rec_pop[:, i] = c return w_rec_pop, time, (u_rec_pop, v_rec, I_rec, c_rec_pop)
def linear_calcium(u, v, w0, seed): """Integrates the spike-timing dependent synaptic strength. Args: u (float): presynaptic firing rate. v (float): postsynaptic firing rate. w0 (float): initial synapse strength. seed (int): random state. Returns: tuple: (w, t, (u, v, I, c)) with array: w, change of synapse strengths. Shape (#synapses, #timesteps). array: t, time. array: u, presynaptic spike trains. Shape (#synapses, #timesteps). array: v, postsynaptic spike train. Shape (#timesteps). array: I, postsynaptic current. Shape (#timesteps). array: c, calcium traces. Shape (#synapses, #timesteps). """ # Calcium tau_Ca = 0.02227212 Cpre = 0.84410 Cpost = 1.62138 # Plasticity thetaD = 1 thetaP = 2.009289 drate = 137.7586 prate = 597.08922 sigma = 2.8284 tau = 520.76129 sqrttau = np.sqrt(tau) # Optional, for current approximation tau_m = 5.e-3 c_N = 0.4 R = 50e6 Iconst = c_N * tau_m / R np.random.seed(seed) time = np.linspace(0., cbsp.SIMULATION_TIME, int(cbsp.SIMULATION_TIME / cbsp.TIMESTEP) + 1) N = 1000 cpre = np.zeros(N) cpost = np.zeros(N) c = np.zeros(N) w = np.zeros(N) w[:] = w0 # np.random.normal(w0, w0_std, N) w_rec_pop = np.zeros((N, len(time))) u_rec_pop = np.zeros((N, len(time))) v_rec = np.zeros_like(time) I_rec = np.zeros_like(time) c_rec_pop = np.zeros((N, len(time))) for i, t in enumerate(time): u_sp = utils.spike_train(N, u, cbsp.TIMESTEP) v_sp = utils.spike_train(1, v, cbsp.TIMESTEP) n = utils.standard_normal(N, cbsp.TIMESTEP) Hp = utils.heaviside(c - thetaP) Hd = utils.heaviside(c - thetaD) c = c - cbsp.TIMESTEP * c / tau_Ca + Cpre * u_sp + Cpost * v_sp w = w + cbsp.TIMESTEP / tau * (prate * (1 - w) * Hp - drate * w * Hd + np.sqrt(Hp + Hd) * sigma * sqrttau * n) w_rec_pop[:, i] = w u_rec_pop[:, i] = u_sp v_rec[i] = v_sp.item() I_rec[i] = Iconst * np.dot(w, u_sp) c_rec_pop[:, i] = c return w_rec_pop, time, (u_rec_pop, v_rec, I_rec, c_rec_pop)