def do_one_to_one_conductance_test(self, neurons_per_core, pre_size, post_size, weight, delay): sim.setup(1.0) sim.set_number_of_neurons_per_core(sim.IF_cond_exp, neurons_per_core) pre = sim.Population(pre_size, sim.IF_cond_exp()) post = sim.Population(post_size, sim.IF_cond_exp()) proj = sim.Projection(pre, post, sim.OneToOneConnector(), sim.StaticSynapse(weight=weight, delay=delay)) sim.run(0) conns = proj.get(["weight", "delay"], "list") sim.end() for pre, post, w, d in conns: assert pre == post assert numpy.allclose(w, weight, rtol=0.0001) assert d == delay
def do_run(): p.setup(timestep=1, min_delay=1, max_delay=15) spiker = p.Population(1, p.SpikeSourceArray(spike_times=[[0]]), label='inputSSA_1') if_pop = p.Population(2, p.IF_cond_exp(), label='pop_1') if_pop.record("spikes") if_pop.record("v") p.Projection(spiker, if_pop, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory", source=None, space=None) p.run(30) all1 = if_pop.get_data(["spikes", "v"]) p.reset() p.run(30) all2 = if_pop.get_data(["spikes", "v"]) p.end() return (all1, all2)
def add_correlation_population(sim, populations, projections): print("Adding a input/output correlation population...") #Define neuron model for population (long intergration time) propably the same as the others corr_neuron_model_params = populations[1].celltype.default_parameters input_size = populations[0].size # Make a population that correlates input and output corr_pop = sim.Population(input_size, cellclass=sim.IF_cond_exp(), label='corr_pop') # Add it to populations populations.append(corr_pop) #Weight for just one spike low_weight = 0.01 weight = 0.1 #Proj from input (remember delay) #Add to projections projections.append( sim.Projection(populations[0], corr_pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=low_weight, delay=len(populations) - 1), receptor_type='excitatory')) #Proj from output classes #Add to projections from_list = [(7, x, weight, 0) for x in range(input_size)] projections.append( sim.Projection(populations[-2], corr_pop, sim.FromListConnector(from_list), receptor_type='excitatory')) return populations, projections
def do_run(): """ test that tests the printing of v from a pre determined recording :return: """ p.setup(timestep=0.04, min_delay=1.0, max_delay=4.0) n_neurons = 128 * 128 # number of neurons in each population p.set_number_of_neurons_per_core(p.IF_cond_exp, 256) 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, 'e_rev_E': 0., 'e_rev_I': -80. } populations = list() projections = list() weight_to_spike = 0.035 delay = 1.7 current_file_path = os.path.dirname(os.path.abspath(__file__)) spikes_file = os.path.join(current_file_path, 'test.spikes') spikes = read_spikefile(spikes_file, n_neurons) populations.append( p.Population(n_neurons, p.SpikeSourceArray(spike_times=spikes), label='inputSpikes_1')) populations.append( p.Population(n_neurons, p.IF_cond_exp(**cell_params_lif), label='pop_1')) projections.append( p.Projection(populations[0], populations[1], p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=weight_to_spike, delay=delay))) populations[1].record("spikes") p.run(1000) spikes = populations[1].get_data("spikes") p.end() return spikes
def run_network(timestep, steps_per_timestep): p.setup(timestep, max_delay=1.0) pre = p.Population(1, p.SpikeSourceArray(range(0, 100, 10))) post = p.Population(1, p.IF_cond_exp(), additional_parameters={ "n_steps_per_timestep": steps_per_timestep}) post.record(["v", "spikes"]) p.Projection(pre, post, p.AllToAllConnector(), p.StaticSynapse(weight=0.13)) p.run(100) v = post.get_data("v").segments[0].filter(name='v')[0] spikes = post.get_data("spikes").segments[0].spiketrains p.end() return v, spikes
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 do_run(): p.setup(timestep=1, min_delay=1) spiker = p.Population(1, p.SpikeSourceArray(spike_times=[[5, 25]]), label='inputSSA') if_pop = p.Population(1, p.IF_cond_exp(), label='pop') if_pop.record("spikes") if_pop.record("v") runtime = 30 # Create projection with delay such that the second spike occurs after # the run has finished weight = 5.0 delay = 7 p.Projection(spiker, if_pop, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=weight, delay=delay), receptor_type="excitatory", source=None, space=None) p.run(runtime) all1 = if_pop.get_data(["spikes", "v"]) # Reset (to time=0) and run again p.reset() p.run(runtime) all2 = if_pop.get_data(["spikes", "v"]) p.end() return (all1, all2)
'cm': 0.0001, 'tau_m': 0.8325, 'tau_syn_E': 0.001, 'tau_syn_I': 0.001, 'tau_refrac': 0.0 } cellvalues = {'v': 0.25} #cellvalues = {'v': -0.25} # debe haber simetria t2 = [[2, 3, 4, 8], [2, 4, 6, 8]] t1 = [2, 12] input_celltype = sim.SpikeSourceArray(spike_times=t1) fc_celltype = sim.IF_cond_exp(**cellparams) pop0 = sim.Population(1, input_celltype) pop1 = sim.Population(1, fc_celltype) pop1.initialize(**cellvalues) #pop1.set(i_offset=b) pop1.record(['spikes', 'v']) pop0.record(['spikes']) # create synapsis conn = sim.FromListConnector(w1) pro = sim.Projection(pop0, pop1, connector=conn) sim.run(duration)
def test_module_get_parameter_names(self): module = p.IF_cond_exp() self.assertEqual(IFCondExpBase.default_parameters.keys(), module.get_parameter_names())
def test_module_default_parameters(self): module = p.IF_cond_exp() self.assertEqual(IFCondExpBase.default_parameters, module.default_parameters)
'e_rev_E': 0., 'e_rev_I': -80. } weight_to_spike = 0.035 delay = 17 loopConnections = list() for i in range(0, nNeurons): singleConnection = ((i, (i + 1) % nNeurons, weight_to_spike, delay)) loopConnections.append(singleConnection) injectionConnection = [(0, 0)] spikeArray = {'spike_times': [[0]]} main_pop = p.Population(nNeurons, p.IF_cond_exp(**cell_params_lif), label='pop_1') input_pop = p.Population(1, p.SpikeSourceArray(**spikeArray), label='inputSpikes_1') p.Projection(main_pop, main_pop, p.FromListConnector(loopConnections), p.StaticSynapse(weight=weight_to_spike, delay=delay)) p.Projection(input_pop, main_pop, p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=1)) main_pop.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)
def potentiation_and_depression(self): p.setup(1) runtime = 100 initial_run = 1000 # to negate any initial conditions # STDP parameters a_plus = 0.1 a_minus = 0.0375 tau_plus = 20 tau_minus = 64 plastic_delay = 1 initial_weight = 0.05 max_weight = 0.1 min_weight = 0 pre_spikes = [10, 50] extra_spikes = [30] for i in range(len(pre_spikes)): pre_spikes[i] += initial_run for i in range(len(extra_spikes)): extra_spikes[i] += initial_run # Spike source to send spike via plastic synapse pre_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': pre_spikes}, label="pre") # Spike source to send spike via static synapse to make # post-plastic-synapse neuron fire extra_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': extra_spikes}, label="extra") # Post-plastic-synapse population post_pop = p.Population(1, p.IF_cond_exp(), label="post") # Create projections p.Projection(pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") p.Projection(extra_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") syn_plas = p.STDPMechanism( timing_dependence=p.extra_models.SpikeNearestPairRule( tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=p.AdditiveWeightDependence(w_min=min_weight, w_max=max_weight), weight=initial_weight, delay=plastic_delay) plastic_synapse = p.Projection(pre_pop, post_pop, p.OneToOneConnector(), synapse_type=syn_plas, receptor_type='excitatory') # Record the spikes post_pop.record("spikes") # Run p.run(initial_run + runtime) # Get the weights weights = plastic_synapse.get('weight', 'list', with_address=False) # Get the spikes post_spikes = numpy.array( # pylint: disable=no-member post_pop.get_data('spikes').segments[0].spiketrains[0].magnitude) # End the simulation as all information gathered p.end() # Get the spikes and time differences that will be considered by # the simulation (as the last pre-spike will be considered differently) pre_spikes = numpy.array(pre_spikes) last_pre_spike = pre_spikes[-1] considered_post_spikes = post_spikes[post_spikes < last_pre_spike] considered_post_spikes += plastic_delay potentiation_times = list() depression_times = list() for time in pre_spikes: post_times = considered_post_spikes[considered_post_spikes > time] if len(post_times) > 0: last_time = post_times[0] potentiation_times.append(time - last_time) post_times = considered_post_spikes[considered_post_spikes < time] if len(post_times) > 0: last_time = post_times[-1] depression_times.append(last_time - time) potentiation_times = numpy.array(potentiation_times) depression_times = numpy.array(depression_times) # Work out the weight according to the rules potentiations = max_weight * a_plus * numpy.exp( (potentiation_times / tau_plus)) depressions = max_weight * a_minus * numpy.exp( (depression_times / tau_minus)) new_weight_exact = \ initial_weight + numpy.sum(potentiations) - numpy.sum(depressions) # print("Pre neuron spikes at: {}".format(pre_spikes)) # print("Post-neuron spikes at: {}".format(post_spikes)) target_spikes = [1013, 1032, 1051, 1056] self.assertListEqual(list(post_spikes), target_spikes) # print("New weight exact: {}".format(new_weight_exact)) # print("New weight SpiNNaker: {}".format(weights)) self.assertTrue(numpy.allclose(weights, new_weight_exact, rtol=0.001))
def spinn_net(): np.random.seed(272727) global output_labels global input_labels p.setup(timestep=1.0, min_delay=1, max_delay=60) p.set_number_of_neurons_per_core(p.IF_cond_exp, 64) n_pop_labels = [] n_pop_list = [] n_proj_list = [] spike_source_list = [] if offset != 0: for i in range(2): del output_labels[0] for i in range(2): del input_labels[0] for i in range(no_neuron_pops): #set up the input as a live spike source if i < 2: n_pop_labels.append("Input_pop{}".format(i)) input_labels.append("Input_pop{}".format(i)) n_pop_list.append( p.Population(pop_sizes[i], p.SpikeSourcePoisson(rate=poisson_rate), label=n_pop_labels[i])) n_pop_list[i].record(["spikes"]) p.external_devices.add_poisson_live_rate_control( n_pop_list[i], database_notify_port_num=(160+offset)) #set up output pop elif i < 4: n_pop_labels.append("Output_pop{}".format(i)) output_labels.append("Output_pop{}".format(i)) n_pop_list.append(p.Population(pop_sizes[i], p.IF_cond_exp(), label=n_pop_labels[i])) p.external_devices.activate_live_output_for( n_pop_list[i], database_notify_port_num=(180+offset), port=(17000+offset)) spike_source_list.append(p.Population(pop_sizes[i], p.SpikeSourcePoisson(rate=0.0), label="source ".format(n_pop_labels[i]))) n_pop_list[i].record(["spikes", "v"]) #set up all other populations else: n_pop_labels.append("neuron{}".format(i)) n_pop_list.append(p.Population(pop_sizes[i], p.IF_cond_exp(), label=n_pop_labels[i])) spike_source_list.append(p.Population(pop_sizes[i], p.SpikeSourcePoisson(rate=0.0), label="source ".format(n_pop_labels[i]))) n_pop_list[i].record(["spikes", "v"]) poisson_control = p.external_devices.SpynnakerPoissonControlConnection( poisson_labels=input_labels, local_port=(160+offset)) poisson_control.add_start_callback(n_pop_list[0].label, from_list_poisson) # poisson_control.add_start_callback(n_pop_list[1].label, poisson_setting) # poisson_control.add_start_callback(n_pop_list[0].label, poisson_threading) live_connection = p.external_devices.SpynnakerLiveSpikesConnection( receive_labels=output_labels, local_port=(180+offset)) live_connection.add_receive_callback(n_pop_labels[2], receive_spikes) live_connection.add_receive_callback(n_pop_labels[3], receive_spikes) # weight_mu = 0.015 # weight_sdtev = 0.05 # delay_mu = 40 # delay_sdtev = 5 for i in range(no_neuron_pops): np.random.seed(272727) weights = RandomDistribution("normal_clipped", mu=weight_mu[i], sigma=weight_stdev[i], low=0, high=np.inf) delays = RandomDistribution("normal_clipped", mu=delay_mu[i], sigma=delay_stdev[i], low=1, high=55) synapse = p.StaticSynapse(weight=weights, delay=delays) for j in range(2, no_neuron_pops): print "\npop = {}({}) connecting to {}".format(i,pop_sizes[i],j) if connect_prob_ex[i][j-2] > 1e-10: print "ex = {}\tin = {}".format(connect_prob_ex[i][j-2], connect_prob_in[i][j-2]) print "\tweight mu = {}\t stdev = {}".format(weight_mu[i], weight_stdev[i]) print "\tdelay mu = {}\t stdev = {}".format(delay_mu[i], delay_stdev[i]) n_proj_list.append( p.Projection(n_pop_list[i], n_pop_list[j], p.FixedProbabilityConnector(connect_prob_ex[i][j-2]),#p.OneToOneConnector(),# synapse, receptor_type="excitatory")) n_proj_list.append( p.Projection(n_pop_list[i], n_pop_list[j], p.FixedProbabilityConnector(connect_prob_in[i][j-2]),#p.OneToOneConnector(),# synapse, receptor_type="inhibitory")) # n_proj_list.append(p.Projection(n_pop_list[i], n_pop_list[j], # p.FixedProbabilityConnector(1), # synapse, receptor_type="inhibitory")) run = 0 p.run(duration/timeScaleFactor) print "finished 1st" run = 1 p.reset() p.run(duration/timeScaleFactor) total_v = list() spikes = list() v = list() spikes.append(n_pop_list[0].get_data("spikes")) spikes.append(n_pop_list[1].get_data("spikes")) for j in range(2,no_neuron_pops): spikes.append(n_pop_list[j].get_data("spikes")) v.append(n_pop_list[j].get_data("v")) Figure( # raster plot of the presynaptic neuron spike times Panel(spikes[0].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), Panel(spikes[1].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), Panel(spikes[2].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), Panel(spikes[3].segments[0].spiketrains, yticks=True, markersize=2, xlim=(0, duration)), # Panel(spikes[4].segments[0].spiketrains, # yticks=True, markersize=2, xlim=(0, duration)), # Panel(spikes[no_neuron_pops-2].segments[0].spiketrains, # yticks=True, markersize=2, xlim=(0, duration)), # Panel(spikes[no_neuron_pops-1].segments[0].spiketrains, # yticks=True, markersize=2, xlim=(0, duration)), title="Raster plot", annotations="Simulated with {}".format(p.name()) ) plt.show() Figure( #membrane voltage plots Panel(v[0].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), Panel(v[1].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), Panel(v[2].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), Panel(v[3].segments[0].filter(name='v')[0], ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), # Panel(v[4].segments[0].filter(name='v')[0], # ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), # Panel(v[no_neuron_pops-4].segments[0].filter(name='v')[0], # ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), # Panel(v[no_neuron_pops-3].segments[0].filter(name='v')[0], # ylabel="Membrane potential (mV)", yticks=True, xlim=(0, duration)), title="Membrane voltage plot", ) plt.show() # p.reset() p.end() poisson_control.close() live_connection.close() print "finished run"
p.SpikeSourcePoisson(rate=2), label="input_connect") p.Projection(spike_input, breakout_pop, p.AllToAllConnector(), p.StaticSynapse(weight=0.1)) weight = 0.1 [Connections_on, Connections_off] = subsample_connection(X_RESOLUTION / x_factor1, Y_RESOLUTION / y_factor1, 1, 1, weight, row_col_to_input_breakout) # Create population of neurons to receive input from Breakout receive_pop_size = int(X_RESOLUTION / x_factor1) * int( Y_RESOLUTION / y_factor1) receive_pop = p.Population(receive_pop_size, p.IF_cond_exp(), label="receive_pop") p.Projection(breakout_pop, receive_pop, p.FromListConnector(Connections_on), p.StaticSynapse(weight=weight)) # Create population to receive reward signal from Breakout (n0: rew, n1: pun) receive_reward_pop = p.Population(2, p.IF_cond_exp(), label="receive_rew_pop") p.Projection(breakout_pop, receive_reward_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.1 * weight)) # Setup recording spike_input.record('spikes') receive_pop.record('spikes') receive_reward_pop.record('all') # -----------------------------------------------------------------------------
def breakout_test(connections, arms, split=4, runtime=2000, exposure_time=200, noise_rate=100, noise_weight=0.01, reward=0, spike_f=False, seed=0): np.random.seed(seed) sleep = 10 * np.random.random() time.sleep(sleep) max_attempts = 2 try_except = 0 while try_except < max_attempts: bandit = [] bandit_count = -1 excite = [] excite_count = -1 excite_marker = [] inhib = [] inhib_count = -1 inhib_marker = [] failures = [] try: p.setup(timestep=1.0, min_delay=1, max_delay=127) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) except: print "set up failed, trying again" try: p.setup(timestep=1.0, min_delay=1, max_delay=127) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) except: print "set up failed, trying again for the last time" p.setup(timestep=1.0, min_delay=1, max_delay=127) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) # starting_pistol = p.Population(len(arms), p.SpikeSourceArray(spike_times=[0])) for i in range(len(connections)): [in2e, in2i, e_size, e2e, e2i, i_size, i2e, i2i, e2out, i2out] = connections[i] if (len(in2e) == 0 and len(in2i) == 0) or (len(e2out) == 0 and len(i2out) == 0): failures.append(i) print "agent {} was not properly connected to the game".format(i) else: bandit_count += 1 bandit.append( p.Population(len(arms), spinn_breakout.Breakout(x_factor=x_factor, y_factor=y_factor, label="breakout {}".format(i)))) if e_size > 0: excite_count += 1 excite.append( p.Population(e_size, p.IF_cond_exp(), label='excite_pop_{}-{}'.format(excite_count, i))) excite_noise = p.Population(e_size, p.SpikeSourcePoisson(rate=noise_rate)) p.Projection(excite_noise, excite[excite_count], p.OneToOneConnector(), p.StaticSynapse(weight=noise_weight), receptor_type='excitatory') if spike_f: excite[excite_count].record('spikes') excite_marker.append(i) if i_size > 0: inhib_count += 1 inhib.append(p.Population(i_size, p.IF_cond_exp(), label='inhib_pop_{}-{}'.format(inhib_count, i))) inhib_noise = p.Population(i_size, p.SpikeSourcePoisson(rate=noise_rate)) p.Projection(inhib_noise, inhib[inhib_count], p.OneToOneConnector(), p.StaticSynapse(weight=noise_weight), receptor_type='excitatory') if spike_f: inhib[inhib_count].record('spikes') inhib_marker.append(i) if len(in2e) != 0: p.Projection(bandit[bandit_count], excite[excite_count], p.FromListConnector(in2e), receptor_type='excitatory') # p.Projection(starting_pistol, excite[excite_count], p.FromListConnector(in2e), # receptor_type='excitatory') if len(in2i) != 0: p.Projection(bandit[bandit_count], inhib[inhib_count], p.FromListConnector(in2i), receptor_type='excitatory') # p.Projection(starting_pistol, inhib[inhib_count], p.FromListConnector(in2i), # receptor_type='excitatory') if len(e2e) != 0: p.Projection(excite[excite_count], excite[excite_count], p.FromListConnector(e2e), receptor_type='excitatory') if len(e2i) != 0: p.Projection(excite[excite_count], inhib[inhib_count], p.FromListConnector(e2i), receptor_type='excitatory') if len(i2e) != 0: p.Projection(inhib[inhib_count], excite[excite_count], p.FromListConnector(i2e), receptor_type='inhibitory') if len(i2i) != 0: p.Projection(inhib[inhib_count], inhib[inhib_count], p.FromListConnector(i2i), receptor_type='inhibitory') if len(e2out) != 0: p.Projection(excite[excite_count], bandit[bandit_count], p.FromListConnector(e2out), receptor_type='excitatory') if len(i2out) != 0: p.Projection(inhib[inhib_count], bandit[bandit_count], p.FromListConnector(i2out), receptor_type='inhibitory') simulator = get_simulator() try: p.run(runtime) try_except = max_attempts break except: traceback.print_exc() try: globals_variables.unset_simulator() print "end was necessary" except: traceback.print_exc() print "end wasn't necessary" try_except += 1 print "failed to run on attempt ", try_except, "\n" # . total fails: ", all_fails, "\n" if try_except >= max_attempts: print "calling it a failed population, splitting and rerunning" return 'fail' scores = [] agent_fitness = [] fails = 0 excite_spike_count = [0 for i in range(len(connections))] excite_fail = 0 inhib_spike_count = [0 for i in range(len(connections))] inhib_fail = 0 print "reading the spikes of ", config for i in range(len(connections)): print "started processing fitness of: ", i if i in failures: print "worst score for the failure" fails += 1 scores.append([[max_fail_score], [max_fail_score], [max_fail_score], [max_fail_score]]) # agent_fitness.append(scores[i]) excite_spike_count[i] -= max_fail_score inhib_spike_count[i] -= max_fail_score else: if spike_f: if i in excite_marker: print "counting excite spikes" spikes = excite[i - excite_fail - fails].get_data('spikes').segments[0].spiketrains for neuron in spikes: for spike in neuron: excite_spike_count[i] += 1 else: excite_fail += 1 print "had an excite failure" if i in inhib_marker: print "counting inhib spikes" spikes = inhib[i - inhib_fail - fails].get_data('spikes').segments[0].spiketrains for neuron in spikes: for spike in neuron: inhib_spike_count[i] += 1 else: inhib_fail += 1 print "had an inhib failure" scores.append(get_scores(game_pop=bandit[i - fails], simulator=simulator)) # pop[i].stats = {'fitness': scores[i][len(scores[i]) - 1][0]} # , 'steps': 0} print "finished spikes" if spike_f: agent_fitness.append([scores[i][len(scores[i]) - 1][0], excite_spike_count[i] + inhib_spike_count[i]]) else: agent_fitness.append(scores[i][len(scores[i]) - 1][0]) # print i, "| e:", excite_spike_count[i], "-i:", inhib_spike_count[i], "|\t", scores[i] print "The scores for this run of {} agents are:".format(len(connections)) for i in range(len(connections)): print "c:{}, s:{}, si:{}, si0:{}".format(len(connections), len(scores), len(scores[i]), len(scores[i][0])) e_string = "e: {}".format(excite_spike_count[i]) i_string = "i: {}".format(inhib_spike_count[i]) score_string = "" for j in range(len(scores[i])): score_string += "{:4},".format(scores[i][j][0]) print "{:3} | {:8} {:8} - ".format(i, e_string, i_string), score_string p.end() return agent_fitness
def agent_fitness(agent, light_distance, light_theta, print_move): global port_offset global number_of_runs global counter global current_agent global current_fitness global current_light_distance global current_light_theta global currently_running current_agent = agent print "\n\nStarting agent - {}\n\n".format(agent) p.setup(timestep=1.0, min_delay=delay_min, max_delay=delay_max) p.set_number_of_neurons_per_core(p.IF_cond_exp, 20) # setup of different neuronal populations #neuron_pop = list(); neuron_pop = [] if port_offset != 1: for i in range(agent_neurons): del neuron_labels[0] inhibitory_count = 0 excitatory_count = 0 for i in range(agent_neurons): if agent_pop[agent][inhibitory_loc + i] == -1: neuron_labels.append("Inhibitory{}-neuron{}-agent{}-port{}".format( inhibitory_count, i, agent, port_offset)) neuron_pop.append( p.Population(neuron_pop_size, p.IF_cond_exp(), label=neuron_labels[i])) inhibitory_count += 1 else: neuron_labels.append("Excitatory{}-neuron{}-agent{}-port{}".format( excitatory_count, i, agent, port_offset)) neuron_pop.append( p.Population(neuron_pop_size, p.IF_cond_exp(), label=neuron_labels[i])) excitatory_count += 1 # if print_move == True: # neuron_pop[i].record(["spikes", "v"]) # connect neuronal population according to genentic instructions projection_list = list() for i in range(agent_neurons): for j in range(agent_neurons): # if theres a connection connect if agent_pop[agent][set2loc + (i * agent_neurons) + j] != 0: # if connection is inhibitory set as such if agent_pop[agent][inhibitory_loc + i] == -1: synapse = p.StaticSynapse( weight=-agent_pop[agent][(i * agent_neurons) + j], delay=agent_pop[agent][delay_loc + ((i * agent_neurons) + j)]) projection_list.append( p.Projection(neuron_pop[i], neuron_pop[j], p.AllToAllConnector(), synapse, receptor_type="inhibitory")) # set as excitatory else: synapse = p.StaticSynapse( weight=agent_pop[agent][(i * agent_neurons) + j], delay=agent_pop[agent][delay_loc + ((i * agent_neurons) + j)]) projection_list.append( p.Projection(neuron_pop[i], neuron_pop[j], p.AllToAllConnector(), synapse, receptor_type="excitatory")) # set STDP, weight goes to negative if inhibitory? # stdp_model = p.STDPMechanism( # timing_dependence=p.SpikePairRule( # tau_plus=20., tau_minus=20.0, A_plus=0.5, A_minus=0.5), # weight_dependence=p.AdditiveWeightDependence(w_min=weight_min, w_max=weight_max)) # connect in and out live links #visual_input = list() visual_input = [] visual_projection = [] #list() input_labels = [] #list() #sensor_poisson = [0 for j in range(visual_discrete)] sensor_poisson = poisson_rate(agent, light_distance, light_theta) for i in range(visual_discrete): print i input_labels.append("input_spikes{}".format(i)) visual_input.append( p.Population(1, p.SpikeSourcePoisson(rate=sensor_poisson[i]), label=input_labels[i])) visual_projection.append( p.Projection( visual_input[i], neuron_pop[i], p.OneToOneConnector(), p.StaticSynapse(weight=visual_weight, delay=visual_delay))) p.external_devices.add_poisson_live_rate_control( visual_input[i], database_notify_port_num=16000 + port_offset) # poisson_control = p.external_devices.SpynnakerPoissonControlConnection(poisson_labels=[visual_input[i].label])#,local_port=18000+(port_offset*visual_discrete)+i) # poisson_control.add_start_callback(visual_input[i].label, poisson_setting) # visual_input = p.Population(visual_discrete, p.SpikeSourcePoisson(rate=sensor_poisson), label=input) # p.Projection( # visual_input, neuron_pop[(i for i in range(0,visual_discrete))], p.OneToOneConnector(), p.StaticSynapse(weight=visual_weight, delay=visual_delay)) # p.external_devices.add_poisson_live_rate_control(visual_input) poisson_control = p.external_devices.SpynnakerPoissonControlConnection( poisson_labels=input_labels, local_port=16000 + port_offset) poisson_control.add_start_callback(visual_input[0].label, poisson_setting) # poisson_control.add_start_callback(visual_input[1].label, empty_function) # poisson_control2 = p.external_devices.SpynnakerPoissonControlConnection(poisson_labels=[visual_input[1].label],local_port=19998)#+(port_offset*visual_discrete)+i) # poisson_control2.add_start_callback(visual_input[1].label, poisson_setting2) # poisson_control.add_start_callback(visual_input[1].label, poisson_setting) # for i in range(visual_discrete): # print i # input_labels.append("input_spikes{}".format(i)) # visual_input.append(p.Population( # 1, p.SpikeSourcePoisson(rate=sensor_poisson[i]), label=input_labels[i])) # visual_projection.append(p.Projection( # visual_input[i], neuron_pop[i], p.OneToOneConnector(), p.StaticSynapse( # weight=visual_weight, delay=visual_delay))) # p.external_devices.add_poisson_live_rate_control(visual_input[i]) #possible all at once # poisson_control = p.external_devices.SpynnakerPoissonControlConnection(poisson_labels=[input_labels[0], input_labels[1]]) # #for i in range(visual_discrete): # poisson_control.add_start_callback(input_labels[i], poisson_setting) # for i in range(4): # del motor_labels[0] motor_labels = [] for i in range(4): print i motor_labels.append(neuron_labels[agent_neurons - (i + 1)]) p.external_devices.activate_live_output_for( neuron_pop[agent_neurons - (i + 1)], database_notify_port_num=18000 + port_offset) live_connection = p.external_devices.SpynnakerLiveSpikesConnection( receive_labels=[ motor_labels[0], motor_labels[1], motor_labels[2], motor_labels[3] ], local_port=(18000 + port_offset)) for i in range(4): live_connection.add_receive_callback(motor_labels[i], receive_spikes) #fitness = 0 # spikes = list() # v = list() current_fitness = 0 current_light_theta = light_theta current_light_distance = light_distance currently_running = True p.run(total_runtime) currently_running = False no_move_distance = light_distance * total_runtime / time_slice fitness = current_fitness if abs(fitness - no_move_distance) < 1e-10: fitness *= no_move_punishment print "agent failed to move so was punished" # if print_move == True: # spikes = [] # v = [] # for j in range(agent_neurons): # spikes.append(neuron_pop[j].get_data("spikes")) # v.append(neuron_pop[j].get_data("v")) live_connection.close() live_connection._handle_possible_rerun_state() p.end() if counter != number_of_runs: counter += 1 port_offset += 1 reset_agent(agent) if print_move == True: with open( 'movement {}.csv'.format( (port_offset - counter) / number_of_runs), 'a') as file: writer = csv.writer(file, delimiter=',', lineterminator='\n') writer.writerow([ light_distance * np.sin(light_theta), light_distance * np.cos(light_theta) ]) port_recurse_check = port_offset fitness += agent_fitness(agent, light_distance, -light_theta, print_move) else: counter = 1 port_offset -= 1 port_offset += 1 reset_agent(agent) return fitness
def test_potentiation_and_depression(self): p.setup(1) runtime = 100 initial_run = 1000 # to negate any initial conditions # STDP parameters a_plus = 0.1 a_minus = 0.0375 tau_plus = 20 tau_minus = 64 plastic_delay = 1 initial_weight = 0.05 max_weight = 0.1 min_weight = 0 spike_times = [10, 50] spike_times2 = [30] for i in range(len(spike_times)): spike_times[i] += initial_run for i in range(len(spike_times2)): spike_times2[i] += initial_run # Spike source to send spike via plastic synapse pop_src1 = p.Population(1, p.SpikeSourceArray, {'spike_times': spike_times}, label="src1") # Spike source to send spike via static synapse to make # post-plastic-synapse neuron fire pop_src2 = p.Population(1, p.SpikeSourceArray, {'spike_times': spike_times2}, label="src2") # Post-plastic-synapse population pop_exc = p.Population(1, p.IF_cond_exp(), label="test") # Create projections p.Projection( pop_src1, pop_exc, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") p.Projection( pop_src2, pop_exc, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") syn_plas = p.STDPMechanism( timing_dependence=p.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=p.AdditiveWeightDependence(w_min=min_weight, w_max=max_weight), weight=initial_weight, delay=plastic_delay) plastic_synapse = p.Projection(pop_src1, pop_exc, p.OneToOneConnector(), synapse_type=syn_plas, receptor_type='excitatory') pop_src1.record('all') pop_exc.record("all") p.run(initial_run + runtime) weights = [] weights.append(plastic_synapse.get('weight', 'list', with_address=False)[0]) # pre_spikes = pop_src1.get_data('spikes') # v = pop_exc.get_data('v') spikes = pop_exc.get_data('spikes') potentiation_time_1 = (spikes.segments[0].spiketrains[0].magnitude[0] + plastic_delay) - spike_times[0] potentiation_time_2 = (spikes.segments[0].spiketrains[0].magnitude[1] + plastic_delay) - spike_times[0] depression_time_1 = spike_times[1] - ( spikes.segments[0].spiketrains[0].magnitude[0] + plastic_delay) depression_time_2 = spike_times[1] - ( spikes.segments[0].spiketrains[0].magnitude[1] + plastic_delay) potentiation_1 = max_weight * a_plus * \ math.exp(-potentiation_time_1/tau_plus) potentiation_2 = max_weight * a_plus * \ math.exp(-potentiation_time_2/tau_plus) depression_1 = max_weight * a_minus * \ math.exp(-depression_time_1/tau_minus) depression_2 = max_weight * a_minus * \ math.exp(-depression_time_2/tau_minus) new_weight_exact = (initial_weight + potentiation_1 + potentiation_2 - depression_1 - depression_2) print("Pre neuron spikes at: {}".format(spike_times)) print("Post-neuron spikes at: {}".format( spikes.segments[0].spiketrains[0].magnitude)) print("Potentiation time differences: {}, {},\ \nDepression time difference: {}, {}".format( potentiation_time_1, potentiation_time_2, depression_time_1, depression_time_2)) print("Ammounts to potentiate: {}, {},\ \nAmount to depress: {}, {},".format( potentiation_1, potentiation_2, depression_1, depression_2)) print("New weight exact: {}".format(new_weight_exact)) print("New weight SpiNNaker: {}".format(weights[0])) self.assertTrue(numpy.allclose(weights[0], new_weight_exact, rtol=0.001)) p.end()
def test_agent(arm1, arm2): arm = [arm1, arm2] print "arm = ", arm connections = read_agent() p.setup(timestep=1.0, min_delay=1, max_delay=127) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) bandit = p.Population(len(arm), Bandit(arm, exposure_time, reward_based=reward, label='bandit_pop')) [in2e, in2i, e_size, e2e, e2i, i_size, i2e, i2i, e2out, i2out] = connections if e_size > 0: excite = p.Population(e_size, p.IF_cond_exp(), label='excite_pop') excite_noise = p.Population(e_size, p.SpikeSourcePoisson(rate=noise_rate)) p.Projection(excite_noise, excite, p.OneToOneConnector(), p.StaticSynapse(weight=noise_weight), receptor_type='excitatory') excite.record('spikes') if i_size > 0: inhib = p.Population(i_size, p.IF_cond_exp(), label='inhib_pop') inhib_noise = p.Population(i_size, p.SpikeSourcePoisson(rate=noise_rate)) p.Projection(inhib_noise, inhib, p.OneToOneConnector(), p.StaticSynapse(weight=noise_weight), receptor_type='excitatory') inhib.record('spikes') if len(in2e) != 0: p.Projection(bandit, excite, p.FromListConnector(in2e), receptor_type='excitatory') # p.Projection(starting_pistol, excite, p.FromListConnector(in2e), # receptor_type='excitatory') if len(in2i) != 0: p.Projection(bandit, inhib, p.FromListConnector(in2i), receptor_type='excitatory') # p.Projection(starting_pistol, inhib, p.FromListConnector(in2i), # receptor_type='excitatory') if len(e2e) != 0: p.Projection(excite, excite, p.FromListConnector(e2e), receptor_type='excitatory') if len(e2i) != 0: p.Projection(excite, inhib, p.FromListConnector(e2i), receptor_type='excitatory') if len(i2e) != 0: p.Projection(inhib, excite, p.FromListConnector(i2e), receptor_type='inhibitory') if len(i2i) != 0: p.Projection(inhib, inhib, p.FromListConnector(i2i), receptor_type='inhibitory') if len(e2out) != 0: p.Projection(excite, bandit, p.FromListConnector(e2out), receptor_type='excitatory') if len(i2out) != 0: p.Projection(inhib, bandit, p.FromListConnector(i2out), receptor_type='inhibitory') simulator = get_simulator() p.run(runtime) scores = get_scores(game_pop=bandit, simulator=simulator) print scores print arm e_spikes = excite.get_data('spikes').segments[0].spiketrains i_spikes = inhib.get_data('spikes').segments[0].spiketrains # v = receive_pop[i].get_data('v').segments[0].filter(name='v')[0] plt.figure("[{}, {}] - {}".format(arm1, arm2, scores)) Figure( Panel(e_spikes, xlabel="Time (ms)", ylabel="nID", xticks=True), Panel(i_spikes, xlabel="Time (ms)", ylabel="nID", xticks=True) ) plt.show() p.end()
def potentiation_and_depression(self): p.setup(1) runtime = 100 initial_run = 1000 # to negate any initial conditions # STDP parameters a_plus = 0.1 a_minus = 0.0375 tau_plus = 20 tau_minus = 64 plastic_delay = 1 initial_weight = 0.05 max_weight = 0.1 min_weight = 0 pre_spikes = [10, 50] extra_spikes = [30] for i in range(len(pre_spikes)): pre_spikes[i] += initial_run for i in range(len(extra_spikes)): extra_spikes[i] += initial_run # Spike source to send spike via plastic synapse pre_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': pre_spikes}, label="pre") # Spike source to send spike via static synapse to make # post-plastic-synapse neuron fire extra_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': extra_spikes}, label="extra") # Post-plastic-synapse population post_pop = p.Population(1, p.IF_cond_exp(), label="post") # Create projections p.Projection(pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") p.Projection(extra_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") syn_plas = p.STDPMechanism( timing_dependence=p.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=p.AdditiveWeightDependence(w_min=min_weight, w_max=max_weight), weight=initial_weight, delay=plastic_delay) plastic_synapse = p.Projection(pre_pop, post_pop, p.OneToOneConnector(), synapse_type=syn_plas, receptor_type='excitatory') # Record the spikes post_pop.record("spikes") # Run p.run(initial_run + runtime) # Get the weights weights = plastic_synapse.get('weight', 'list', with_address=False) # Get the spikes post_spikes = numpy.array( post_pop.get_data('spikes').segments[0].spiketrains[0].magnitude) # End the simulation as all information gathered p.end() new_weight_exact = calculate_spike_pair_additive_stdp_weight( pre_spikes, post_spikes, initial_weight, plastic_delay, max_weight, a_plus, a_minus, tau_plus, tau_minus) # print("Pre neuron spikes at: {}".format(pre_spikes)) # print("Post-neuron spikes at: {}".format(post_spikes)) target_spikes = [1013, 1032, 1051, 1056] self.assertListEqual(list(post_spikes), target_spikes) # print("New weight exact: {}".format(new_weight_exact)) # print("New weight SpiNNaker: {}".format(weights)) self.assertTrue(numpy.allclose(weights, new_weight_exact, rtol=0.001))
inputs = 2 outputs = 2 p.setup(timestep=1.0, min_delay=1) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) input_model = gym.Pendulum( encoding=encoding, time_increment=time_increment, pole_length=pole_length, pole_angle=pole_angle, reward_based=reward_based, force_increments=force_increments, max_firing_rate=max_firing_rate, number_of_bins=number_of_bins, central=central, rand_seed=[np.random.randint(0xffff) for i in range(4)], bin_overlap=3, label='pendulum_pop') pendulum_pop_size = input_model.neurons() pendulum = p.Population(pendulum_pop_size, input_model) null_pop = p.Population(4*number_of_bins, p.IF_cond_exp(), label='null') p.Projection(pendulum, null_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.09)) null_pop.record(['spikes', 'v', 'gsyn_exc']) # null_pop.record(['spikes', 'v']) # null_pops = [] # for i in range(4*number_of_bins): # null_pops.append(p.Population(1, p.IF_cond_exp(), # label='null {}'.format(i))) # null_pops[i].record(['spikes', 'v']) # p.Projection(pendulum, null_pops[i], # p.FromListConnector([[i, 0, weight, 1]])) arm_collection = [] # input_spikes = [] rate = 5
scores = b_vertex.get_data('score', simulator.no_machine_time_steps, simulator.placements, simulator.graph_mapper, simulator.buffer_manager, simulator.machine_time_step) return scores.tolist() p.setup(timestep=1.0) probabilities = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6] input_size = len(probabilities) input_pop = p.Population(len(probabilities), p.SpikeSourcePoisson(rate=5)) output_pop1 = p.Population(2, p.IF_cond_exp()) output_pop2 = p.Population(2, p.IF_cond_exp()) random_seed = [] for j in range(4): random_seed.append(np.random.randint(0xffff)) arms_pop = p.Population(input_size, Bandit(probabilities, 200, rand_seed=random_seed)) input_pop.record('spikes') # arms_pop.record('spikes') output_pop1.record('spikes') output_pop2.record('spikes') i2a = p.Projection(input_pop, arms_pop, p.AllToAllConnector())
def do_run(plot): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) # Experiment Parameters rng = pyNN.random.NumpyRNG(seed=124578) n_groups = 6 # Number of Synfire Groups n_exc = 100 # Number of excitatory neurons per group n_inh = 25 # Number of inhibitory neurons per group sim_duration = 500. # defining the initial pulse-packet pp_a = 5 # Nr of pulses in the packet pp_sigma = 5.0 # sigma of pulse-packet pp_start = 50. # start = center of pulse-packet # Neuron Parameters as in Kremkow et al. paper cell_params = {'cm': 0.290, # nF 'tau_m': 290.0/29.0, # pF / nS = ms 'v_rest': -70.0, # mV 'v_thresh': -57.0, # mV 'tau_syn_E': 1.5, # ms 'tau_syn_I': 10.0, # ms 'tau_refrac': 2.0, # ms 'v_reset': -70.0, # mV 'e_rev_E': 0.0, # mV 'e_rev_I': -75.0, # mV } weight_exc = 0.001 # uS weight for excitatory to excitatory connections weight_inh = 0.002 # uS weight for inhibitory to excitatory connections # list of excitatory populations exc_pops = [] # list of inhibitory populations inh_pops = [] # and Assembly of all populations all_populations = [] # Create Groups print("Creating ", n_groups, " SynfireGroups") for group_index in range(n_groups): # create the excitatory Population exc_pop = p.Population(n_exc, p.IF_cond_exp(**cell_params), label=("pop_exc_%s" % group_index)) exc_pops.append(exc_pop) # append to excitatory populations all_populations += [exc_pop] # and to the Assembly # create the inhibitory Population inh_pop = p.Population(n_inh, p.IF_cond_exp(**cell_params), label=("pop_inh_%s" % group_index)) inh_pops.append(inh_pop) all_populations += [inh_pop] # connect Inhibitory to excitatory Population p.Projection(inh_pop, exc_pop, p.AllToAllConnector(), synapse_type=p.StaticSynapse(weight=weight_inh, delay=8.), receptor_type='inhibitory') # Create Stimulus and connect it to first group print("Create Stimulus Population") # We create a Population of SpikeSourceArrays of the same dimension # as excitatory neurons in a synfire group pop_stim = p.Population(n_exc, p.SpikeSourceArray({}), label="pop_stim") # We create a normal distribution around pp_start with sigma = pp_sigma rd = pyNN.random.RandomDistribution('normal', [pp_start, pp_sigma]) all_spiketimes = [] # for each cell in the population, we take pp_a values from the # random distribution for cell in range(len(pop_stim)): spiketimes = [] for pulse in range(pp_a): spiketimes.append(rd.next()) # draw from the random distribution spiketimes.sort() all_spiketimes.append(spiketimes) # convert into a numpy array all_spiketimes = numpy.array(all_spiketimes) # 'topographic' setting of parameters. # all_spiketimes must have the same dimension as the Population pop_stim.set(spike_times=all_spiketimes) # Connect Groups with the subsequent ones print("Connecting Groups with subsequent ones") for group_index in range(n_groups-1): p.Projection(exc_pops[group_index % n_groups], exc_pops[(group_index+1) % n_groups], p.FixedNumberPreConnector(60, rng=rng, with_replacement=True), synapse_type=p.StaticSynapse(weight=weight_exc, delay=10.), receptor_type='excitatory') p.Projection(exc_pops[group_index % n_groups], inh_pops[(group_index+1) % n_groups], p.FixedNumberPreConnector(60, rng=rng, with_replacement=True), synapse_type=p.StaticSynapse(weight=weight_exc, delay=10.), receptor_type='excitatory') # Make another projection for testing that connects to itself p.Projection(exc_pops[1], exc_pops[1], p.FixedNumberPreConnector(60, rng=rng, allow_self_connections=False), synapse_type=p.StaticSynapse(weight=weight_exc, delay=10.), receptor_type='excitatory') # Connect the Stimulus to the first group print("Connecting Stimulus to first group") p.Projection(pop_stim, inh_pops[0], p.FixedNumberPreConnector(20, rng=rng), synapse_type=p.StaticSynapse(weight=weight_exc, delay=20.), receptor_type='excitatory') p.Projection(pop_stim, exc_pops[0], p.FixedNumberPreConnector(60, rng=rng), synapse_type=p.StaticSynapse(weight=weight_exc, delay=20.), receptor_type='excitatory') # Recording spikes pop_stim.record('spikes') for pop in all_populations: pop.record('spikes') # Run print("Run the simulation") p.run(sim_duration) # Get data print("Simulation finished, now collect all spikes and plot them") stim_spikes = pop_stim.spinnaker_get_data('spikes') stim_spikes[:, 0] -= n_exc # collect all spikes and make a raster_plot spklist_exc = [] spklist_inh = [] for group in range(n_groups): EXC_spikes = exc_pops[group].spinnaker_get_data('spikes') INH_spikes = inh_pops[group].spinnaker_get_data('spikes') EXC_spikes[:, 0] += group*(n_exc+n_inh) INH_spikes[:, 0] += group*(n_exc+n_inh) + n_exc spklist_exc += EXC_spikes.tolist() spklist_inh += INH_spikes.tolist() # Plot if plot: pylab.figure() pylab.plot([i[1] for i in spklist_exc], [i[0] for i in spklist_exc], "r.") pylab.plot([i[1] for i in spklist_inh], [i[0] for i in spklist_inh], "b.") pylab.plot([i[1] for i in stim_spikes], [i[0] for i in stim_spikes], "k.") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes') for group in range(n_groups): pylab.axhline(y=(group+1)*(n_exc+n_inh), color="lightgrey") pylab.axhline(y=(group+1)*(n_exc+n_inh)-n_inh, color="lightgrey") pylab.axhline(y=0, color="grey", linewidth=1.5) pylab.show() p.end() return stim_spikes, spklist_exc, spklist_inh
**{ 'i_offset': 0.1, 'tau_refrac': 3.0, 'v_thresh': -51.0, 'v_reset': -70.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0 })) exp_cell = sim.Population( 1, sim.IF_cond_exp( **{ 'i_offset': 0.1, 'tau_refrac': 3.0, 'v_thresh': -51.0, 'v_reset': -70.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0 })) spike_sourceE = sim.Population( 1, sim.SpikeSourceArray( **{'spike_times': [float(i) for i in range(5, 105, 10)]})) spike_sourceI = sim.Population( 1, sim.SpikeSourceArray( **{'spike_times': [float(i) for i in range(155, 255, 10)]})) sim.Projection(spike_sourceE,