'b': 60., 'C_m': 200., 'V_m': -60., 'w': 0., 'tau_syn_ex': 0.2 } pop = nngt.NeuralPop.uniform(1000, neuron_model='aeif_psc_alpha', neuron_param=di_param) net = nngt.generation.erdos_renyi(avg_deg=100, nodes=1000, population=pop, weights=43.) gids = net.to_nest() ''' Record from it ''' rec_param = [{'to_file': True}] recorder, recorded = monitor_nodes(gids, params=rec_param, network=net) nest.Simulate(2000.) activity = pna.analysis.raster_analysis(recorder[0], limits=[300., np.inf]) ''' Plot the spikes with sorted neurons ''' pprint(activity.properties()) pna.plot.raster_plot(activity, sort='spikes') plt.show()
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")
#~ nngt.generation.connect_neural_types(graph, 1, 1, "random_scale_free", {"in_exp":2.1, "out_exp":2.9, "density":0.05}) #~ nngt.generation.connect_neural_types(graph, -1, 1, "erdos_renyi", {"density": 0.05}) #~ nngt.generation.connect_neural_types(graph, -1, -1, "erdos_renyi", {"density": 0.01}) graph = nngt.generation.erdos_renyi(density=0.1, population=pop, weight_prop={"distrib":"gaussian", "distrib_prop":{"avg":avg}}) #~ nngt.generation.random_scale_free(2.2, 2.9, density=0.15, from_graph=graph) #~ graph = nngt.generation.newman_watts(10, 0.1, population=pop) #-----------------------------------------------------------------------------# # NEST objects #------------------------ # subnet, gids = make_nest_network(graph) recorders, record = monitor_nodes(gids, ["spike_detector"], [["spikes"]], network=graph) recorders2, record2 = monitor_nodes((gids[0],), ["multimeter"], [["V_m","w"]]) set_noise(gids, 0., 200.) rate = 20000. if nmodel == "aeif_cond_exp": rate = 56000. #~ set_poisson_input(gids[670:870], rate) set_poisson_input(gids[:800], rate) set_poisson_input(gids[800:], 0.75*rate) #-----------------------------------------------------------------------------# # Names
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=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()