def RasterPlot(self, SpikesP, SpikesE, SpikesI, title='Title', markersize=.5): fig = Figure(Panel(SpikesP.spiketrains, xticks=False, ylabel='Input', color='k', markersize=markersize), Panel(SpikesE.spiketrains, xticks=False, ylabel='Excitatory', color='r', markersize=markersize), Panel(SpikesI.spiketrains, xticks=True, xlabel='Time(ms)', ylabel='Inhibitory', color='b', markersize=markersize), title=title, settings={'figure.figsize': [9., 6.]}) '''for ax in fig.fig.axes: ax.set_xticks(np.linspace(0, self.sim_params['simtime'], 6, endpoint = True))''' fig.fig.subplots_adjust(hspace=0) return fig
def test_SpikeSourceArray(self): spike_times = [50.] p = sim.Population(3, sim.SpikeSourceArray(spike_times=spike_times)) p2 = sim.Population(3, sim.Hardware_IF_cond_exp()) syn = sim.StaticSynapse(weight=0.012) con = sim.Projection(p, p2, connector=sim.OneToOneConnector(), synapse_type=syn, receptor_type='excitatory') spike_times_g = p.get('spike_times') p2.record('v') sim.run(100.0) weights = nan_to_num(con.get('weight', format="array")) print weights data = p2.get_data().segments[0] vm = data.filter(name="v")[0] print vm Figure( Panel(weights, data_labels=["ext->cell"], line_properties=[{ 'xticks': True, 'yticks': True, 'cmap': 'Greys' }]), Panel(vm, ylabel="Membrane potential (mV)", data_labels=["excitatory", "excitatory"], line_properties=[{ 'xticks': True, 'yticks': True }]), ).save("result")
def main(argv=None): run_time = 10000 rospy.init_node("offline_spinnaker") np.random.seed(12345) spinn_network = SpinnakerNetwork(n_neurons=20) spinn_network.setup() spinn_network.make_inference_network() rospy.loginfo("SpiNNaker network ready: starting to run") print "running" Frontend.run(run_time) # Getting specific data from the recordings input_spikes = spinn_network.populations['spike_sender'].get_data('spikes') cann_spikes = spinn_network.populations['cann_pop'].get_data('spikes') cann_spikes_count = spinn_network.populations['cann_pop'].get_spike_counts( gather=True) cann_v = spinn_network.populations['cann_pop'].get_data('v') inhib_spikes = spinn_network.populations['inh_pop'].get_data('spikes') inhib_spikes_count = spinn_network.populations['inh_pop'].get_spike_counts( gather=True) inhib_v = spinn_network.populations['inh_pop'].get_data('v') print "Spikes per neuron in cann_net: ", cann_spikes_count winner = max(cann_spikes_count, key=cann_spikes_count.get) print "The most active neuron is NeuronID:", winner print "spikes in inhib_pop\n\n", inhib_spikes_count Frontend.end() # Plotting the data Figure(Panel(input_spikes.segments[0].spiketrains, xticks=True, yticks=True, markersize=.2, xlim=(0, run_time)), Panel(cann_spikes.segments[0].spiketrains, xticks=True, yticks=True, markersize=.2, xlim=(0, run_time)), Panel(inhib_spikes.segments[0].spiketrains, xticks=True, yticks=True, markersize=.2, xlim=(0, run_time)), Panel(cann_v.segments[0].filter(name='v')[0], ylabel="Memb pot (mV) for Cann", xticks=True, yticks=True, xlim=(0, run_time)), annotations="Simulated with {}".format(Frontend.name())) plt.show()
def plotBlackAndWhite(): Figure(Panel(spiketrains, ylabel="Neuron ID", yticks=True), Panel(voltage[0], xlabel="Time (ms)", ylabel="Membrane potential (mV)", data_labels=[pop_exc.label], xticks=True, yticks=True), title="Recurrent Spiking Neural Network", annotations="Simulated with {}".format( sim.name())) #.save("recurrent_snn.png") plt.legend(loc="lower right") plt.show()
def plot( populations, plot_title=None, annotations=None ): if populations != []: panels = [] for variable in ( 'v', 'u', 'gsyn_exc', 'gsyn_inh', 's', 'w' ): for population in populations: data_segment = population.get_data().segments[0] data = None if variable != 's' and data_segment.filter( name=variable ) != []: data = data_segment.filter( name=variable )[0] elif variable == 's' and data_segment.spiketrains != []: data = data_segment.spiketrains if data is not None: panels.append( Panel( data, ylabel=get_y_label( variable ), yticks=True, data_labels=[population.label] ), ) panels[-1].options.update( xticks=True, xlabel="Time (ms)" ) Figure( *panels, title=plot_title if plot_title != None else "", annotations=annotations if annotations != None else "" ) plt.show() else: print( "No population, no plot!" )
def run_sim(self): sim.run(self.sim_t) # === Save the results, optionally plot a figure ============================= # filename = normalized_filename("Results" , "Izhikevich" , "pkl" , # options.simulator , sim.num_processes()) # self.ens.write_data(filename , annotations = {'script_name': __file__}) if options.plot_figure: from pyNN.utility.plotting import Figure, Panel data = self.ens.get_data().segments[0] v = data.filter(name="v")[0] # u = data.filter(name="u")[0] Figure( Panel(v, ylabel="Membrane potential (mV)", xticks=True, xlabel="Time (ms)", yticks=True), # Panel(u, ylabel="u variable (units?)"), annotations="Simulated with %s" % options.simulator.upper()).save("en.png") # === Clean up and quit ======================================================== sim.end()
def test_levels(rates=(500, 1000), weights=(0.005, 0.0005)): counter = 0 receive_pop = [] spike_input = [] p.setup(timestep=1, min_delay=1, max_delay=127) p.set_number_of_neurons_per_core(p.IF_cond_exp, 10) for rate in rates: for weight in weights: pop_size = 10 receive_pop.append(p.Population(pop_size, p.IF_cond_exp( ))) #, label="receive_pop{}-{}".format(rate, weight))) receive_pop[counter].record(['spikes', 'v']) #["spikes"]) # Connect key spike injector to input population spike_input.append( p.Population(pop_size, p.SpikeSourcePoisson(rate=rate)) ) #, label="input_connect{}-{}".format(rate, weight))) p.Projection(spike_input[counter], receive_pop[counter], p.OneToOneConnector(), p.StaticSynapse(weight=weight)) print "reached here 1" runtime = 11000 counter += 1 p.run(runtime) print "reached here 2" for i in range(counter): weight_index = i % len(weights) rate_index = (i - weight_index) / len(weights) print weight_index print rate_index # for j in range(receive_pop_size): spikes = receive_pop[i].get_data('spikes').segments[0].spiketrains v = receive_pop[i].get_data('v').segments[0].filter(name='v')[0] plt.figure("rate = {} - weight = {}".format(rates[rate_index], weights[weight_index])) Figure(Panel(spikes, xlabel="Time (ms)", ylabel="nID", xticks=True), Panel(v, ylabel="Membrane potential (mV)", yticks=True)) plt.show() # End simulation p.end()
def plot_signal(record, seg=-1): """ Plot voltage trace for all output neurons (seg=-1 corresponds to last trial no.) """ data = record.segments[seg] vm = data.filter(name="v")[0] Figure(Panel(vm, ylabel="Membrane potential (mV)", xlabel="Time (ms)", xticks=True, yticks=True))
def do_run(plot): p.setup(timestep=1.0) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } def create_grid(n, label, dx=1.0, dy=1.0): grid_structure = p.Grid2D(dx=dx, dy=dy, x0=0.0, y0=0.0) return p.Population(n * n, p.IF_curr_exp(**cell_params_lif), structure=grid_structure, label=label) # Parameters n = 5 weight_to_spike = 2.0 delay = 2 runtime = 1000 p.set_number_of_neurons_per_core(p.IF_curr_exp, 100) # Network population small_world = create_grid(n, 'small_world') # SpikeInjector injectionConnection = [(0, 0)] spikeArray = {'spike_times': [[0]]} inj_pop = p.Population(1, p.SpikeSourceArray(**spikeArray), label='inputSpikes_1') # Injector projection p.Projection(inj_pop, small_world, p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=delay)) # Connectors degree = 2.0 rewiring = 0.4 rng = NumpyRNG(seed=1) small_world_connector = p.SmallWorldConnector(degree, rewiring, rng=rng) # Projection for small world grid sw_pro = p.Projection(small_world, small_world, small_world_connector, p.StaticSynapse(weight=2.0, delay=5)) small_world.record(['v', 'spikes']) p.run(runtime) v = small_world.get_data('v') spikes = small_world.get_data('spikes') weights = sw_pro.get('weight', 'list') if plot: # pylint: disable=no-member Figure( # raster plot of the presynaptic neuron spike times Panel(spikes.segments[0].spiketrains, yticks=True, markersize=0.2, xlim=(0, runtime), xticks=True), # membrane potential of the postsynaptic neuron Panel(v.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[small_world.label], yticks=True, xlim=(0, runtime), xticks=True), title="Simple small world connector", annotations="Simulated with {}".format(p.name())) plt.show() p.end() return v, spikes, weights
MyProgressBar(10.0, 1000.0), SetRate(p, rate_generator, interval) ]) # === Retrieve recorded data, and count the spikes in each interval ========== data = p.get_data().segments[0] all_spikes = np.hstack([st.magnitude for st in data.spiketrains]) spike_counts = [((all_spikes >= x) & (all_spikes < x + interval)).sum() for x in range(0, 1000, interval)] expected_spike_counts = [ p.size * rate * interval / 1000.0 for rate in range(0, 100, rate_increment) ] print("\nActual spike counts: {}".format(spike_counts)) print("Expected mean spike counts: {}".format(expected_spike_counts)) if options.plot_figure: Figure(Panel(data.spiketrains, xlabel="Time (ms)", xticks=True, markersize=0.5), title="Incrementally updated SpikeSourceArrays", annotations="Simulated with %s" % options.simulator.upper()).save( normalized_filename("Results", "update_spike_source_array", "png", options.simulator)) sim.end()
p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=1))) populations[0].record(['v', 'gsyn_exc', 'gsyn_inh', 'spikes']) p.run(runtime) # get data (could be done as one, but can be done bit by bit as well) data = populations[0].get_data(['v', 'gsyn_exc', 'spikes', 'gsyn_inh']) figure_filename = "results.png" Figure( # raster plot of the presynaptic neuron spike times Panel(data.segments[0].spiketrains, yticks=True, markersize=0.2, xlim=(0, runtime)), # membrane potential of the postsynaptic neuron Panel(data.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[populations[0].label], yticks=True, xlim=(0, runtime)), Panel(data.segments[0].filter(name='gsyn_exc')[0], ylabel="gsyn excitatory (mV)", data_labels=[populations[0].label], yticks=True, xlim=(0, runtime)), Panel(data.segments[0].filter(name='gsyn_inh')[0], ylabel="gsyn inhibitory (mV)", data_labels=[populations[0].label],
syn = sim.StaticSynapse(weight=w, delay=syn_delay) input_conns = sim.Projection(spike_source, cells, sim.FixedProbabilityConnector(0.5), syn) # === Run simulation =========================================================== sim.run(simtime) filename = normalized_filename("Results", "small_network", "pkl", options.simulator, sim.num_processes()) cells.write_data(filename, annotations={'script_name': __file__}) print("Mean firing rate: ", cells.mean_spike_count() * 1000.0 / simtime, "Hz") if options.plot_figure: from pyNN.utility.plotting import Figure, Panel figure_filename = filename.replace("pkl", "png") data = cells.get_data().segments[0] vm = data.filter(name="v")[0] gsyn = data.filter(name="gsyn_exc")[0] Figure( Panel(vm, ylabel="Membrane potential (mV)"), Panel(gsyn, ylabel="Synaptic conductance (uS)"), Panel(data.spiketrains, xlabel="Time (ms)", xticks=True), annotations="Simulated with %s" % options.simulator.upper() ).save(figure_filename) print(figure_filename) # === Clean up and quit ======================================================== sim.end()
def make_panel(population, label): return Panel( population.get_data().segments[0].filter(name='gsyn_inh')[0], data_labels=[label], yticks=True)
input = net.populations["Ext"] input.record('spikes') exc = net.populations["Exc"] exc.record(["spikes", "nrn_V", "syn_A", "syn_B"]) inh = net.populations["Inh"] inh.record(["spikes", "nrn_V", "syn_A"]) sim.run(10.0) input_data = input.get_data().segments[0] exc_data = exc.get_data().segments[0] inh_data = inh.get_data().segments[0] #import pdb; pdb.set_trace() #all.write_data("brunel_network_components_test.h5") sim.end() Figure( Panel(input_data.spiketrains), Panel(exc_data.analogsignalarrays[0], yticks=True), Panel(exc_data.analogsignalarrays[1], yticks=True), Panel(exc_data.analogsignalarrays[2], yticks=True), #Panel(exc_data.spiketrains), Panel(inh_data.analogsignalarrays[0], yticks=True), Panel(inh_data.analogsignalarrays[1], yticks=True, xticks=True, xlabel="Time (ms)"), #Panel(inh_data.spiketrains, xticks=True, xlabel="Time (ms)"), ).save("brunel_network_components_test.png")
else: i = 0 print("cart \t\t|\t\t angle") while i < len(scores[0]): print("{:8}\t{:8}".format(scores[0][i], scores[0][i+1])) i += 2 spikes_n = null_pop.get_data('spikes').segments[0].spiketrains v_n = null_pop.get_data('v').segments[0].filter(name='v')[0] spikes_o = output_pop.get_data('spikes').segments[0].spiketrains v_o = output_pop.get_data('v').segments[0].filter(name='v')[0] g_o = output_pop.get_data('gsyn_exc').segments[0].filter(name='gsyn_exc')[0] spikes_o2 = output_pop2.get_data('spikes').segments[0].spiketrains v_o2 = output_pop2.get_data('v').segments[0].filter(name='v')[0] g_o2 = output_pop2.get_data('gsyn_exc').segments[0].filter(name='gsyn_exc')[0] plt.figure("spikes out {}".format(label)) Figure( Panel(spikes_n, xlabel="Time (ms)", ylabel="nID", xticks=True), Panel(v_n, ylabel="Membrane potential (mV)", yticks=True), Panel(spikes_o, xlabel="Time (ms)", ylabel="nID", xticks=True), Panel(v_o, ylabel="Membrane potential (mV)", yticks=True), Panel(g_o, ylabel="Gsyn_exc potential (mV)", yticks=True), Panel(spikes_o2, xlabel="Time (ms)", ylabel="nID", xticks=True), Panel(v_o2, ylabel="Membrane potential (mV)", yticks=True), Panel(g_o2, ylabel="Gsyn_exc potential (mV)", yticks=True) ) plt.show() print('rate = ', rate) p.end()
p.FromListConnector(injectionConnection_2), p.StaticSynapse(weight=weight_to_spike, delay=1)) main_pop.record("spikes") second_main_pop.record("spikes") p.run(run_time) # get data (could be done as one, but can be done bit by bit as well) spikes1 = main_pop.get_data('spikes') spikes2 = second_main_pop.get_data("spikes") Figure( # raster plot of the pre_synaptic neuron spike times Panel(spikes1.segments[0].spiketrains, ylabel="spikes from first pop", yticks=True, markersize=0.2, xlim=(0, run_time)), # membrane potential of the post_synaptic neuron Panel(spikes2.segments[0].spiketrains, ylabel="spikes from second pop", yticks=True, markersize=0.2, xlim=(0, run_time)), title="large data Simple synfire chain example", annotations="Simulated with {}".format(p.name())) plt.show() p.end()
gsyn_mean = neo.AnalogSignal(gsyn.mean(axis=1).reshape(-1, 1), sampling_rate=gsyn.sampling_rate) gsyn_mean.channel_index = neo.ChannelIndex(np.array([0])) gsyn_mean.name = 'gsyn_inh_mean' data[label].analogsignals.append(gsyn_mean) def make_panel(population, label): return Panel( population.get_data().segments[0].filter(name='gsyn_inh')[0], data_labels=[label], yticks=True) panels = [ Panel(data['depressing, deterministic'].filter(name='gsyn_inh')[0][:, 0], data_labels=['depressing, deterministic'], yticks=True, ylim=[0, 0.008]), Panel(data['depressing, stochastic'].filter(name='gsyn_inh_mean')[0], data_labels=['depressing, stochastic mean'], yticks=True, ylim=[0, 0.008]), Panel( data['facilitating, deterministic'].filter(name='gsyn_inh')[0][:, 0], data_labels=['facilitating, deterministic'], yticks=True, ylim=[0, 0.002]), Panel(data['facilitating, stochastic'].filter(name='gsyn_inh_mean')[0], data_labels=['facilitating, stochastic mean'], yticks=True,
return w0 + numpy.where(t >= t0, wp * numpy.exp(-(t - t0) / tau), wn * numpy.exp((t - t0) / tau)) p0 = (-1.0, 5e-8, 1e-8, -1.2e-8, 20.0) popt, pcov = plasticity_data.fit_curve(double_exponential, p0, ftol=1e-10) print( "Best fit parameters: t0={0}, w0={1}, wp={2}, wn={3}, tau={4}".format( *popt)) if options.plot_figure: from pyNN.utility.plotting import Figure, Panel, DataTable figure_filename = filename.replace("pkl", "png") Figure( # raster plot of the presynaptic neuron spike times Panel(presynaptic_data.spiketrains, yticks=True, markersize=0.2, xlim=(0, t_stop)), # membrane potential of the postsynaptic neuron Panel(postsynaptic_data.filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[p2.label], yticks=True, xlim=(0, t_stop)), # evolution of the synaptic weights with time Panel(weights, xticks=True, yticks=True, xlabel="Time (ms)", legend=False, xlim=(0, t_stop)), # scatterplot of the final weight of each synapse against the relative
filename = normalized_filename(save_dir, "input", "pkl", options.simulator) input.write_data(filename, annotations={'script_name': __file__}) filename = normalized_filename(save_dir, "hidden", "pkl", options.simulator) hidden.write_data(filename, annotations={'script_name': __file__}) filename = normalized_filename(save_dir, "output", "pkl", options.simulator) output.write_data(filename, annotations={'script_name': __file__}) if options.plot_figure: from pyNN.utility.plotting import Figure, Panel figure_filename = filename.replace("pkl", "png") Figure( Panel(hidden.get_data().segments[0].spiketrains, ylabel="Membrane potential (mV)", yticks=True, ylim=(-66, -48)), Panel(hidden.get_data().segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, ylim=(-1.2, 1.2), legend=False), Panel(output.get_data().segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[output.label], yticks=True, ylim=(-3, 3)), # title="Membrane potential of hidden and output layers", annotations="Simulated with %s" % options.simulator.upper()).save(figure_filename) print(figure_filename)
# === Run the simulation ===================================================== sim.run(100.0) # === Save the results, optionally plot a figure ============================= filename = normalized_filename("Results", "cell_type_demonstration", "pkl", options.simulator) all_neurons.write_data(filename, annotations={'script_name': __file__}) if options.plot_figure: from pyNN.utility.plotting import Figure, Panel figure_filename = filename.replace("pkl", "png") Figure(Panel(cuba_exp.get_data().segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[cuba_exp.label], yticks=True, ylim=(-66, -48)), Panel(hh.get_data().segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[hh.label], yticks=True, ylim=(-100, 60)), Panel(adexp.get_data().segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[adexp.label], yticks=True, ylim=(-75, -40)), Panel(adexp.get_data().segments[0].filter(name='w')[0], ylabel="w (nA)", data_labels=[adexp.label],
p.run(run_time) print stdp_connection.get('weight', 'list') # get v for each example v_my_model_pop = my_model_pop.get_data('v') v_my_model_my_synapse_type_pop = my_model_my_synapse_type_pop.get_data('v') v_my_model_my_additional_input_pop = my_model_my_additional_input_pop.get_data( 'v') v_my_model_my_threshold_pop = my_model_my_threshold_pop.get_data('v') Figure( # membrane potentials for each example Panel(v_my_model_pop.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[my_model_pop.label], yticks=True, xlim=(0, run_time)), Panel(v_my_model_my_synapse_type_pop.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[my_model_my_synapse_type_pop.label], yticks=True, xlim=(0, run_time)), Panel(v_my_model_my_additional_input_pop.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[my_model_my_additional_input_pop.label], yticks=True, xlim=(0, run_time)), Panel(v_my_model_my_threshold_pop.segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", data_labels=[my_model_my_threshold_pop.label],
count = 0 for t in spiketrain: count += 1 st_count.append(count) predicted = st_count.index(max(st_count)) membranes_0 = fc0.get_data().segments[-1].analogsignals[0] #membranes_1 = fc1.get_data().segments[-1].analogsignals[0] #membranes_2 = fc2.get_data().segments[-1].analogsignals[0] from pyNN.utility.plotting import Figure, Panel Figure( Panel(membranes_0[:, 15:25], ylabel="Membrane potential (mV)", xticks=True, xlabel="Time (ms)", yticks=True)) #Figure( # Panel(membranes_1[:,15:25], ylabel="Membrane potential (mV)", xticks=True, # xlabel="Time (ms)", yticks=True)) # #Figure( # Panel(membranes_2[:,:10], ylabel="Membrane potential out (mV)", xticks=True, # xlabel="Time (ms)", yticks=True)) ## animate sample #fig=plt.figure('nmnist sample') #for t in range(sample_image.shape[0]): # data = np.array([sample_image[t,0,:,:],
for label, p in populations.items(): filename = normalized_filename("Results", "stochastic_synapses_%s" % label, "pkl", options.simulator) p.write_data(filename, annotations={'script_name': __file__}) if options.plot_figure: from pyNN.utility.plotting import Figure, Panel figure_filename = normalized_filename("Results", "stochastic_synapses_", "png", options.simulator) panels = [] for variable in ('gsyn_inh', 'v'): for population in populations.values(): panels.append( Panel( population.get_data().segments[0].filter(name=variable)[0], data_labels=[population.label], yticks=True), ) # add ylabel to top panel in each group panels[0].options.update(ylabel=u'Synaptic conductance (µS)') panels[3].options.update(ylabel='Membrane potential (mV)') # add xticks and xlabel to final panel panels[-1].options.update(xticks=True, xlabel="Time (ms)") Figure(*panels, title="Example of simple stochastic synapses", annotations="Simulated with %s" % options.simulator.upper()).save(figure_filename) print(figure_filename) # === Clean up and quit ========================================================
neurons.initialize(v=-70.0, u=-14.0) # === Run the simulation ===================================================== sim.run(Trec_ms) # === Save the results, optionally plot a figure ============================= filename = normalized_filename("Results", "Izhikevich", "pkl", options.simulator, sim.num_processes()) if options.plot_figure: from pyNN.utility.plotting import Figure, Panel figure_filename = filename.replace("pkl", "pdf") data = neurons.get_data().segments[0] v = data.filter(name="v")[0] u = data.filter(name="u")[0] Figure( Panel(v, ylabel="Membrane potential (mV)", xticks=True, xlabel="Time (ms)", yticks=True), Panel(u, ylabel="Recovery variable (mV)", xticks=True, xlabel="Time (ms)", yticks=True), #Panel(u, ylabel="u variable (units?)"), annotations="Simulated with %s" % options.simulator.upper()).save(figure_filename) print(figure_filename)
# Set up callbacks to occur when spikes are received live_spikes_connection_receive.add_receive_callback( "pop_forward", receive_spikes) live_spikes_connection_receive.add_receive_callback( "pop_backward", receive_spikes) # Run the simulation on spiNNaker Frontend.run(run_time) spikes_forward = pop_forward.get_data('spikes') spikes_backward = pop_backward.get_data('spikes') Figure( # raster plot of the presynaptic neuron spike times Panel(spikes_forward.segments[0].spiketrains, yticks=True, markersize=0.2, xlim=(0, run_time)), Panel(spikes_backward.segments[0].spiketrains, yticks=True, markersize=0.2, xlim=(0, run_time)), title="Simple synfire chain example with injected spikes", annotations="Simulated with {}".format(Frontend.name())) plt.show() # Clear data structures on spiNNaker to leave the machine in a clean state for # future executions Frontend.end()
I_pop, Ext_conn, receptor_type="excitatory", synapse_type=pynn.StaticSynapse(weight=J_E * 10, delay=delay_distr)) # Record stuff E_pop.record("spikes") pynn.run(sim_time) esp = None isp = None pe = None pi = None v_esp = None esp = E_pop.get_data("spikes") Figure( # raster plot of the presynaptic neuron spike times Panel(esp.segments[0].spiketrains, yticks=True, markersize=1, xlim=(0, sim_time)), title="Simple synfire chain example", annotations="Simulated with {}".format(pynn.name())) plt.show() pynn.end()
ifcell[0:2].record(('v', 'gsyn_exc')) run(200.0) for (population, variables, filename) in simulator.state.write_on_end: io = get_io(filename) population.write_data(filename, variables) simulator.state.write_on_end = [] end() data = ifcell.get_data().segments[0] vm = data.filter(name="v")[0] gsyn = data.filter(name="gsyn_exc")[0] Figure(Panel(vm, ylabel="Membrane potential (mV)"), Panel(gsyn, ylabel="Synaptic conductance (uS)"), Panel(data.spiketrains, xlabel="Time (ms)", xticks=True)).save("simulation_results.png") ''' v_value=ifcell.get_data() print(v_value.segments[0].analogsignals[0].shape) plt.figure() plt.plot(v_value.segments[0].analogsignals[0]) plt.plot(v_value.segments[0].analogsignals[1]) plt.show() ''' import pickle f = open('ifcell.pkl', 'rb') ifcell_load = pickle.load(f)
def send_spike(label, sender): time.sleep(0.01) print "Sending spike to neuron 0" sender.send_spike(label, 0) live_connection.add_receive_callback('pop_1', receive_spikes_1) live_connection.add_receive_callback("pop_2", receive_spikes_2) live_connection.add_start_callback("inputSpikes_1", send_spike) p.run(runtime) # get data (could be done as one, but can be done bit by bit as well) spikes_1 = populations[0].get_data('spikes') spikes_2 = populations[1].get_data('spikes') line_properties = [{'color': 'red', 'markersize': 2}, {'color': 'blue', 'markersize': 2}] Figure( # raster plot of the presynaptic neuron spike times Panel(spikes_1.segments[0].spiketrains, spikes_2.segments[0].spiketrains, yticks=True, line_properties=line_properties, xlim=(0, runtime)), title="Simple synfire chain example", annotations="Simulated with {}".format(p.name()) ) plt.show() p.end()
# +-------------------------------------------------------------------+ # Record neurons' potentials pre_pop.record(['v', 'spikes']) post_pop.record(['v', 'spikes']) # Run simulation sim.run(simtime) print("Weights:{}".format(plastic_projection.get('weight', 'list'))) pre_spikes = pre_pop.get_data('spikes') post_spikes = post_pop.get_data('spikes') Figure( # raster plot of the presynaptic neuron spike times Panel(pre_spikes.segments[0].spiketrains, yticks=True, markersize=0.2, xlim=(0, simtime)), Panel(post_spikes.segments[0].spiketrains, yticks=True, markersize=0.2, xlim=(0, simtime)), title="stdp example curr", annotations="Simulated with {}".format(sim.name())) plt.show() # End simulation on SpiNNaker sim.end()
cann_2_inh = sim.Projection(cann_pop, inhib_pop, sim.AllToAllConnector(), sim.StaticSynapse(weight=0.02, delay=0.1), receptor_type="excitatory") inh_2_cann = sim.Projection(inhib_pop, cann_pop, sim.AllToAllConnector(), sim.StaticSynapse(weight=0.2, delay=0.1), receptor_type="inhibitory") #spike_source.record('spikes') cann_pop.record(('v', 'spikes')) inhib_pop.record(('v', 'spikes')) sim.run(5000.0) from pyNN.utility.plotting import Figure, Panel cann_data = cann_pop.get_data().segments[0] cann_vm = cann_data.filter(name="v")[0] inh_data = inhib_pop.get_data().segments[0] inh_vm = inh_data.filter(name="v")[0] Figure( Panel(cann_vm, ylabel="Cann Membrane potential (mV)", yticks=True), Panel(cann_data.spiketrains, yticks=True), Panel(inh_vm, ylabel="Inh Membrane potential (mV)", yticks=True), Panel(inh_data.spiketrains, xlabel="Time (ms)", yticks=True, xticks=True)) sim.end()