def test_poissoninput(): """ Test collect_PoissonInput() """ # test 1 start_scope() v_th = 1 * volt grp = NeuronGroup(10, 'dv/dt = (v_th - v)/(10*ms) :volt', method='euler', threshold='v>100*mV', reset='v=0*mV') poi = PoissonInput(grp, 'v', 10, 1*Hz, 'v_th * rand() + 1*mV') poi_dict = collect_PoissonInput(poi, get_local_namespace(0)) assert poi_dict['target'] == grp.name assert poi_dict['rate'] == 1*Hz assert poi_dict['N'] == 10 assert poi_dict['target_var'] == 'v' assert poi_dict['when'] == poi.when assert poi_dict['order'] == poi.order assert poi_dict['clock'] == poi.clock.dt assert poi_dict['identifiers']['v_th'] == v_th # test 2 grp2 = NeuronGroup(10, 'dv_1_2_3/dt = (v_th - v_1_2_3)/(10*ms) :volt', method='euler', threshold='v_1_2_3>v_th', reset='v_1_2_3=-v_th') poi2 = PoissonInput(grp2, 'v_1_2_3', 0, 0*Hz, v_th) poi_dict = collect_PoissonInput(poi2, get_local_namespace(0)) assert poi_dict['target'] == grp2.name assert poi_dict['rate'] == 0*Hz assert poi_dict['N'] == 0 assert poi_dict['target_var'] == 'v_1_2_3' with pytest.raises(KeyError): poi_dict['identifiers']
def test_ExportDevice_unsupported(): """ Test whether unsupported objects for standard format export are raising Error """ start_scope() set_device('exporter') eqn = ''' v = 1 :1 g :1 ''' G = NeuronGroup(1, eqn) _ = PoissonInput(G, 'g', 1, 1 * Hz, 1) # with pytest.raises(NotImplementedError): run(10 * ms)
def sim_decision_making_network( N_Excit=384, N_Inhib=96, weight_scaling_factor=5.33, t_stimulus_start=100 * b2.ms, t_stimulus_duration=9999 * b2.ms, coherence_level=0., stimulus_update_interval=30 * b2.ms, mu0_mean_stimulus_Hz=160., stimulus_std_Hz=20., N_extern=1000, firing_rate_extern=9.8 * b2.Hz, w_pos=1.90, f_Subpop_size=0.25, # .15 in publication [1] max_sim_time=1000. * b2.ms, stop_condition_rate=None, monitored_subset_size=512): """ Args: N_Excit (int): total number of neurons in the excitatory population N_Inhib (int): nr of neurons in the inhibitory populations weight_scaling_factor: When increasing the number of neurons by 2, the weights should be scaled down by 1/2 t_stimulus_start (Quantity): time when the stimulation starts t_stimulus_duration (Quantity): duration of the stimulation coherence_level (int): coherence of the stimulus. Difference in mean between the PoissonGroups "left" stimulus and "right" stimulus stimulus_update_interval (Quantity): the mean of the stimulating PoissonGroups is re-sampled at this interval mu0_mean_stimulus_Hz (float): maximum mean firing rate of the stimulus if c=+1 or c=-1. Each neuron in the populations "Left" and "Right" receives an independent poisson input. stimulus_std_Hz (float): std deviation of the stimulating PoissonGroups. N_extern (int): nr of neurons in the stimulus independent poisson background population firing_rate_extern (int): firing rate of the stimulus independent poisson background population w_pos (float): Scaling (strengthening) of the recurrent weights within the subpopulations "Left" and "Right" f_Subpop_size (float): fraction of the neurons in the subpopulations "Left" and "Right". #left = #right = int(f_Subpop_size*N_Excit). max_sim_time (Quantity): simulated time. stop_condition_rate (Quantity): An optional stopping criteria: If not None, the simulation stops if the firing rate of either subpopulation "Left" or "Right" is above stop_condition_rate. monitored_subset_size (int): max nr of neurons for which a state monitor is registered. Returns: A dictionary with the following keys (strings): "rate_monitor_A", "spike_monitor_A", "voltage_monitor_A", "idx_monitored_neurons_A", "rate_monitor_B", "spike_monitor_B", "voltage_monitor_B", "idx_monitored_neurons_B", "rate_monitor_Z", "spike_monitor_Z", "voltage_monitor_Z", "idx_monitored_neurons_Z", "rate_monitor_inhib", "spike_monitor_inhib", "voltage_monitor_inhib", "idx_monitored_neurons_inhib" """ print("simulating {} neurons. Start: {}".format(N_Excit + N_Inhib, time.ctime())) t_stimulus_end = t_stimulus_start + t_stimulus_duration N_Group_A = int( N_Excit * f_Subpop_size ) # size of the excitatory subpopulation sensitive to stimulus A N_Group_B = N_Group_A # size of the excitatory subpopulation sensitive to stimulus B N_Group_Z = N_Excit - N_Group_A - N_Group_B # (1-2f)Ne excitatory neurons do not respond to either stimulus. Cm_excit = 0.5 * b2.nF # membrane capacitance of excitatory neurons G_leak_excit = 25.0 * b2.nS # leak conductance E_leak_excit = -70.0 * b2.mV # reversal potential v_spike_thr_excit = -50.0 * b2.mV # spike condition v_reset_excit = -60.0 * b2.mV # reset voltage after spike t_abs_refract_excit = 2. * b2.ms # absolute refractory period # specify the inhibitory interneurons: # N_Inhib = 200 Cm_inhib = 0.2 * b2.nF G_leak_inhib = 20.0 * b2.nS E_leak_inhib = -70.0 * b2.mV v_spike_thr_inhib = -50.0 * b2.mV v_reset_inhib = -60.0 * b2.mV t_abs_refract_inhib = 1.0 * b2.ms # specify the AMPA synapses E_AMPA = 0.0 * b2.mV tau_AMPA = 2.5 * b2.ms # specify the GABA synapses E_GABA = -70.0 * b2.mV tau_GABA = 5.0 * b2.ms # specify the NMDA synapses E_NMDA = 0.0 * b2.mV tau_NMDA_s = 100.0 * b2.ms tau_NMDA_x = 2. * b2.ms alpha_NMDA = 0.5 * b2.kHz # projections from the external population g_AMPA_extern2inhib = 1.62 * b2.nS g_AMPA_extern2excit = 2.1 * b2.nS # projectsions from the inhibitory populations g_GABA_inhib2inhib = weight_scaling_factor * 1.25 * b2.nS g_GABA_inhib2excit = weight_scaling_factor * 1.60 * b2.nS # projections from the excitatory population g_AMPA_excit2excit = weight_scaling_factor * 0.012 * b2.nS g_AMPA_excit2inhib = weight_scaling_factor * 0.015 * b2.nS g_NMDA_excit2excit = weight_scaling_factor * 0.040 * b2.nS g_NMDA_excit2inhib = weight_scaling_factor * 0.045 * b2.nS # stronger projection to inhib. # weights and "adjusted" weights. w_neg = 1. - f_Subpop_size * (w_pos - 1.) / (1. - f_Subpop_size) # We use the same postsyn AMPA and NMDA conductances. Adjust the weights coming from different sources: w_ext2inhib = g_AMPA_extern2inhib / g_AMPA_excit2inhib w_ext2excit = g_AMPA_extern2excit / g_AMPA_excit2excit # other weights are 1 # print("w_neg={}, w_ext2inhib={}, w_ext2excit={}".format(w_neg, w_ext2inhib, w_ext2excit)) # Define the inhibitory population # dynamics: inhib_lif_dynamics = """ s_NMDA_total : 1 # the post synaptic sum of s. compare with s_NMDA_presyn dv/dt = ( - G_leak_inhib * (v-E_leak_inhib) - g_AMPA_excit2inhib * s_AMPA * (v-E_AMPA) - g_GABA_inhib2inhib * s_GABA * (v-E_GABA) - g_NMDA_excit2inhib * s_NMDA_total * (v-E_NMDA)/(1.0+1.0*exp(-0.062*v/volt)/3.57) )/Cm_inhib : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 """ inhib_pop = NeuronGroup(N_Inhib, model=inhib_lif_dynamics, threshold="v>v_spike_thr_inhib", reset="v=v_reset_inhib", refractory=t_abs_refract_inhib, method="rk2") # initialize with random voltages: inhib_pop.v = rnd.uniform(v_spike_thr_inhib / b2.mV - 4., high=v_spike_thr_inhib / b2.mV - 1., size=N_Inhib) * b2.mV # Specify the excitatory population: # dynamics: excit_lif_dynamics = """ s_NMDA_total : 1 # the post synaptic sum of s. compare with s_NMDA_presyn dv/dt = ( - G_leak_excit * (v-E_leak_excit) - g_AMPA_excit2excit * s_AMPA * (v-E_AMPA) - g_GABA_inhib2excit * s_GABA * (v-E_GABA) - g_NMDA_excit2excit * s_NMDA_total * (v-E_NMDA)/(1.0+1.0*exp(-0.062*v/volt)/3.57) )/Cm_excit : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 ds_NMDA/dt = -s_NMDA/tau_NMDA_s + alpha_NMDA * x * (1-s_NMDA) : 1 dx/dt = -x/tau_NMDA_x : 1 """ # define the three excitatory subpopulations. # A: subpop receiving stimulus A excit_pop_A = NeuronGroup(N_Group_A, model=excit_lif_dynamics, threshold="v>v_spike_thr_excit", reset="v=v_reset_excit", refractory=t_abs_refract_excit, method="rk2") excit_pop_A.v = rnd.uniform(E_leak_excit / b2.mV, high=E_leak_excit / b2.mV + 5., size=excit_pop_A.N) * b2.mV # B: subpop receiving stimulus B excit_pop_B = NeuronGroup(N_Group_B, model=excit_lif_dynamics, threshold="v>v_spike_thr_excit", reset="v=v_reset_excit", refractory=t_abs_refract_excit, method="rk2") excit_pop_B.v = rnd.uniform(E_leak_excit / b2.mV, high=E_leak_excit / b2.mV + 5., size=excit_pop_B.N) * b2.mV # Z: non-sensitive excit_pop_Z = NeuronGroup(N_Group_Z, model=excit_lif_dynamics, threshold="v>v_spike_thr_excit", reset="v=v_reset_excit", refractory=t_abs_refract_excit, method="rk2") excit_pop_Z.v = rnd.uniform(v_reset_excit / b2.mV, high=v_spike_thr_excit / b2.mV - 1., size=excit_pop_Z.N) * b2.mV # now define the connections: # projections FROM EXTERNAL POISSON GROUP: #################################################### poisson2Inhib = PoissonInput(target=inhib_pop, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2inhib) poisson2A = PoissonInput(target=excit_pop_A, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2excit) poisson2B = PoissonInput(target=excit_pop_B, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2excit) poisson2Z = PoissonInput(target=excit_pop_Z, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2excit) ############################################################################################### # GABA projections FROM INHIBITORY population: ################################################ syn_inhib2inhib = Synapses(inhib_pop, target=inhib_pop, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2inhib.connect(p=1.) syn_inhib2A = Synapses(inhib_pop, target=excit_pop_A, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2A.connect(p=1.) syn_inhib2B = Synapses(inhib_pop, target=excit_pop_B, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2B.connect(p=1.) syn_inhib2Z = Synapses(inhib_pop, target=excit_pop_Z, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2Z.connect(p=1.) ############################################################################################### # AMPA projections FROM EXCITATORY A: ######################################################### syn_AMPA_A2A = Synapses(excit_pop_A, target=excit_pop_A, on_pre="s_AMPA += w_pos", delay=0.5 * b2.ms) syn_AMPA_A2A.connect(p=1.) syn_AMPA_A2B = Synapses(excit_pop_A, target=excit_pop_B, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_A2B.connect(p=1.) syn_AMPA_A2Z = Synapses(excit_pop_A, target=excit_pop_Z, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_A2Z.connect(p=1.) syn_AMPA_A2inhib = Synapses(excit_pop_A, target=inhib_pop, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_A2inhib.connect(p=1.) ############################################################################################### # AMPA projections FROM EXCITATORY B: ######################################################### syn_AMPA_B2A = Synapses(excit_pop_B, target=excit_pop_A, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_B2A.connect(p=1.) syn_AMPA_B2B = Synapses(excit_pop_B, target=excit_pop_B, on_pre="s_AMPA += w_pos", delay=0.5 * b2.ms) syn_AMPA_B2B.connect(p=1.) syn_AMPA_B2Z = Synapses(excit_pop_B, target=excit_pop_Z, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_B2Z.connect(p=1.) syn_AMPA_B2inhib = Synapses(excit_pop_B, target=inhib_pop, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_B2inhib.connect(p=1.) ############################################################################################### # AMPA projections FROM EXCITATORY Z: ######################################################### syn_AMPA_Z2A = Synapses(excit_pop_Z, target=excit_pop_A, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_Z2A.connect(p=1.) syn_AMPA_Z2B = Synapses(excit_pop_Z, target=excit_pop_B, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_Z2B.connect(p=1.) syn_AMPA_Z2Z = Synapses(excit_pop_Z, target=excit_pop_Z, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_Z2Z.connect(p=1.) syn_AMPA_Z2inhib = Synapses(excit_pop_Z, target=inhib_pop, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_Z2inhib.connect(p=1.) ############################################################################################### # NMDA projections FROM EXCITATORY to INHIB, A,B,Z @network_operation() def update_nmda_sum(): sum_sNMDA_A = sum(excit_pop_A.s_NMDA) sum_sNMDA_B = sum(excit_pop_B.s_NMDA) sum_sNMDA_Z = sum(excit_pop_Z.s_NMDA) # note the _ at the end of s_NMDA_total_ disables unit checking inhib_pop.s_NMDA_total_ = (1.0 * sum_sNMDA_A + 1.0 * sum_sNMDA_B + 1.0 * sum_sNMDA_Z) excit_pop_A.s_NMDA_total_ = (w_pos * sum_sNMDA_A + w_neg * sum_sNMDA_B + w_neg * sum_sNMDA_Z) excit_pop_B.s_NMDA_total_ = (w_neg * sum_sNMDA_A + w_pos * sum_sNMDA_B + w_neg * sum_sNMDA_Z) excit_pop_Z.s_NMDA_total_ = (1.0 * sum_sNMDA_A + 1.0 * sum_sNMDA_B + 1.0 * sum_sNMDA_Z) # set a self-recurrent synapse to introduce a delay when updating the intermediate # gating variable x syn_x_A2A = Synapses(excit_pop_A, excit_pop_A, on_pre="x += 1.", delay=0.5 * b2.ms) syn_x_A2A.connect(j="i") syn_x_B2B = Synapses(excit_pop_B, excit_pop_B, on_pre="x += 1.", delay=0.5 * b2.ms) syn_x_B2B.connect(j="i") syn_x_Z2Z = Synapses(excit_pop_Z, excit_pop_Z, on_pre="x += 1.", delay=0.5 * b2.ms) syn_x_Z2Z.connect(j="i") ############################################################################################### # Define the stimulus: two PoissonInput with time time-dependent mean. poissonStimulus2A = PoissonGroup(N_Group_A, 0. * b2.Hz) syn_Stim2A = Synapses(poissonStimulus2A, excit_pop_A, on_pre="s_AMPA+=w_ext2excit") syn_Stim2A.connect(j="i") poissonStimulus2B = PoissonGroup(N_Group_B, 0. * b2.Hz) syn_Stim2B = Synapses(poissonStimulus2B, excit_pop_B, on_pre="s_AMPA+=w_ext2excit") syn_Stim2B.connect(j="i") @network_operation(dt=stimulus_update_interval) def update_poisson_stimulus(t): if t >= t_stimulus_start and t < t_stimulus_end: offset_A = mu0_mean_stimulus_Hz * (0.5 + 0.5 * coherence_level) offset_B = mu0_mean_stimulus_Hz * (0.5 - 0.5 * coherence_level) rate_A = numpy.random.normal(offset_A, stimulus_std_Hz) rate_A = (max(0, rate_A)) * b2.Hz # avoid negative rate rate_B = numpy.random.normal(offset_B, stimulus_std_Hz) rate_B = (max(0, rate_B)) * b2.Hz poissonStimulus2A.rates = rate_A poissonStimulus2B.rates = rate_B # print("stim on. rate_A= {}, rate_B = {}".format(rate_A, rate_B)) else: # print("stim off") poissonStimulus2A.rates = 0. poissonStimulus2B.rates = 0. ############################################################################################### def get_monitors(pop, monitored_subset_size): """ Internal helper. Args: pop: monitored_subset_size: Returns: """ monitored_subset_size = min(monitored_subset_size, pop.N) idx_monitored_neurons = sample(range(pop.N), monitored_subset_size) rate_monitor = PopulationRateMonitor(pop) # record parameter: record=idx_monitored_neurons is not supported??? spike_monitor = SpikeMonitor(pop, record=idx_monitored_neurons) voltage_monitor = StateMonitor(pop, "v", record=idx_monitored_neurons) return rate_monitor, spike_monitor, voltage_monitor, idx_monitored_neurons # collect data of a subset of neurons: rate_monitor_inhib, spike_monitor_inhib, voltage_monitor_inhib, idx_monitored_neurons_inhib = \ get_monitors(inhib_pop, monitored_subset_size) rate_monitor_A, spike_monitor_A, voltage_monitor_A, idx_monitored_neurons_A = \ get_monitors(excit_pop_A, monitored_subset_size) rate_monitor_B, spike_monitor_B, voltage_monitor_B, idx_monitored_neurons_B = \ get_monitors(excit_pop_B, monitored_subset_size) rate_monitor_Z, spike_monitor_Z, voltage_monitor_Z, idx_monitored_neurons_Z = \ get_monitors(excit_pop_Z, monitored_subset_size) if stop_condition_rate is None: b2.run(max_sim_time) else: sim_sum = 0. * b2.ms sim_batch = 100. * b2.ms samples_in_batch = int(floor(sim_batch / b2.defaultclock.dt)) avg_rate_in_batch = 0 while (sim_sum < max_sim_time) and (avg_rate_in_batch < stop_condition_rate): b2.run(sim_batch) avg_A = numpy.mean(rate_monitor_A.rate[-samples_in_batch:]) avg_B = numpy.mean(rate_monitor_B.rate[-samples_in_batch:]) avg_rate_in_batch = max(avg_A, avg_B) sim_sum += sim_batch print("sim end: {}".format(time.ctime())) ret_vals = dict() ret_vals["rate_monitor_A"] = rate_monitor_A ret_vals["spike_monitor_A"] = spike_monitor_A ret_vals["voltage_monitor_A"] = voltage_monitor_A ret_vals["idx_monitored_neurons_A"] = idx_monitored_neurons_A ret_vals["rate_monitor_B"] = rate_monitor_B ret_vals["spike_monitor_B"] = spike_monitor_B ret_vals["voltage_monitor_B"] = voltage_monitor_B ret_vals["idx_monitored_neurons_B"] = idx_monitored_neurons_B ret_vals["rate_monitor_Z"] = rate_monitor_Z ret_vals["spike_monitor_Z"] = spike_monitor_Z ret_vals["voltage_monitor_Z"] = voltage_monitor_Z ret_vals["idx_monitored_neurons_Z"] = idx_monitored_neurons_Z ret_vals["rate_monitor_inhib"] = rate_monitor_inhib ret_vals["spike_monitor_inhib"] = spike_monitor_inhib ret_vals["voltage_monitor_inhib"] = voltage_monitor_inhib ret_vals["idx_monitored_neurons_inhib"] = idx_monitored_neurons_inhib return ret_vals
def simulate_brunel_network( N_Excit=5000, N_Inhib=None, N_extern=N_POISSON_INPUT, connection_probability=CONNECTION_PROBABILITY_EPSILON, w0=SYNAPTIC_WEIGHT_W0, g=RELATIVE_INHIBITORY_STRENGTH_G, synaptic_delay=SYNAPTIC_DELAY, poisson_input_rate=POISSON_INPUT_RATE, w_external=None, v_rest=V_REST, v_reset=V_RESET, firing_threshold=FIRING_THRESHOLD, membrane_time_scale=MEMBRANE_TIME_SCALE, abs_refractory_period=ABSOLUTE_REFRACTORY_PERIOD, monitored_subset_size=100, random_vm_init=False, sim_time=100.*b2.ms): """ Fully parametrized implementation of a sparsely connected network of LIF neurons (Brunel 2000) Args: N_Excit (int): Size of the excitatory popluation N_Inhib (int): optional. Size of the inhibitory population. If not set (=None), N_Inhib is set to N_excit/4. N_extern (int): optional. Number of presynaptic excitatory poisson neurons. Note: if set to a value, this number does NOT depend on N_Excit and NOT depend on connection_probability (this is different from the book and paper. Only if N_extern is set to 'None', then N_extern is computed as N_Excit*connection_probability. connection_probability (float): probability to connect to any of the (N_Excit+N_Inhib) neurons CE = connection_probability*N_Excit CI = connection_probability*N_Inhib Cexternal = N_extern w0 (float): Synaptic strength J g (float): relative importance of inhibition. J_exc = w0. J_inhib = -g*w0 synaptic_delay (Quantity): Delay between presynaptic spike and postsynaptic increase of v_m poisson_input_rate (Quantity): Poisson rate of the external population w_external (float): optional. Synaptic weight of the excitatory external poisson neurons onto all neurons in the network. Default is None, in that case w_external is set to w0, which is the standard value in the book and in the paper Brunel2000. The purpose of this parameter is to see the effect of external input in the absence of network feedback(setting w0 to 0mV and w_external>0). v_rest (Quantity): Resting potential v_reset (Quantity): Reset potential firing_threshold (Quantity): Spike threshold membrane_time_scale (Quantity): tau_m abs_refractory_period (Quantity): absolute refractory period, tau_ref monitored_subset_size (int): nr of neurons for which a VoltageMonitor is recording Vm random_vm_init (bool): if true, the membrane voltage of each neuron is initialized with a random value drawn from Uniform(v_rest, firing_threshold) sim_time (Quantity): Simulation time Returns: (rate_monitor, spike_monitor, voltage_monitor, idx_monitored_neurons) PopulationRateMonitor: Rate Monitor SpikeMonitor: SpikeMonitor for ALL (N_Excit+N_Inhib) neurons StateMonitor: membrane voltage for a selected subset of neurons list: index of monitored neurons. length = monitored_subset_size """ if N_Inhib is None: N_Inhib = int(N_Excit/4) if N_extern is None: N_extern = int(N_Excit*connection_probability) if w_external is None: w_external = w0 J_excit = w0 J_inhib = -g*w0 lif_dynamics = """ dv/dt = -(v-v_rest) / membrane_time_scale : volt (unless refractory)""" network = NeuronGroup( N_Excit+N_Inhib, model=lif_dynamics, threshold="v>firing_threshold", reset="v=v_reset", refractory=abs_refractory_period, method="linear") if random_vm_init: network.v = random.uniform(v_rest/b2.mV, high=firing_threshold/b2.mV, size=(N_Excit+N_Inhib))*b2.mV else: network.v = v_rest excitatory_population = network[:N_Excit] inhibitory_population = network[N_Excit:] exc_synapses = Synapses(excitatory_population, target=network, on_pre="v += J_excit", delay=synaptic_delay) exc_synapses.connect(p=connection_probability) inhib_synapses = Synapses(inhibitory_population, target=network, on_pre="v += J_inhib", delay=synaptic_delay) inhib_synapses.connect(p=connection_probability) external_poisson_input = PoissonInput(target=network, target_var="v", N=N_extern, rate=poisson_input_rate, weight=w_external) # collect data of a subset of neurons: monitored_subset_size = min(monitored_subset_size, (N_Excit+N_Inhib)) idx_monitored_neurons = sample(range(N_Excit+N_Inhib), monitored_subset_size) rate_monitor = PopulationRateMonitor(network) # record= some_list is not supported? :-( spike_monitor = SpikeMonitor(network, record=idx_monitored_neurons) voltage_monitor = StateMonitor(network, "v", record=idx_monitored_neurons) b2.run(sim_time) return rate_monitor, spike_monitor, voltage_monitor, idx_monitored_neurons
def simulate_wm( N_excitatory=2048, N_inhibitory=512, N_extern_poisson=1000, poisson_firing_rate=1.8 * Hz, sigma_weight_profile=14.4, Jpos_excit2excit=1.63, stimulus1_center_deg=180, stimulus2_center_deg=235, stimulus_width_deg=60, stimulus_strength=0.07 * namp, t_stimulus1_start=0 * ms, t_stimulus2_start=4000 * ms, t_stimulus_duration=0 * ms, t_delay1=3000 * ms, t_delay2=3000 * ms, t_iti_duration=300 * ms, sim_time=2000. * ms, monitored_subset_size=1024): """ Args: N_excitatory (int): Size of the excitatory population N_inhibitory (int): Size of the inhibitory population weight_scaling_factor (float): weight prefactor. When increasing the size of the populations, the synaptic weights have to be decreased. Using the default values, we have N_excitatory*weight_scaling_factor = 2048 and N_inhibitory*weight_scaling_factor=512 N_extern_poisson (int): Size of the external input population (Poisson input) poisson_firing_rate (Quantity): Firing rate of the external population sigma_weight_profile (float): standard deviation of the gaussian input profile in the excitatory population. Jpos_excit2excit (float): Strength of the recurrent input within the excitatory population. Jneg_excit2excit is computed from sigma_weight_profile, Jpos_excit2excit and the normalization condition. stimulus_center_deg (float): Center of the stimulus in [0, 360] stimulus_width_deg (float): width of the stimulus. All neurons in stimulus_center_deg +- (stimulus_width_deg/2) receive the same input current stimulus_strength (Quantity): Input current to the neurons at stimulus_center_deg +- (stimulus_width_deg/2) t_stimulus_start (Quantity): time when the input stimulus is turned on t_stimulus_duration (Quantity): duration of the stimulus. monitored_subset_size (int): nr of neurons for which a Spike- and Voltage monitor is registered. sim_time (Quantity): simulation time Returns: results (tuple): rate_monitor_excit (Brian2 PopulationRateMonitor for the excitatory population), spike_monitor_excit, voltage_monitor_excit, idx_monitored_neurons_excit,\ rate_monitor_inhib, spike_monitor_inhib, voltage_monitor_inhib, idx_monitored_neurons_inhib,\ weight_profile_45 (The weights profile for the neuron with preferred direction = 45deg). """ global par print par devices.device.seed(os.getpid()) # specify the excitatory pyramidal cells: Cm_excit = 0.5 * nF # membrane capacitance of excitatory neurons G_leak_excit = 25.0 * nS # leak conductance E_leak_excit = -70.0 * mV # reversal potential v_firing_threshold_excit = -50.0 * mV # spike condition v_reset_excit = -60.0 * mV # reset voltage after spike t_abs_refract_excit = 2.0 * ms # absolute refractory period # specify the weight profile in the recurrent population # std-dev of the gaussian weight profile around the prefered direction # sigma_weight_profile = 12.0 # std-dev of the gaussian weight profile around the prefered direction # Jneg_excit2excit = 0 # specify the inhibitory interneurons: Cm_inhib = 0.2 * nF G_leak_inhib = 20.0 * nS E_leak_inhib = -70.0 * mV v_firing_threshold_inhib = -50.0 * mV v_reset_inhib = -60.0 * mV t_abs_refract_inhib = 1.0 * ms # specify the AMPA synapses E_AMPA = 0.0 * mV tau_AMPA = 2.0 * ms # specify the GABA synapses E_GABA = -70.0 * mV tau_GABA = 10.0 * ms # specify the NMDA synapses E_NMDA = 0.0 * mV tau_NMDA_s = 100.0 * ms tau_NMDA_x = 2.0 * ms alpha_NMDA = 0.5 * kHz weight_scaling_factor = 2048./N_excitatory # projections from the external population G_extern2inhib = 2.38 * nS G_extern2excit = 3.1 * nS # projectsions from the inhibitory populations G_inhib2inhib = weight_scaling_factor * 1.024 * nS G_inhib2excit = weight_scaling_factor * 1.336 * nS # projections from the excitatory population NMDA G_excit2excit = weight_scaling_factor * 0.28 * nS #nmda+ampa G_excit2inhib = par*weight_scaling_factor * 0.212 * nS # nmda+ampa # recurrent AMPA G_excit2excitA = weight_scaling_factor * 1.* 0.251 * nS #ampa GEEA = G_excit2excitA/G_extern2excit G_excit2inhibA = weight_scaling_factor * 0.192 * nS #ampa GEIA = G_excit2inhibA/G_extern2inhib # STDP taupre = 20 * ms taupost = 20 * ms wmax = 2. #1.1 Apre = 0.00022 #0.00025 #set to zero to deactivate STDP # 0.02 Apost = Apre #-Apre *taupre/taupost*1.03 #1.4 #negative for LTD, positive for LTP stp_decay = 0.04#25 #0.025 # Apost = Apre *taupre/taupost #negative for LTD, positive for LTP # compute the simulus index stim1_center_idx = int(round(N_excitatory / 360. * stimulus1_center_deg)) stim1_width_idx = int(round(N_excitatory / 360. * stimulus_width_deg / 2)) stim1_target_idx = [idx % N_excitatory for idx in range(stim1_center_idx - stim1_width_idx, stim1_center_idx + stim1_width_idx + 1)] stim2_center_idx = int(round(N_excitatory / 360. * stimulus2_center_deg)) stim2_width_idx = int(round(N_excitatory / 360. * stimulus_width_deg / 2)) stim2_target_idx = [idx % N_excitatory for idx in range(stim2_center_idx - stim2_width_idx, stim2_center_idx + stim2_width_idx + 1)] # precompute the weight profile for the recurrent population tmp = math.sqrt(2. * math.pi) * sigma_weight_profile * erf(180. / math.sqrt(2.) / sigma_weight_profile) / 360. Jneg_excit2excit = (1. - Jpos_excit2excit * tmp) / (1. - tmp) presyn_weight_kernel = [(Jneg_excit2excit + (Jpos_excit2excit - Jneg_excit2excit) * math.exp(-.5 * (360. * min(nj, N_excitatory - nj) / N_excitatory) ** 2 / sigma_weight_profile ** 2)) for nj in range(N_excitatory)] fft_presyn_weight_kernel = rfft(presyn_weight_kernel) # define the inhibitory population a = 0.062/mV inhib_lif_dynamics = """ s_NMDA_total : 1 # the post synaptic sum of s. compare with s_NMDA_presyn dv/dt = ( - G_leak_inhib * (v-E_leak_inhib) - G_extern2inhib * s_AMPA * (v-E_AMPA) - G_inhib2inhib * s_GABA * (v-E_GABA) - G_excit2inhib * s_NMDA_total * (v-E_NMDA)/(1.0+1.0*exp(-a*v)/3.57) )/Cm_inhib : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 """ inhib_pop = NeuronGroup( N_inhibitory, model=inhib_lif_dynamics, threshold="v>v_firing_threshold_inhib", reset="v=v_reset_inhib", refractory=t_abs_refract_inhib, method="rk2") # initialize with random voltages: inhib_pop.v = np.random.uniform(v_reset_inhib / mV, high=v_firing_threshold_inhib / mV, size=N_inhibitory) * mV # set the connections: inhib2inhib syn_inhib2inhib = Synapses(inhib_pop, target=inhib_pop, on_pre="s_GABA += 1.0", delay=0.0 * ms) syn_inhib2inhib.connect(condition="i!=j", p=1.0) # syn_inhib2inhib.connect(p=1.0) # set the connections: extern2inhib input_ext2inhib = PoissonInput(target=inhib_pop, target_var="s_AMPA", N=N_extern_poisson, rate=poisson_firing_rate, weight=1.0) # specify the excitatory population: excit_lif_dynamics = """ I_stim : amp s_NMDA_total : 1 # the post synaptic sum of s. compare with s_NMDA_presyn dv/dt = ( - G_leak_excit * (v-E_leak_excit) - G_extern2excit * s_AMPA * (v-E_AMPA) - G_inhib2excit * s_GABA * (v-E_GABA) - G_excit2excit * s_NMDA_total * (v-E_NMDA)/(1.0+1.0*exp(-a*v)/3.57) + I_stim )/Cm_excit : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 ds_NMDA/dt = -s_NMDA/tau_NMDA_s + alpha_NMDA * x * (1-s_NMDA) : 1 dx/dt = -x/tau_NMDA_x : 1 """ excit_pop = NeuronGroup(N_excitatory, model=excit_lif_dynamics, threshold="v>v_firing_threshold_excit", reset="v=v_reset_excit", refractory=t_abs_refract_excit, method="rk2") # initialize with random voltages: excit_pop.v = np.random.uniform(v_reset_excit / mV, high=v_firing_threshold_excit / mV, size=N_excitatory) * mV excit_pop.I_stim = 0. * namp # set the connections: extern2excit input_ext2excit = PoissonInput(target=excit_pop, target_var="s_AMPA", N=N_extern_poisson, rate=poisson_firing_rate, weight=1.0) # set the connections: inhibitory to excitatory syn_inhib2excit = Synapses(inhib_pop, excit_pop, on_pre="s_GABA += 1.0") syn_inhib2excit.connect(p=1.0) # set the connections: excitatory to inhibitory NMDA connections syn_excit2inhib = Synapses(excit_pop, inhib_pop, model="s_NMDA_total_post = s_NMDA_pre : 1 (summed)", method="rk2") syn_excit2inhib.connect(p=1.0) # # set the connections: UNSTRUCTURED excitatory to excitatory # syn_excit2excit = Synapses(excit_pop, excit_pop, # model= "s_NMDA_total_post = s_NMDA_pre : 1 (summed)", method="rk2") # syn_excit2excit.connect(condition="i!=j", p=1.) # set the STRUCTURED recurrent AMPA input # equations for weights, trace decay synapse_eqs = ''' w : 1 stp : 1 dapre/dt = -apre/ taupre : 1 (event-driven) dapost/dt = -apost / taupost : 1 (event-driven) ''' # equations for presynaptic spike eqs_pre = ''' s_AMPA_post += w*stp x_pre += (1.0/N_excitatory)*stp apre += Apre stp = clip(stp + apost - stp_decay * (stp - 1.), 0, wmax) ''' # equations for postsynaptic spike eqs_post = ''' apost += Apost stp = clip(stp + apre, 0, wmax) ''' syn_excit2excit = Synapses(excit_pop, excit_pop, synapse_eqs, on_pre=eqs_pre, on_post=eqs_post) syn_excit2excit.connect(condition='i!=j',p=1.0) syn_excit2excit.stp=1.0 syn_excit2excit.w['abs(i-j)<N_excitatory/2'] = 'GEEA *(Jneg_excit2excit + (Jpos_excit2excit - Jneg_excit2excit) * exp(-.5 * (360. * abs(i-j) / N_excitatory) ** 2 / sigma_weight_profile ** 2))' syn_excit2excit.w['abs(i-j)>=N_excitatory/2'] = 'GEEA *(Jneg_excit2excit + (Jpos_excit2excit - Jneg_excit2excit) * exp(-.5 * (360. * (N_excitatory - abs(i-j)) / N_excitatory) ** 2 / sigma_weight_profile ** 2))' syn_excit2inhibA = Synapses(excit_pop, inhib_pop, model="w : 1", on_pre="s_AMPA_post += w") syn_excit2inhibA.connect(p=1.0) syn_excit2inhibA.w = GEIA # set the STRUCTURED recurrent NMDA input. use a network_operation @network_operation() def update_nmda_sum(): fft_s_NMDA = rfft(excit_pop.s_NMDA) fft_s_NMDA_total = np.multiply(fft_presyn_weight_kernel, fft_s_NMDA) s_NMDA_tot = irfft(fft_s_NMDA_total,N_excitatory) excit_pop.s_NMDA_total_ = s_NMDA_tot # excit_pop.s_NMDA_total = s_NMDA_tot # inhib_pop.s_NMDA_total = fft_s_NMDA[0] @network_operation(dt=100 * ms) def time_counter(t): print(t) @network_operation(dt=1 * ms) def stimulate_network(t): if t >= t_stimulus1_start and t < t_stimulus1_start+t_stimulus_duration: excit_pop.I_stim[stim1_target_idx] = stimulus_strength elif t >= t_stimulus1_start+t_stimulus_duration and t < t_stimulus1_start+t_stimulus_duration+t_delay1: excit_pop.I_stim = 0. * namp elif t >= t_stimulus1_start+t_stimulus_duration+t_delay1 and t < t_stimulus1_start+t_stimulus_duration+t_delay1+t_stimulus_duration: excit_pop.I_stim = -1.*stimulus_strength elif t >= t_stimulus2_start-t_iti_duration and t < t_stimulus2_start: excit_pop.I_stim = 0. * namp elif t >= t_stimulus2_start and t < t_stimulus2_start+t_stimulus_duration: excit_pop.I_stim[stim2_target_idx] = stimulus_strength else: #syn_excit2excit.sgn=-1.0 # neuromodulation change excit_pop.I_stim = 0. * namp def get_monitors(pop, nr_monitored, N): nr_monitored = min(nr_monitored, (N)) idx_monitored_neurons = [int(math.ceil(k)) for k in np.linspace(0, N - 1, nr_monitored + 2)][1:-1] # sample(range(N), nr_monitored) # rate_monitor = PopulationRateMonitor(pop) spike_monitor = SpikeMonitor(pop, record=idx_monitored_neurons) # voltage_monitor = StateMonitor(pop, "v", record=idx_monitored_neurons) synapse_monitor = StateMonitor(syn_excit2excit, "stp", record=syn_excit2excit[stim1_center_idx,stim1_center_idx-10:stim1_center_idx+10], dt=1*ms) # return rate_monitor, spike_monitor, voltage_monitor, idx_monitored_neurons, synapse_monitor return spike_monitor, synapse_monitor # collect data of a subset of neurons: spike_monitor_excit, synapse_monitor_excit = get_monitors(excit_pop, monitored_subset_size, N_excitatory) run(sim_time) return spike_monitor_excit, synapse_monitor_excit
def mk_intcircuit(task_info): """ Creates the 'winner-takes-all' network described in Wang 2002. returns: groups, synapses, update_nmda, subgroups groups, synapses and update_nmda have to be added to the "Network" in order to run the simulation subgroups is used for establishing connections between the sensory and integration circuit; do not add subgroups to the "Network" psr following the published Brian1 code in DB model from Wimmer et al. 2015 - brian2 code - PoissonInput for external connections - no more network_operations - implementation runs in cpp_standalone mode, compatible with SNEP """ # ------------------------------------- # Decision circuit parameters # ------------------------------------- # populations N_E = task_info['dec']['populations'][ 'N_E'] # number of exc neurons (1600) N_I = task_info['dec']['populations']['N_I'] # number of inh neurons (400) sub = task_info['dec']['populations'][ 'sub'] # fraction of stim-selective exc neurons N_D1 = int(N_E * sub) # size of exc pop D1 N_D2 = N_D1 # size of exc pop D2 N_D3 = int(N_E * (1 - 2 * sub)) # size of exc pop D3, the rest # local recurrent connections w_p = task_info['dec']['connectivity'][ 'w_p'] # relative synaptic strength of synapses within pop D1 and D2 w_m = 1 - sub * (w_p - 1) / ( 1 - sub) # relative synaptic strength of synapses across pop D1 and D2 gEEa = task_info['dec']['connectivity'][ 'gEEa'] # AMPA weight of EE synapses gEEn = task_info['dec']['connectivity'][ 'gEEn'] # NMDA weight of EE synapses gEIa = task_info['dec']['connectivity'][ 'gEIa'] # AMPA weight of EI synapses gEIn = task_info['dec']['connectivity'][ 'gEIn'] # NMDA weight of EI synapses gIE = task_info['dec']['connectivity'][ 'gIE'] # GABA weight of IE synapses, vs 1.3*nS from before gII = task_info['dec']['connectivity']['gII'] # GABA weight of II synapses d = task_info['dec']['connectivity'][ 'delay'] # transmission delays of E synapses # external connections gXE = task_info['dec']['connectivity'][ 'gXE'] # weight of XE (ext to exc) synapses gXI = task_info['dec']['connectivity'][ 'gXI'] # weight of XI (ext to inh) synapses # neuron models CmE = task_info['dec']['neuron'][ 'CmE'] # membrane capacitance of E neurons CmI = task_info['dec']['neuron'][ 'CmI'] # membrane capacitance of I neurons gleakE = task_info['dec']['neuron'][ 'gleakE'] # leak conductance of E neurons gleakI = task_info['dec']['neuron'][ 'gleakI'] # leak conductance of I neurons Vl = task_info['dec']['neuron']['Vl'] # resting potential Vt = task_info['dec']['neuron']['Vt'] # spiking threshold Vr = task_info['dec']['neuron']['Vr'] # reset potential tau_refE = task_info['dec']['neuron'][ 'tau_refE'] # absolute refractory period of E neurons tau_refI = task_info['dec']['neuron'][ 'tau_refI'] # absolute refractory period of I neurons nu_ext = task_info['dec']['neuron'][ 'nu_ext'] # firing rate of ext Poisson input to D1 and D2 nu_ext1 = task_info['dec']['neuron'][ 'nu_ext1'] # firing rate of ext Poisson input to D3 and DI # synapse models VrevE = task_info['dec']['synapse'][ 'VrevE'] # reversal potential for E synapses VrevI = task_info['dec']['synapse'][ 'VrevI'] # reversal potential for I synapses tau_ampa = task_info['dec']['synapse'][ 'tau_ampa'] # decay constant of AMPA conductances tau_gaba = task_info['dec']['synapse'][ 'tau_gaba'] # decay constant of GABA conductances tau_nmda_d = task_info['dec']['synapse'][ 'tau_nmda_d'] # decay constant of NMDA conductances tau_nmda_r = task_info['dec']['synapse'][ 'tau_nmda_r'] # rise constant of NMDA conductances alpha_nmda = task_info['dec']['synapse'][ 'alpha_nmda'] # saturation constant of NMDA conductances # namespace with params paramint = { 'w_p': w_p, 'w_m': w_m, 'gEEa': gEEa, 'gEEn': gEEn, 'gEIa': gEIa, 'gEIn': gEIn, 'gIE': gIE, 'gII': gII, 'gXE': gXE, 'gXI': gXI, 'gleakE': gleakE, 'gleakI': gleakI, 'Vl': Vl, 'Vt': Vt, 'Vr': Vr, 'VrevE': VrevE, 'VrevI': VrevI, 'tau_ampa': tau_ampa, 'tau_gaba': tau_gaba, 'tau_nmda_d': tau_nmda_d, 'tau_nmda_r': tau_nmda_r, 'alpha_nmda': alpha_nmda, 'sub': sub, 'CmE': CmE, 'CmI': CmI } # numerical integration method nummethod = task_info['simulation']['nummethod'] # ------------------------------------- # Set up the model and connections # ------------------------------------- # neuron equations eqsE = ''' dV/dt = (-g_ea*(V-VrevE) - g_ent*(V-VrevE)/(1+exp(-V/mV*0.062)/3.57) - g_i*(V-VrevI) - (V-Vl)) / tau : volt (unless refractory) dg_ea/dt = -g_ea / tau_ampa : 1 dg_i/dt = -g_i / tau_gaba : 1 dg_en/dt = -g_en / tau_nmda_d + alpha_nmda * x_en *(1-g_en) : 1 dx_en/dt = -x_en / tau_nmda_r : 1 g_ent : 1 tau = CmE/gleakE : second label : integer (constant) ''' eqsI = ''' dV/dt = (-g_ea*(V-VrevE) - g_entI*(V-VrevE)/(1+exp(-V/mV*0.062)/3.57) - g_i*(V-VrevI) - (V-Vl)) / tau : volt (unless refractory) dg_ea/dt = -g_ea/tau_ampa : 1 dg_i/dt = -g_i/tau_gaba : 1 g_entI = w_nmda * g_ent : 1 g_ent : 1 (linked) w_nmda : 1 tau = CmI/gleakI : second ''' # setup of integration circuit decE = NeuronGroup(N_E, model=eqsE, method=nummethod, threshold='V>=Vt', reset='V=Vr', refractory=tau_refE, namespace=paramint, name='decE') decE1 = decE[:N_D1] decE2 = decE[N_D1:N_D1 + N_D2] decE3 = decE[-N_D3:] decE1.label = 1 decE2.label = 2 decE3.label = 3 decI = NeuronGroup(N_I, model=eqsI, method=nummethod, threshold='V>=Vt', reset='V=Vr', refractory=tau_refI, namespace=paramint, name='decI') # weight according the different subgroups condsame = '(label_pre == label_post and label_pre != 3)' conddiff = '(label_pre != label_post and label_pre != 3) or (label_pre == 3 and label_post != 3)' condrest = '(label_post == 3)' # NMDA: exc --> exc eqsNMDA = ''' g_ent_post = w_nmda * g_en_pre : 1 (summed) w_nmda : 1 (constant) w : 1 (constant) ''' synDEDEn = Synapses(decE, decE, model=eqsNMDA, method=nummethod, on_pre='x_en += w', delay=d, namespace=paramint, name='synDEDEn') synDEDEn.connect() synDEDEn.w['i == j'] = 1 synDEDEn.w['i != j'] = 0 synDEDEn.w_nmda[condsame] = 'w_p * gEEn/gleakE' synDEDEn.w_nmda[conddiff] = 'w_m * gEEn/gleakE' synDEDEn.w_nmda[condrest] = 'gEEn/gleakE' # NMDA: exc --> inh decI.w_nmda = '(gEIn/gleakI) / (gEEn/gleakE)' decI.g_ent = linked_var(decE3, 'g_ent', index=range(N_I)) # AMPA: exc --> exc synDEDEa = Synapses(decE, decE, model='w : 1', method=nummethod, on_pre='g_ea += w', delay=d, namespace=paramint, name='synDEDEa') synDEDEa.connect() synDEDEa.w[condsame] = 'w_p * gEEa/gleakE' synDEDEa.w[conddiff] = 'w_m * gEEa/gleakE' synDEDEa.w[condrest] = 'gEEa/gleakE' # AMPA: exc --> inh synDEDIa = Synapses(decE, decI, model='w : 1', method=nummethod, on_pre='g_ea += w', delay=d, namespace=paramint, name='synDEDIa') synDEDIa.connect() synDEDIa.w = 'gEIa/gleakI' # GABA: inh --> exc synDIDE = Synapses(decI, decE, model='w : 1', method=nummethod, on_pre='g_i += w', delay=d, namespace=paramint, name='synDIDE') synDIDE.connect() synDIDE.w = 'gIE/gleakE' # GABA: inh --> inh synDIDI = Synapses(decI, decI, model='w : 1', method=nummethod, on_pre='g_i += w', delay=d, namespace=paramint, name='synDIDI') synDIDI.connect() synDIDI.w = 'gII/gleakI' # external inputs and connections extE = PoissonInput(decE[:N_D1 + N_D2], 'g_ea', N=1, rate=nu_ext1, weight='gXE/gleakE') extE3 = PoissonInput(decE3, 'g_ea', N=1, rate=nu_ext, weight='gXE/gleakE') extI = PoissonInput(decI, 'g_ea', N=1, rate=nu_ext, weight='gXI/gleakI') # variables to return groups = {'DE': decE, 'DI': decI, 'DX': extE, 'DX3': extE3, 'DXI': extI} subgroups = {'DE1': decE1, 'DE2': decE2, 'DE3': decE3} synapses = { 'synDEDEn': synDEDEn, 'synDEDEa': synDEDEa, 'synDEDIa': synDEDIa, 'synDIDE': synDIDE, 'synDIDI': synDIDI } # 'synDEDIn': synDEDIn, return groups, synapses, subgroups
def simulate_wm( N_excitatory=1024, N_inhibitory=256, N_extern_poisson=1000, poisson_firing_rate=1.4 * b2.Hz, weight_scaling_factor=2., sigma_weight_profile=20., Jpos_excit2excit=1.6, stimulus_center_deg=180, stimulus_width_deg=40, stimulus_strength=0.07 * b2.namp, t_stimulus_start=0 * b2.ms, t_stimulus_duration=0 * b2.ms, monitored_subset_size=1024, sim_time=800. * b2.ms): """ Args: N_excitatory (int): Size of the excitatory population N_inhibitory (int): Size of the inhibitory population weight_scaling_factor (float): weight prefactor. When increasing the size of the populations, the synaptic weights have to be decreased. Using the default values, we have N_excitatory*weight_scaling_factor = 2048 and N_inhibitory*weight_scaling_factor=512 N_extern_poisson (int): Size of the external input population (Poisson input) poisson_firing_rate (Quantity): Firing rate of the external population sigma_weight_profile (float): standard deviation of the gaussian input profile in the excitatory population. Jpos_excit2excit (float): Strength of the recurrent input within the excitatory population. Jneg_excit2excit is computed from sigma_weight_profile, Jpos_excit2excit and the normalization condition. stimulus_center_deg (float): Center of the stimulus in [0, 360] stimulus_width_deg (float): width of the stimulus. All neurons in stimulus_center_deg +\- (stimulus_width_deg/2) receive the same input current stimulus_strength (Quantity): Input current to the neurons at stimulus_center_deg +\- (stimulus_width_deg/2) t_stimulus_start (Quantity): time when the input stimulus is turned on t_stimulus_duration (Quantity): duration of the stimulus. monitored_subset_size (int): nr of neurons for which a Spike- and Voltage monitor is registered. sim_time (Quantity): simulation time Returns: results (tuple): rate_monitor_excit (Brian2 PopulationRateMonitor for the excitatory population), spike_monitor_excit, voltage_monitor_excit, idx_monitored_neurons_excit,\ rate_monitor_inhib, spike_monitor_inhib, voltage_monitor_inhib, idx_monitored_neurons_inhib,\ weight_profile_45 (The weights profile for the neuron with preferred direction = 45deg). """ # specify the excitatory pyramidal cells: Cm_excit = 0.5 * b2.nF # membrane capacitance of excitatory neurons G_leak_excit = 25.0 * b2.nS # leak conductance E_leak_excit = -70.0 * b2.mV # reversal potential v_firing_threshold_excit = -50.0 * b2.mV # spike condition v_reset_excit = -60.0 * b2.mV # reset voltage after spike t_abs_refract_excit = 2.0 * b2.ms # absolute refractory period # specify the weight profile in the recurrent population # std-dev of the gaussian weight profile around the prefered direction # sigma_weight_profile = 12.0 # std-dev of the gaussian weight profile around the prefered direction # # Jneg_excit2excit = 0 # specify the inhibitory interneurons: Cm_inhib = 0.2 * b2.nF G_leak_inhib = 20.0 * b2.nS E_leak_inhib = -70.0 * b2.mV v_firing_threshold_inhib = -50.0 * b2.mV v_reset_inhib = -60.0 * b2.mV t_abs_refract_inhib = 1.0 * b2.ms # specify the AMPA synapses E_AMPA = 0.0 * b2.mV tau_AMPA = .9 * 2.0 * b2.ms # specify the GABA synapses E_GABA = -70.0 * b2.mV tau_GABA = 10.0 * b2.ms # specify the NMDA synapses E_NMDA = 0.0 * b2.mV tau_NMDA_s = .65 * 100.0 * b2.ms # orig: 100 tau_NMDA_x = .94 * 2.0 * b2.ms alpha_NMDA = 0.5 * b2.kHz # projections from the external population G_extern2inhib = 2.38 * b2.nS G_extern2excit = 3.1 * b2.nS # projectsions from the inhibitory populations G_inhib2inhib = weight_scaling_factor * .35 * 1.024 * b2.nS G_inhib2excit = weight_scaling_factor * .35 * 1.336 * b2.nS # projections from the excitatory population G_excit2excit = weight_scaling_factor * .35 * 0.381 * b2.nS G_excit2inhib = weight_scaling_factor * .35 * 1.2 * 0.292 * b2.nS # todo: verify this scaling t_stimulus_end = t_stimulus_start + t_stimulus_duration # compute the simulus index stim_center_idx = int(round(N_excitatory / 360. * stimulus_center_deg)) stim_width_idx = int(round(N_excitatory / 360. * stimulus_width_deg / 2)) stim_target_idx = [idx % N_excitatory for idx in range(stim_center_idx - stim_width_idx, stim_center_idx + stim_width_idx + 1)] # precompute the weight profile for the recurrent population tmp = math.sqrt(2. * math.pi) * sigma_weight_profile * erf(180. / math.sqrt(2.) / sigma_weight_profile) / 360. Jneg_excit2excit = (1. - Jpos_excit2excit * tmp) / (1. - tmp) presyn_weight_kernel = \ [(Jneg_excit2excit + (Jpos_excit2excit - Jneg_excit2excit) * math.exp(-.5 * (360. * min(j, N_excitatory - j) / N_excitatory) ** 2 / sigma_weight_profile ** 2)) for j in range(N_excitatory)] # validate the normalization condition: (360./N_excitatory)*sum(presyn_weight_kernel)/360. fft_presyn_weight_kernel = rfft(presyn_weight_kernel) weight_profile_45 = deque(presyn_weight_kernel) rot_dist = int(round(len(weight_profile_45) / 8)) weight_profile_45.rotate(rot_dist) # define the inhibitory population inhib_lif_dynamics = """ s_NMDA_total : 1 # the post synaptic sum of s. compare with s_NMDA_presyn dv/dt = ( - G_leak_inhib * (v-E_leak_inhib) - G_extern2inhib * s_AMPA * (v-E_AMPA) - G_inhib2inhib * s_GABA * (v-E_GABA) - G_excit2inhib * s_NMDA_total * (v-E_NMDA)/(1.0+1.0*exp(-0.062*v/volt)/3.57) )/Cm_inhib : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 """ inhib_pop = NeuronGroup( N_inhibitory, model=inhib_lif_dynamics, threshold="v>v_firing_threshold_inhib", reset="v=v_reset_inhib", refractory=t_abs_refract_inhib, method="rk2") # initialize with random voltages: inhib_pop.v = numpy.random.uniform(v_reset_inhib / b2.mV, high=v_firing_threshold_inhib / b2.mV, size=N_inhibitory) * b2.mV # set the connections: inhib2inhib syn_inhib2inhib = Synapses(inhib_pop, target=inhib_pop, on_pre="s_GABA += 1.0", delay=0.0 * b2.ms) syn_inhib2inhib.connect(condition="i!=j", p=1.0) # set the connections: extern2inhib input_ext2inhib = PoissonInput(target=inhib_pop, target_var="s_AMPA", N=N_extern_poisson, rate=poisson_firing_rate, weight=1.0) # specify the excitatory population: excit_lif_dynamics = """ I_stim : amp s_NMDA_total : 1 # the post synaptic sum of s. compare with s_NMDA_presyn dv/dt = ( - G_leak_excit * (v-E_leak_excit) - G_extern2excit * s_AMPA * (v-E_AMPA) - G_inhib2excit * s_GABA * (v-E_GABA) - G_excit2excit * s_NMDA_total * (v-E_NMDA)/(1.0+1.0*exp(-0.062*v/volt)/3.57) + I_stim )/Cm_excit : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 ds_NMDA/dt = -s_NMDA/tau_NMDA_s + alpha_NMDA * x * (1-s_NMDA) : 1 dx/dt = -x/tau_NMDA_x : 1 """ excit_pop = NeuronGroup(N_excitatory, model=excit_lif_dynamics, threshold="v>v_firing_threshold_excit", reset="v=v_reset_excit; x+=1.0", refractory=t_abs_refract_excit, method="rk2") # initialize with random voltages: excit_pop.v = numpy.random.uniform(v_reset_excit / b2.mV, high=v_firing_threshold_excit / b2.mV, size=N_excitatory) * b2.mV excit_pop.I_stim = 0. * b2.namp # set the connections: extern2excit input_ext2excit = PoissonInput(target=excit_pop, target_var="s_AMPA", N=N_extern_poisson, rate=poisson_firing_rate, weight=1.0) # set the connections: inhibitory to excitatory syn_inhib2excit = Synapses(inhib_pop, target=excit_pop, on_pre="s_GABA += 1.0") syn_inhib2excit.connect(p=1.0) # set the connections: excitatory to inhibitory NMDA connections syn_excit2inhib = Synapses(excit_pop, inhib_pop, model="s_NMDA_total_post = s_NMDA_pre : 1 (summed)", method="rk2") syn_excit2inhib.connect(p=1.0) # # set the connections: UNSTRUCTURED excitatory to excitatory # syn_excit2excit = Synapses(excit_pop, excit_pop, # model= "s_NMDA_total_post = s_NMDA_pre : 1 (summed)", method="rk2") # syn_excit2excit.connect(condition="i!=j", p=1.) # set the STRUCTURED recurrent input. use a network_operation @network_operation() def update_nmda_sum(): fft_s_NMDA = rfft(excit_pop.s_NMDA) fft_s_NMDA_total = numpy.multiply(fft_presyn_weight_kernel, fft_s_NMDA) s_NMDA_tot = irfft(fft_s_NMDA_total) excit_pop.s_NMDA_total_ = s_NMDA_tot @network_operation(dt=1 * b2.ms) def stimulate_network(t): if t >= t_stimulus_start and t < t_stimulus_end: # excit_pop[stim_start_i - 15:stim_start_i + 15].I_stim = 0.25 * b2.namp # Todo: review indexing # print("stim on") excit_pop.I_stim[stim_target_idx] = stimulus_strength else: # print("stim off") excit_pop.I_stim = 0. * b2.namp def get_monitors(pop, nr_monitored, N): nr_monitored = min(nr_monitored, (N)) idx_monitored_neurons = \ [int(math.ceil(k)) for k in numpy.linspace(0, N - 1, nr_monitored + 2)][1:-1] # sample(range(N), nr_monitored) rate_monitor = PopulationRateMonitor(pop) # record= some_list is not supported? :-( spike_monitor = SpikeMonitor(pop, record=idx_monitored_neurons) voltage_monitor = StateMonitor(pop, "v", record=idx_monitored_neurons) return rate_monitor, spike_monitor, voltage_monitor, idx_monitored_neurons # collect data of a subset of neurons: rate_monitor_inhib, spike_monitor_inhib, voltage_monitor_inhib, idx_monitored_neurons_inhib = \ get_monitors(inhib_pop, monitored_subset_size, N_inhibitory) rate_monitor_excit, spike_monitor_excit, voltage_monitor_excit, idx_monitored_neurons_excit = \ get_monitors(excit_pop, monitored_subset_size, N_excitatory) b2.run(sim_time) return \ rate_monitor_excit, spike_monitor_excit, voltage_monitor_excit, idx_monitored_neurons_excit,\ rate_monitor_inhib, spike_monitor_inhib, voltage_monitor_inhib, idx_monitored_neurons_inhib,\ weight_profile_45
def sim_decision_making_network_full( N_Excit=400, N_Inhib=100, weight_scaling_factor=5.33, t_stimulus_start=100 * b2.ms, t_stimulus_duration=9999 * b2.ms, coherence_level=0.0, stimulus_update_interval=30 * b2.ms, mu0_mean_stimulus_Hz=40., stimulus_std_Hz=10., N_extern=1000, firing_rate_extern=9.8 * b2.Hz, w_pos=2.4, f_Subpop_size=0.25, # .15 in publication [1] max_sim_time=2000. * b2.ms, stop_condition_rate=20 * b2.Hz, monitored_subset_size=512, ): # print('Simulation starts') startting_time = time.time() t_stimulus_end = t_stimulus_start + t_stimulus_duration N_Group_A = int( N_Excit * f_Subpop_size ) # size of the excitatory subpopulation sensitive to stimulus A N_Group_B = N_Group_A # size of the excitatory subpopulation sensitive to stimulus B N_Group_Z = N_Excit - N_Group_A - N_Group_B # (1-2f)Ne excitatory neurons do not respond to either stimulus. Cm_excit = 0.5 * b2.nF # membrane capacitance of excitatory neurons G_leak_excit = 25.0 * b2.nS # leak conductance E_leak_excit = -70.0 * b2.mV # reversal potential v_spike_thr_excit = -50.0 * b2.mV # spike condition v_reset_excit = -55.0 * b2.mV # reset voltage after spike t_abs_refract_excit = 2.0 * b2.ms # absolute refractory period # specify the inhibitory interneurons: # N_Inhib = 200 Cm_inhib = 0.2 * b2.nF G_leak_inhib = 20.0 * b2.nS E_leak_inhib = -70.0 * b2.mV v_spike_thr_inhib = -50.0 * b2.mV v_reset_inhib = -55.0 * b2.mV t_abs_refract_inhib = 1.0 * b2.ms # specify the AMPA synapses E_AMPA = 0.0 * b2.mV tau_AMPA = 2.0 * b2.ms # specify the GABA synapses E_GABA = -70.0 * b2.mV tau_GABA = 2.0 * b2.ms # specify the NMDA synapses # projections from the external population g_AMPA_extern2inhib = 1.62 * b2.nS g_AMPA_extern2excit = 2.1 * b2.nS # projectsions from the inhibitory populations g_GABA_inhib2inhib = weight_scaling_factor * 1.25 * b2.nS g_GABA_inhib2excit = weight_scaling_factor * 1.60 * b2.nS # projections from the excitatory population g_AMPA_excit2excit = 2.1 * weight_scaling_factor * 0.012 * b2.nS g_AMPA_excit2inhib = 0.14 * weight_scaling_factor * 0.015 * b2.nS # weights and "adjusted" weights. w_neg = 1. - f_Subpop_size * (w_pos - 1.) / (1. - f_Subpop_size) w_ext2inhib = g_AMPA_extern2inhib / g_AMPA_excit2inhib w_ext2excit = g_AMPA_extern2excit / g_AMPA_excit2excit # other weights are 1 # Define the inhibitory population # dynamics: inhib_lif_dynamics = """ dv/dt = ( - G_leak_inhib * (v-E_leak_inhib) - g_AMPA_excit2inhib * s_AMPA * (v-E_AMPA) - g_GABA_inhib2inhib * s_GABA * (v-E_GABA) )/Cm_inhib : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 """ inhib_pop = NeuronGroup(N_Inhib, model=inhib_lif_dynamics, threshold="v>v_spike_thr_inhib", reset="v=v_reset_inhib", refractory=t_abs_refract_inhib, method="rk2") # initialize with random voltages: inhib_pop.v = rnd.uniform(v_spike_thr_inhib / b2.mV - 4., high=v_spike_thr_inhib / b2.mV - 1., size=N_Inhib) * b2.mV # Specify the excitatory population: # dynamics: excit_lif_dynamics = """ dv/dt = ( - G_leak_excit * (v-E_leak_excit) - g_AMPA_excit2excit * s_AMPA * (v-E_AMPA) - g_GABA_inhib2excit * s_GABA * (v-E_GABA) )/Cm_excit : volt (unless refractory) ds_AMPA/dt = -s_AMPA/tau_AMPA : 1 ds_GABA/dt = -s_GABA/tau_GABA : 1 """ # define the three excitatory subpopulations. # A: subpop receiving stimulus A excit_pop_A = NeuronGroup(N_Group_A, model=excit_lif_dynamics, threshold="v > v_spike_thr_excit", reset="v = v_reset_excit", refractory=t_abs_refract_excit, method="rk2") excit_pop_A.v = rnd.uniform(E_leak_excit / b2.mV, high=E_leak_excit / b2.mV + 5., size=excit_pop_A.N) * b2.mV # B: subpop receiving stimulus B excit_pop_B = NeuronGroup(N_Group_B, model=excit_lif_dynamics, threshold="v > v_spike_thr_excit", reset="v = v_reset_excit", refractory=t_abs_refract_excit, method="rk2") excit_pop_B.v = rnd.uniform(E_leak_excit / b2.mV, high=E_leak_excit / b2.mV + 5., size=excit_pop_B.N) * b2.mV # Z: non-sensitive excit_pop_Z = NeuronGroup(N_Group_Z, model=excit_lif_dynamics, threshold="v>v_spike_thr_excit", reset="v=v_reset_excit", refractory=t_abs_refract_excit, method="rk2") excit_pop_Z.v = rnd.uniform(v_reset_excit / b2.mV, high=v_spike_thr_excit / b2.mV - 1., size=excit_pop_Z.N) * b2.mV # now define the connections: # projections FROM EXTERNAL POISSON GROUP: #################################################### poisson2Inhib = PoissonInput(target=inhib_pop, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2inhib) poisson2A = PoissonInput(target=excit_pop_A, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2excit) poisson2B = PoissonInput(target=excit_pop_B, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2excit) poisson2Z = PoissonInput(target=excit_pop_Z, target_var="s_AMPA", N=N_extern, rate=firing_rate_extern, weight=w_ext2excit) ############################################################################################### # GABA projections FROM INHIBITORY population: ################################################ syn_inhib2inhib = Synapses(inhib_pop, target=inhib_pop, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2inhib.connect(p=1.) syn_inhib2A = Synapses(inhib_pop, target=excit_pop_A, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2A.connect(p=1.) syn_inhib2B = Synapses(inhib_pop, target=excit_pop_B, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2B.connect(p=1.) syn_inhib2Z = Synapses(inhib_pop, target=excit_pop_Z, on_pre="s_GABA += 1.0", delay=0.5 * b2.ms) syn_inhib2Z.connect(p=1.) ############################################################################################### # AMPA projections FROM EXCITATORY A: ######################################################### syn_AMPA_A2A = Synapses(excit_pop_A, target=excit_pop_A, on_pre="s_AMPA += w_pos", delay=0.5 * b2.ms) syn_AMPA_A2A.connect(p=1.) syn_AMPA_A2B = Synapses(excit_pop_A, target=excit_pop_B, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_A2B.connect(p=1.) syn_AMPA_A2Z = Synapses(excit_pop_A, target=excit_pop_Z, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_A2Z.connect(p=1.) syn_AMPA_A2inhib = Synapses(excit_pop_A, target=inhib_pop, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_A2inhib.connect(p=1.) ############################################################################################### # AMPA projections FROM EXCITATORY B: ######################################################### syn_AMPA_B2A = Synapses(excit_pop_B, target=excit_pop_A, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_B2A.connect(p=1.) syn_AMPA_B2B = Synapses(excit_pop_B, target=excit_pop_B, on_pre="s_AMPA += w_pos", delay=0.5 * b2.ms) syn_AMPA_B2B.connect(p=1.) syn_AMPA_B2Z = Synapses(excit_pop_B, target=excit_pop_Z, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_B2Z.connect(p=1.) syn_AMPA_B2inhib = Synapses(excit_pop_B, target=inhib_pop, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_B2inhib.connect(p=1.) ############################################################################################### # AMPA projections FROM EXCITATORY Z: ######################################################### syn_AMPA_Z2A = Synapses(excit_pop_Z, target=excit_pop_A, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_Z2A.connect(p=1.) syn_AMPA_Z2B = Synapses(excit_pop_Z, target=excit_pop_B, on_pre="s_AMPA += w_neg", delay=0.5 * b2.ms) syn_AMPA_Z2B.connect(p=1.) syn_AMPA_Z2Z = Synapses(excit_pop_Z, target=excit_pop_Z, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_Z2Z.connect(p=1.) syn_AMPA_Z2inhib = Synapses(excit_pop_Z, target=inhib_pop, on_pre="s_AMPA += 1.0", delay=0.5 * b2.ms) syn_AMPA_Z2inhib.connect(p=1.) ############################################################################################### # Define the stimulus: two PoissonInput with time time-dependent mean. poissonStimulus2A = PoissonGroup(N_Group_A, 0. * b2.Hz) syn_Stim2A = Synapses(poissonStimulus2A, excit_pop_A, on_pre="s_AMPA+=w_ext2excit") syn_Stim2A.connect(j="i") poissonStimulus2B = PoissonGroup(N_Group_B, 0. * b2.Hz) syn_Stim2B = Synapses(poissonStimulus2B, excit_pop_B, on_pre="s_AMPA+=w_ext2excit") syn_Stim2B.connect(j="i") @network_operation(dt=stimulus_update_interval) def update_poisson_stimulus(t): if t >= t_stimulus_start and t < t_stimulus_end: offset_A = mu0_mean_stimulus_Hz * (1 + 0.01 * coherence_level) offset_B = mu0_mean_stimulus_Hz * (1 - 0.01 * coherence_level) rate_A = numpy.random.normal(offset_A, stimulus_std_Hz) rate_A = (max(0, rate_A)) * b2.Hz # avoid negative rate rate_B = numpy.random.normal(offset_B, stimulus_std_Hz) rate_B = (max(0, rate_B)) * b2.Hz poissonStimulus2A.rates = rate_A poissonStimulus2B.rates = rate_B else: poissonStimulus2A.rates = 0. poissonStimulus2B.rates = 0. ############################################################################################### def get_monitors(pop, monitored_subset_size): monitored_subset_size = min(monitored_subset_size, pop.N) idx_monitored_neurons = sample(range(pop.N), monitored_subset_size) rate_monitor = PopulationRateMonitor(pop) spike_monitor = SpikeMonitor(pop, record=idx_monitored_neurons) voltage_monitor = StateMonitor(pop, "v", record=idx_monitored_neurons) return rate_monitor, spike_monitor, voltage_monitor, idx_monitored_neurons # collect data of a subset of neurons: rate_monitor_inhib, spike_monitor_inhib, voltage_monitor_inhib, idx_monitored_neurons_inhib = \ get_monitors(inhib_pop, monitored_subset_size) rate_monitor_A, spike_monitor_A, voltage_monitor_A, idx_monitored_neurons_A = \ get_monitors(excit_pop_A, monitored_subset_size) rate_monitor_B, spike_monitor_B, voltage_monitor_B, idx_monitored_neurons_B = \ get_monitors(excit_pop_B, monitored_subset_size) rate_monitor_Z, spike_monitor_Z, voltage_monitor_Z, idx_monitored_neurons_Z = \ get_monitors(excit_pop_Z, monitored_subset_size) if stop_condition_rate is None: b2.run(max_sim_time) else: sim_sum = 0. * b2.ms sim_batch = 25. * b2.ms samples_in_batch = int(floor(sim_batch / b2.defaultclock.dt)) avg_rate_in_batch = 0 while (sim_sum < max_sim_time) and (avg_rate_in_batch < stop_condition_rate): b2.run(sim_batch) avg_A = numpy.mean(rate_monitor_A.rate[-samples_in_batch:]) avg_B = numpy.mean(rate_monitor_B.rate[-samples_in_batch:]) avg_rate_in_batch = max(avg_A, avg_B) sim_sum += sim_batch print("Time elapsed =", time.time() - startting_time, 'seconds') ret_vals = dict() ret_vals["rate_monitor_A"] = rate_monitor_A ret_vals["spike_monitor_A"] = spike_monitor_A ret_vals["voltage_monitor_A"] = voltage_monitor_A ret_vals["idx_monitored_neurons_A"] = idx_monitored_neurons_A ret_vals["rate_monitor_B"] = rate_monitor_B ret_vals["spike_monitor_B"] = spike_monitor_B ret_vals["voltage_monitor_B"] = voltage_monitor_B ret_vals["idx_monitored_neurons_B"] = idx_monitored_neurons_B ret_vals["rate_monitor_Z"] = rate_monitor_Z ret_vals["spike_monitor_Z"] = spike_monitor_Z ret_vals["voltage_monitor_Z"] = voltage_monitor_Z ret_vals["idx_monitored_neurons_Z"] = idx_monitored_neurons_Z ret_vals["rate_monitor_inhib"] = rate_monitor_inhib ret_vals["spike_monitor_inhib"] = spike_monitor_inhib ret_vals["voltage_monitor_inhib"] = voltage_monitor_inhib ret_vals["idx_monitored_neurons_inhib"] = idx_monitored_neurons_inhib return ret_vals
pop_e_sel[0].rate = 30 * Hz solver = MFSolver.rates_voltages(system, solver='simplex', maxiter=1) #sol = solver.run() #print(sol) #system.graph().view(cleanup=True) # at 1s, select population 1 C_selection = int(f * C_ext) rate_selection = 50 * Hz stimuli1 = TimedArray(np.r_[np.zeros(40), np.ones(2), np.zeros(1000)], dt=25 * ms) input1 = PoissonInput(pop_e_sel[0].brian2, 's_noise_E_sel_0', C_selection, rate_selection, 'stimuli1(t)') # at 2s, select population 2 stimuli2 = TimedArray(np.r_[np.zeros(80), np.ones(2), np.zeros(100)], dt=25 * ms) input2 = PoissonInput(pop_e_sel[1].brian2, 's_noise_E_sel_1', C_selection, rate_selection, 'stimuli2(t)') net = system.collect_brian2_network(*all_sp, *all_rm, input1, input2) net.run(4 * second, report='stdout') # plotting plots.rates(all_rm, 25 * ms)