"print_time": True, "overwrite_files": True, 'local_num_threads': 4, "rng_seeds": [5, 6, 7, 8] }) gids = net.to_nest() pg = ns.set_poisson_input(gids, rate=p_rate, syn_spec={ "weight": J_ex, "delay": delay }) ns.set_minis(net, base_rate=0.1) recorders, records = ns.monitor_groups(["excitatory", "inhibitory"], network=net) nest.Simulate(simtime) if nngt.get_config('with_plot'): ideg = net.get_degrees("in", syn_type="inhibitory") edeg = net.get_degrees("in", syn_type="excitatory") # plot the basic activity ns.plot_activity(recorders, records, network=net, show=False) # sort by firing rate ns.plot_activity(recorders, records,
def test_utils(): ''' Check NEST utility functions ''' nest = pytest.importorskip("nest") import nngt.simulation as ns nest.ResetKernel() resol = nest.GetKernelStatus('resolution') w = 5. net, gids = make_nest_net(100, w, deg=10) # set inputs ns.set_noise(gids, 0., 20.) assert len(nest.GetConnections()) == net.edge_nb() + net.node_nb() ns.set_poisson_input(gids, 5.) assert len(nest.GetConnections()) == net.edge_nb() + 2 * net.node_nb() ns.set_minis(net, base_rate=1.5, weight=2.) assert len(nest.GetConnections()) == net.edge_nb() + 3 * net.node_nb() ns.set_step_currents(gids[::2], times=[40., 60.], currents=[800., 0.]) min_conn = net.edge_nb() + 3 * net.node_nb() + 1 max_conn = net.edge_nb() + 4 * net.node_nb() num_conn = len(nest.GetConnections()) assert min_conn <= num_conn <= max_conn # check randomization of neuronal properties vms = {d['V_m'] for d in nest.GetStatus(gids)} assert len(vms) == 1 ns.randomize_neural_states(net, {'V_m': ('uniform', -70., -60.)}) vms = {d['V_m'] for d in nest.GetStatus(gids)} assert len(vms) == net.node_nb() # monitoring nodes sd, _ = ns.monitor_groups(net.population, net) assert len(nest.GetConnections()) == num_conn + net.node_nb() vm, rec = ns.monitor_nodes(gids[0], nest_recorder='voltmeter', params={'interval': resol}) assert len(nest.GetConnections()) == num_conn + net.node_nb() + 1 nest.Simulate(100.) ns.plot_activity(show=False) ns.plot_activity(vm, rec, show=True)
def activity_simulation(net, pop, sim_duration=sim_duration): ''' Execute activity simulation on the generated graph -------------------------------------------------- Input : net : nngt generated graph with model pop : neurons population sim_duration : time (s) duration of simulation Output : activity graphs ''' if (nngt.get_config('with_nest')) and (simulate_activity is True): print("SIMULATE ACTIVITY") import nngt.simulation as ns import nest nest.ResetKernel() nest.SetKernelStatus({'local_num_threads': 14}) nest.SetKernelStatus({'resolution': .5}) gids = net.to_nest() # nngt.simulation.randomize_neural_states(net, {"w": ("uniform", 0, 200), # "V_m": ("uniform", -70., -40.)}) nngt.simulation.randomize_neural_states(net, { "w": ("normal", 50., 5.), "V_m": ("uniform", -80., -50.) }) # add noise to the excitatory neurons excs = list(gids) # ns.set_noise(excs, 10., 2.) # ns.set_poisson_input(gids, rate=3500., syn_spec={"weight": 34.}) target_rate = 25. # 2019 11 13 OLD VERSION TO THIS DATE # According to Mallory nngt now dealse differently with # minis-rate and weight, automatically normalizing with the degree average_degree = net.edge_nb() / float(net.node_nb()) syn_rate = target_rate / average_degree print("syn_rate", syn_rate) print("avg_deg", average_degree) # ns.set_minis(net, base_rate=syn_rate, weight=.4, gids=gids ns.set_minis(net, base_rate=target_rate, weight=.4 * synaptic_weigth, gids=gids) vm, vs = ns.monitor_nodes([1, 10], "voltmeter") recorders, records = ns.monitor_groups(pop.keys(), net) nest.Simulate(sim_duration) if plot_activity is True: print("Plot raster") ns.plot_activity(vm, vs, network=net, show=False) ns.plot_activity(recorders, records, network=net, show=False, histogram=True) plt.show() if animation_movie is True: print("Process animation") anim = nngt.plot.AnimationNetwork(recorders, net, resolution=0.1, interval=20, decimate=-1) # ~ anim.save_movie("structured_bursting.mp4", fps=2, start=650., # ~ stop=1500, interval=20) # ~ anim.save_movie("structured_bursting.mp4", fps=5, num_frames=50) anim.save_movie("structured_bursting.mp4", fps=15, interval=10) if save_spikes is True: print("Save sikes of neurons") nngt.simulation.save_spikes("spikes_output.dat")
def activity_simulation(net, pop, sim_duration=5000.): ''' Execute activity simulation on the generated graph -------------------------------------------------- Input : net : nngt generated graph with model pop : neurons population sim_duration : time (s) duration of simulation Output : activity graphs ''' if nngt.get_config('with_nest'): import nngt.simulation as ns import nest nest.ResetKernel() nest.SetKernelStatus({'local_num_threads': 14}) gids = net.to_nest() #nngt.simulation.randomize_neural_states(net, {"w": ("uniform", 0, 200), # "V_m": ("uniform", -70., -40.)}) nngt.simulation.randomize_neural_states(net, { "w": ("normal", 50., 5.), "V_m": ("uniform", -80., -50.) }) # add noise to the excitatory neurons excs = list(gids) #ns.set_noise(excs, 10., 2.) #ns.set_poisson_input(gids, rate=3500., syn_spec={"weight": 34.}) target_rate = 25. average_degree = net.edge_nb() / float(net.node_nb()) syn_rate = target_rate / average_degree print("syn_rate", syn_rate) print("avg_deg", average_degree) ns.set_minis(net, base_rate=syn_rate, weight_fraction=.4, gids=gids) vm, vs = ns.monitor_nodes([1], "voltmeter") recorders, records = ns.monitor_groups(pop.keys(), net) nest.Simulate(5000) # ~ if nngt.get_config('with_plot'): # ~ ns.plot_activity(vm, vs, network=net, show=False) # ~ ns.plot_activity(recorders, records, network=net, show=False, hist=True) anim = nngt.plot.AnimationNetwork(recorders, net, resolution=0.1, interval=20, decimate=-1) # ~ anim.save_movie("structured_bursting.mp4", fps=2, start=650., # ~ stop=1500, interval=20) # ~ anim.save_movie("structured_bursting.mp4", fps=5, num_frames=50) anim.save_movie("structured_bursting.mp4", fps=15, interval=10) plt.show()