def test_simulation_theory(self): reset_brian2() t = 1000 * ms dt = 0.01 * ms defaultclock.dt = dt pop = MFLinearPopulation( 100, { PP.GM: 25. * nS, PP.CM: 0.5 * nF, PP.VL: -70. * mV, PP.VTHR: -50. * mV, PP.VRES: -55. * mV, PP.TAU_RP: 2. * ms }) pop.rate = 1 * Hz noise = MFStaticInput(1000, 1 * Hz, pop, { IP.GM: 2 * nS, IP.VREV: 0 * volt, IP.TAU: 2. * ms, }) rec = MFLinearInput(pop, pop, { IP.GM: 0.973 / 100 * nS, IP.VREV: -70 * volt, IP.TAU: 10. * ms, }) system = MFSystem(pop) solver = MFSolver.rates_voltages(system, solver='mse', maxiter=1) sol = solver.run() theory = sol.state[0] rate = PopulationRateMonitor(pop.brian2) net = system.collect_brian2_network(rate) net.run(t) #brian2_introspect(net, globals()) stable_t = int(t / dt * 0.1) isolated = np.array(rate.rate)[stable_t:-stable_t] print(isolated.mean()) if False: plt.plot(rate.t / ms, rate.smooth_rate(width=25 * ms) / Hz) plt.plot(np.ones(10000) * isolated.mean(), label='simulation mean') plt.plot(np.ones(10000) * theory, label='theory mean') plt.ylabel('Population rate (Hz) per 100') plt.xlabel('Simulation time (ms)') plt.title('Poisson noise 5 Hz per 1000') plt.legend() plt.show()
def with_rate(rate): reset_brian2() pop = MFLinearPopulation(n_pop, { PP.GM: 25. * nS, PP.CM: 0.5 * nF, PP.VL: -70. * mV, PP.VTHR: -50. * mV, PP.VRES: -55. * mV, PP.TAU_RP: 2. * ms }) pop.rate = 10 * Hz MFStaticInput(n_noise, rate * Hz, pop, { IP.GM: 2.08 * nS, IP.VREV: 0 * volt, IP.TAU: 1.5 * ms, }) system = MFSystem(pop) rate = PopulationRateMonitor(pop.brian2) net = system.collect_brian2_network(rate) net.run(t) margin = round(0.5 * second / defaultclock.dt) stable = rate.smooth_rate(width=20 * ms)[margin:-margin] mean_simu = np.mean(stable) std_simu = np.reshape(stable, (samples, -1)).mean(axis=1).std() / np.sqrt(samples) * 1.96 print(std_simu) solver = MFSolver.rates_voltages(system, solver='simplex', maxiter=1) sol = solver.run() mean_theo = sol.state[0] return [mean_theo, mean_simu, std_simu]
def for_rate(rate): reset_brian2() pop = MFLinearPopulation( n_pop, { PP.GM: 25. * nS, PP.CM: 0.5 * nF, PP.VL: -70. * mV, PP.VTHR: -50. * mV, PP.VRES: -55. * mV, PP.TAU_RP: 2. * ms }) pop.rate = 1 * Hz MFStaticInput(n_noise, rate * Hz, pop, { IP.GM: 2 * nS, IP.VREV: 0 * volt, IP.TAU: 2. * ms, }) t = 500 * ms dt = 0.1 * ms system = MFSystem(pop) rate = PopulationRateMonitor(pop.brian2) net = system.collect_brian2_network(rate) net.run(t) stable_t = int(t / dt * 0.1) isolated = np.array(rate.rate)[stable_t:-stable_t] sim = np.mean(isolated) solver = MFSolver.rates_voltages(system, solver='simplex', maxiter=1) sol = solver.run() return [sol.state[0], sim]
def for_rate(rate): pop = MFLinearPopulation(100, { PP.GM: 25. * nS, PP.CM: 0.5 * nF, PP.VL: -70. * mV, PP.VTHR: -50. * mV, PP.VRES: -55. * mV, PP.TAU_RP: 2. * ms }) pop.rate = 10 * Hz noise = MFStaticInput(1000, rate * Hz, pop, { IP.GM: 2 * nS, IP.VREV: 0 * volt, IP.TAU: 2. * ms, }) pop.add_noise(noise) system = MFSystem(pop) solver = MFSolver.rates_voltages(system, solver='mse', maxiter=1) print(solver.state) sol = solver.run() return sol.state[0]
def one_subpopulation(): # populations N = 250 N_E = int(N * 0.8) # pyramidal neurons N_I = int(N * 0.2) # interneurons # voltage V_L = -70. * mV V_thr = -50. * mV V_reset = -55. * mV V_E = 0. * mV V_I = -70. * mV # membrane capacitance C_m_E = 0.5 * nF C_m_I = 0.2 * nF # membrane leak g_m_E = 25. * nS g_m_I = 20. * nS # refractory period tau_rp_E = 2. * ms tau_rp_I = 1. * ms # external stimuli rate = 3 * Hz C_ext = 800 # AMPA (excitatory) g_AMPA_ext_E = 2.08 * nS g_AMPA_rec_E = 0.104 * nS * 800. / N_E g_AMPA_ext_I = 1.62 * nS g_AMPA_rec_I = 0.081 * nS * 800. / N_E tau_AMPA = 2. * ms # NMDA (excitatory) g_NMDA_E = 0.327 * nS * 800. / N_E g_NMDA_I = 0.258 * nS * 800. / N_E tau_NMDA_rise = 2. * ms tau_NMDA_decay = 100. * ms alpha = 0.5 / ms beta = 0.062 gamma = 1. / 3.57 Mg2 = 1. # GABAergic (inhibitory) g_GABA_E = 1.25 * nS * 200. / N_I g_GABA_I = 0.973 * nS * 200. / N_I tau_GABA = 10. * ms # subpopulations f = 0.1 p = 1 N_sub = int(N_E * f) N_non = int(N_E * (1. - f * p)) w_plus = 2.1 w_minus = 1. - f * (w_plus - 1.) / (1. - f) # modeling E_params = { PP.GM: g_m_E, PP.CM: C_m_E, PP.VL: V_L, PP.VTHR: V_thr, PP.VRES: V_reset, PP.TAU_RP: tau_rp_E } I_params = { PP.GM: g_m_I, PP.CM: C_m_I, PP.VL: V_L, PP.VTHR: V_thr, PP.VRES: V_reset, PP.TAU_RP: tau_rp_I, } pop_e1 = MFLinearPopulation(N_non, E_params, name="E") pop_e2 = MFLinearPopulation(N_sub, E_params, name="Edown") pop_i = MFLinearPopulation(N_I, I_params, name="I") # noise pops MFStaticInput(C_ext, rate, pop_e1, { IP.GM: g_AMPA_ext_E, IP.VREV: V_E, IP.TAU: tau_AMPA, }, name="E_noise1") MFStaticInput(C_ext, rate, pop_e2, { IP.GM: g_AMPA_ext_E, IP.VREV: V_E, IP.TAU: tau_AMPA, }, name="E_noise2") MFStaticInput(C_ext, rate, pop_i, { IP.GM: g_AMPA_ext_I, IP.VREV: V_E, IP.TAU: tau_AMPA, }, name="I_noise") # E->E NMDA ee_nmda = MFParameters({ IP.GM: g_NMDA_E, IP.VREV: V_E, IP.TAU: tau_NMDA_decay, IP.TAU_NMDA_RISE: tau_NMDA_rise, IP.ALPHA: alpha, IP.BETA: beta, IP.GAMMA: gamma, IP.MG: Mg2, }) MFNonLinearNMDAInput(pop_e1, pop_e1, ee_nmda + {IP.W: 1}, name='EE NMDA 1', connection=Connection.all_to_others()) MFNonLinearNMDAInput(pop_e1, pop_e2, ee_nmda + {IP.W: w_minus}, name='EE NMDA 2') MFNonLinearNMDAInput(pop_e2, pop_e2, ee_nmda + {IP.W: w_plus}, name='EE NMDA 3', connection=Connection.all_to_others()) MFNonLinearNMDAInput(pop_e2, pop_e1, ee_nmda + {IP.W: 1}, name='EE NMDA 4') # E->E AMPA ee_ampa = MFParameters({ IP.GM: g_AMPA_rec_E, IP.VREV: V_E, IP.TAU: tau_AMPA, }) MFLinearInput(pop_e1, pop_e1, ee_ampa + {IP.W: 1}, name='EE AMPA 1') MFLinearInput(pop_e1, pop_e2, ee_ampa + {IP.W: w_minus}, name='EE AMPA 2', connection=Connection.all_to_others()) MFLinearInput(pop_e2, pop_e1, ee_ampa + {IP.W: w_plus}, name='EE AMPA 3') MFLinearInput(pop_e2, pop_e2, ee_ampa + {IP.W: 1}, name='EE AMPA 4', connection=Connection.all_to_others()) # E->I NMDA ei_nmda = { IP.GM: g_NMDA_I, IP.VREV: V_E, IP.W: 1, IP.TAU: tau_NMDA_decay, IP.TAU_NMDA_RISE: tau_NMDA_rise, IP.ALPHA: alpha, IP.BETA: beta, IP.GAMMA: gamma, IP.MG: Mg2, } MFNonLinearNMDAInput(pop_e1, pop_i, ei_nmda, name='EI NMDA') MFNonLinearNMDAInput(pop_e2, pop_i, ei_nmda, name='EI NMDA 2') # E->I AMPA ei_ampa = { IP.GM: g_AMPA_rec_E, IP.VREV: V_E, IP.TAU: tau_AMPA, } MFLinearInput(pop_e1, pop_i, ei_ampa, name='EI AMPA') MFLinearInput(pop_e2, pop_i, ei_ampa, name='EI AMPA 2') # I->I GABA MFLinearInput(pop_i, pop_i, { IP.GM: g_GABA_I, IP.VREV: V_I, IP.TAU: tau_GABA, }, name='II GABA', connection=Connection.all_to_others()) # I->E GABA ie_gaba = { IP.GM: g_GABA_E, IP.VREV: V_I, IP.TAU: tau_GABA, } MFLinearInput(pop_i, pop_e1, ie_gaba, name='IE GABA 1') MFLinearInput(pop_i, pop_e2, ie_gaba, name='IE GABA 2') return MFSystem(pop_e1, pop_e2, pop_i, name="Brunel Wang 2001")
def no_subpopulation(): # brunel 1999 system, one up state pop initials = {'nu_e': 3 * Hz, 'nu_i': 9 * Hz} pop_e = MFLinearPopulation(800, { PP.GM: params_standard['E']['g_L'], PP.VL: params_standard['E']['V_L'], PP.CM: params_standard['E']['C_m'], PP.VTHR: params_standard['E']['V_th'], PP.VRES: params_standard['E']['V_reset'], PP.TAU_RP: params_standard['E']['t_ref'] }, name='E') pop_i = MFLinearPopulation(200, { PP.GM: params_standard['I']['g_L'], PP.VL: params_standard['I']['V_L'], PP.CM: params_standard['I']['C_m'], PP.VTHR: params_standard['I']['V_th'], PP.VRES: params_standard['I']['V_reset'], PP.TAU_RP: params_standard['I']['t_ref'] }, name='I') pop_e.rate = initials['nu_e'] pop_e.v_mean = -51. * mV pop_i.rate = initials['nu_i'] pop_i.v_mean = -55. * mV system = MFSystem(pop_e, pop_i, name='EI') # noise pops source_e_noise = MFStaticInput(params_standard['E']['Cext'], params_standard['E']['nu_ext'], pop_e, { IP.GM: params_standard['E']['gAMPA'], IP.VREV: params_standard['E']['VE'], IP.TAU: params_standard['E']['tau_AMPA'], }, name='E_noise') source_i_noise = MFStaticInput(params_standard['I']['Cext'], params_standard['I']['nu_ext'], pop_i, { IP.GM: params_standard['I']['gAMPA'], IP.VREV: params_standard['I']['VE'], IP.TAU: params_standard['I']['tau_AMPA'], }, name='I_noise') # E->E NMDA source_ee_nmda = MFLinearSTPNMDAInput(pop_e, pop_e, { IP.BETA: params_standard['E']['beta'], IP.GAMMA: params_standard['E']['gamma'], IP.GM: params_standard['E']['gNMDA'], IP.VREV: params_standard['E']['VE'], IP.TAU: params_standard['E']['tau_NMDA'], IP.W: 1, IP.TAU_F: 1000 * ms, IP.TAU_D: 150 * ms, IP.U: 1, }, name='EE Nmda') # E->I NMDA source_ie_nmda = MFLinearSTPNMDAInput(pop_e, pop_i, { IP.BETA: params_standard['I']['beta'], IP.GAMMA: params_standard['I']['gamma'], IP.GM: params_standard['I']['gNMDA'], IP.VREV: params_standard['I']['VE'], IP.TAU: params_standard['I']['tau_NMDA'], IP.W: 1, IP.TAU_F: 1000 * ms, IP.TAU_D: 150 * ms, IP.U: 1, }, name='IE Nmda') # I->I GABA source_ii_gaba = MFLinearInput(pop_i, pop_i, { IP.GM: params_standard['I']['gGABA'], IP.VREV:params_standard['I']['VI'], IP.TAU: params_standard['I']['tau_GABA'], }, name='II Gaba') # I->E GABA source_ei_gaba = MFLinearInput(pop_i, pop_e, { IP.GM: params_standard['E']['gGABA'], IP.VREV: params_standard['E']['VI'], IP.TAU: params_standard['E']['tau_GABA'], }, name='EI Gaba') return system
def one_subpopulation(w_plus_val=2.5): # brunel 1999 system, one up state pop ff = .1 w_plus = w_plus_val w_min = 1. - ff * (w_plus - 1.) / (1. - ff) initials = {'nu_plus': 25 * Hz, 'nu_min': 1.5 * Hz, 'nu_i': 9 * Hz} pop_e1 = MFLinearPopulation(800 * ff, { PP.GM: params_standard['E']['g_L'], PP.VL: params_standard['E']['V_L'], PP.CM: params_standard['E']['C_m'], PP.VTHR: params_standard['E']['V_th'], PP.VRES: params_standard['E']['V_reset'], PP.TAU_RP: params_standard['E']['t_ref'] }, name='Eup') pop_e2 = MFLinearPopulation(800 * (1. - ff), { PP.GM: params_standard['E']['g_L'], PP.VL: params_standard['E']['V_L'], PP.CM: params_standard['E']['C_m'], PP.VTHR: params_standard['E']['V_th'], PP.VRES: params_standard['E']['V_reset'], PP.TAU_RP: params_standard['E']['t_ref'] }, name='Edown') pop_i = MFLinearPopulation(200, { PP.GM: params_standard['I']['g_L'], PP.VL: params_standard['I']['V_L'], PP.CM: params_standard['I']['C_m'], PP.VTHR: params_standard['I']['V_th'], PP.VRES: params_standard['I']['V_reset'], PP.TAU_RP: params_standard['I']['t_ref'] }, name='I') pop_e1.rate = initials['nu_plus'] pop_e1.v_mean = -51. * mV pop_e2.rate = initials['nu_min'] pop_e2.v_mean = -55. * mV pop_i.rate = initials['nu_i'] pop_i.v_mean = -55. * mV system = MFSystem(pop_e1, pop_e2, pop_i, name='Brunel') # noise pops source_e_noise1 = MFStaticInput(params_standard['E']['Cext'], params_standard['E']['nu_ext'], pop_e1, { IP.GM: params_standard['E']['gAMPA'], IP.VREV: params_standard['E']['VE'], IP.TAU: params_standard['E']['tau_AMPA'], }, name='E_noise1') source_e_noise2 = MFStaticInput(params_standard['E']['Cext'], params_standard['E']['nu_ext'], pop_e2, { IP.GM: params_standard['E']['gAMPA'], IP.VREV: params_standard['E']['VE'], IP.TAU: params_standard['E']['tau_AMPA'], }, name='E_noise2') source_i_noise = MFStaticInput(params_standard['I']['Cext'], params_standard['I']['nu_ext'], pop_i, { IP.GM: params_standard['I']['gAMPA'], IP.VREV: params_standard['I']['VE'], IP.TAU: params_standard['I']['tau_AMPA'], }, name='I_noise') # E->E NMDA ee_nmda = MFParameters({ IP.BETA: params_standard['E']['beta'], IP.GAMMA: params_standard['E']['gamma'], IP.GM: params_standard['E']['gNMDA'], IP.VREV: params_standard['E']['VE'], IP.TAU: params_standard['E']['tau_NMDA'], IP.TAU_F: 1000 * ms, IP.TAU_D: 150 * ms, IP.U: 1, }) source_ee_nmda1 = MFLinearSTPNMDAInput(pop_e1, pop_e1, ee_nmda + { IP.W: w_plus }, name='EE Nmda1') source_ee_nmda12 = MFLinearSTPNMDAInput(pop_e2, pop_e1, ee_nmda + { IP.W: w_min }, name='EE Nmda12') source_ee_nmda2 = MFLinearSTPNMDAInput(pop_e1, pop_e2, ee_nmda + { IP.W: w_min }, name='EE Nmda2') source_ee_nmda22 = MFLinearSTPNMDAInput(pop_e2, pop_e2, ee_nmda + { IP.W: (w_plus * ff + (1. - 2. * ff) * w_min) / (1 - ff) }, name='EE Nmda22') # E->I NMDA ei_nmda = { IP.BETA: params_standard['I']['beta'], IP.GAMMA: params_standard['I']['gamma'], IP.GM: params_standard['I']['gNMDA'], IP.VREV: params_standard['I']['VE'], IP.TAU: params_standard['I']['tau_NMDA'], IP.W: 1, IP.TAU_F: 1000 * ms, IP.TAU_D: 150 * ms, IP.U: 1, } source_ie_nmda = MFLinearSTPNMDAInput(pop_e1, pop_i, ei_nmda, name='IE Nmda') source_ie_nmda2 = MFLinearSTPNMDAInput(pop_e2, pop_i, ei_nmda, name='IE Nmda2') # I->I GABA source_ii_gaba = MFLinearInput(pop_i, pop_i, { IP.GM: params_standard['I']['gGABA'], IP.VREV: params_standard['I']['VI'], IP.TAU: params_standard['I']['tau_GABA'], }, name='II Gaba') # I->E GABA source_ei_gaba1 = MFLinearInput(pop_i, pop_e1, { IP.GM: params_standard['E']['gGABA'], IP.VREV: params_standard['E']['VI'], IP.TAU: params_standard['E']['tau_GABA'], }, name='EI Gaba') source_ei_gaba2 = MFLinearInput(pop_i, pop_e2, { IP.GM: params_standard['E']['gGABA'], IP.VREV: params_standard['E']['VI'], IP.TAU: params_standard['E']['tau_GABA'], }, name='EI Gaba2') return system