def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core("IF_curr_exp", 250) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 5.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } populations = list() projections = list() weight_to_spike = 1.5 delay = 1 connections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, delay)] spikeArray = {'spike_times': [[0]]} populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) projections.append( p.Projection(populations[0], populations[0], p.FromListConnector(connections))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(1000) '''' weights = projections[0].getWeights() delays = projections[0].getDelays() ''' v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) p.end() return (v, gsyn, spikes)
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) max_delay = 50 p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons / 2) 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 } populations = list() projections = list() weight_to_spike = 2.0 delay = numpy.random.RandomState() delays = list() connections = list() for i in range(0, nNeurons): d_value = int(delay.uniform(low=1, high=max_delay)) delays.append(float(d_value)) singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, d_value) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, 1)] spikeArray = {'spike_times': [[0]]} populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) projections.append( p.Projection(populations[0], populations[0], p.FromListConnector(connections))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() run_time = (max_delay * nNeurons) print "Running for {} ms".format(run_time) p.run(run_time) v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) p.end() return (v, gsyn, spikes)
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("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) spike_array = {'spike_times': spikes} populations.append( p.Population(n_neurons, p.SpikeSourceArray, spike_array, 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(weights=weight_to_spike, delays=delay))) populations[1].record() p.run(1000) spikes = populations[1].getSpikes(compatible_output=True) p.end() return spikes
def test_recording_numerious_element(self): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 20 # number of neurons in each population p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2) 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 } populations = list() projections = list() boxed_array = numpy.zeros(shape=(0, 2)) spike_array = list() for neuron_id in range(0, n_neurons): spike_array.append(list()) for counter in range(0, 20): random_time = random.randint(0, 5000) boxed_array = numpy.append(boxed_array, [[neuron_id, random_time]], axis=0) spike_array[neuron_id].append(random_time) spike_array_params = {'spike_times': spike_array} populations.append( p.Population(n_neurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(n_neurons, p.SpikeSourceArray, spike_array_params, label='inputSpikes_1')) projections.append( p.Projection(populations[1], populations[0], p.OneToOneConnector())) populations[1].record() p.run(5000) spike_array_spikes = populations[1].getSpikes() boxed_array = boxed_array[numpy.lexsort( (boxed_array[:, 1], boxed_array[:, 0]))] numpy.testing.assert_array_equal(spike_array_spikes, boxed_array) p.end()
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core(IZK_curr_exp, 100) cell_params_izk = { 'a': 0.02, 'b': 0.2, 'c': -65, 'd': 8, 'v_init': -75, 'u_init': 0, 'tau_syn_E': 2, 'tau_syn_I': 2, 'i_offset': 0 } populations = list() projections = list() weight_to_spike = 40 delay = 1 connections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, delay)] spikeArray = {'spike_times': [[50]]} populations.append(p.Population(nNeurons, IZK_curr_exp, cell_params_izk, label='pop_1')) populations.append(p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) projections.append(p.Projection(populations[0], populations[0], p.FromListConnector(connections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(500) v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) p.end() return (v, gsyn, spikes)
def do_run(nNeurons): p.setup(timestep=0.1, min_delay=1.0, max_delay=7.5) p.set_number_of_neurons_per_core("IF_curr_exp", 100) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 6, 'tau_syn_I': 6, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -55.4 } populations = list() projections = list() weight_to_spike = 12 injection_delay = 1 delay = 1 spikeArray = {'spike_times': [[0, 10, 20, 30]]} populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='pop_0')) populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_2')) connector = p.AllToAllConnector(weights=weight_to_spike, delays=injection_delay) projections.append(p.Projection(populations[0], populations[1], connector)) connector = p.OneToOneConnector(weights=weight_to_spike, delays=delay) projections.append(p.Projection(populations[1], populations[2], connector)) populations[1].record_v() populations[1].record() p.run(100) v = populations[1].get_v(compatible_output=True) spikes = populations[1].getSpikes(compatible_output=True) p.end() return (v, spikes)
def do_run(split_spike_source_poisson=False, change_spike_rate=True, split_if_curr_exp=False, change_if_curr=True): p.setup(1.0) if split_spike_source_poisson: print "split SpikeSourcePoisson", split_spike_source_poisson p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 27) if split_if_curr_exp: print "split IF_curr_exp" p.set_number_of_neurons_per_core(p.IF_curr_exp, 22) inp = p.Population(100, p.SpikeSourcePoisson, {"rate": 100}, label="input") pop = p.Population(100, p.IF_curr_exp, {}, label="pop") p.Projection(inp, pop, p.OneToOneConnector(weights=5.0)) pop.record() inp.record() p.run(100) if change_spike_rate: inp.set("rate", 10) if change_if_curr: # pop.set("cm", 0.25) pop.set("tau_syn_E", 1) p.run(100) pop_spikes1 = pop.getSpikes() inp_spikes1 = inp.getSpikes() p.reset() inp.set("rate", 0) pop.set("i_offset", 1.0) pop.initialize("v", p.RandomDistribution("uniform", [-65.0, -55.0])) p.run(100) pop_spikes2 = pop.getSpikes() inp_spikes2 = inp.getSpikes() p.end() return (pop_spikes1, inp_spikes1, pop_spikes2, inp_spikes2)
def test_recording_1_element(self): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 200 # number of neurons in each population p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2) 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 } populations = list() projections = list() spike_array = {'spike_times': [[0]]} populations.append( p.Population(n_neurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(1, p.SpikeSourceArray, spike_array, label='inputSpikes_1')) projections.append( p.Projection(populations[1], populations[0], p.AllToAllConnector())) populations[1].record() p.run(5000) spike_array_spikes = populations[1].getSpikes() boxed_array = numpy.zeros(shape=(0, 2)) boxed_array = numpy.append(boxed_array, [[0, 0]], axis=0) numpy.testing.assert_array_equal(spike_array_spikes, boxed_array) p.end()
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core("IF_curr_exp", 100) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 10.0, 'tau_refrac': 2.0, 'tau_syn_E': 0.5, 'tau_syn_I': 0.5, 'v_reset': -65.0, 'v_rest': -65.0, 'v_thresh': -64.4 } populations = list() projections = list() weight_to_spike = 2 delay = 1 connections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, delay)] spikeArray = {'spike_times': [[0]]} for x in range(6): populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif)) populations.append(p.Population(1, p.SpikeSourceArray, spikeArray)) for x in range(0, 12, 2): projections.append( p.Projection(populations[x], populations[x], p.FromListConnector(connections))) connector = p.FromListConnector(injectionConnection) projections.append( p.Projection(populations[x + 1], populations[x], connector)) populations[x].record() p.run(1000) p.end()
def do_run(nNeurons, _neurons_per_core): spike_list = {'spike_times': [float(x) for x in range(0, 599, 50)]} p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core("SpikeSourceArray", _neurons_per_core) pop = p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input') pop.record() p.run(1000) spikes = pop.getSpikes(compatible_output=True) p.end() return spikes
def test_recording_poisson_spikes_rate_0(self): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 256 # number of neurons in each population p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2) 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 } populations = list() projections = list() populations.append( p.Population(n_neurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(n_neurons, p.SpikeSourcePoisson, {'rate': 0}, label='inputSpikes_1')) projections.append( p.Projection(populations[1], populations[0], p.OneToOneConnector())) populations[1].record() p.run(5000) spikes = populations[1].getSpikes() print spikes p.end()
def stimulate_cores(self, w_range=[1.4, 1.4], d_range=[1.0, 1.0], w_clues=[1.4, 1.6]): # w_clues=[0.0, 0.2] """Connect stimulating noise sources to variables populations. args: w_range: range for the random distribution of synaptic weights in the form [w_min, w_max]. d_range: range for the random distribution of synaptic delays in the form [d_min, d_max]. w_clues: clues specific range for the random distribution of synaptic weights in the form [w_min, w_max]. """ p.set_number_of_neurons_per_core(p.IF_curr_exp, 150) print msg, 'connecting Poisson noise sources to neural populations for stimulation' delays = RandomDistribution('uniform', d_range) weights = RandomDistribution('uniform', w_range) weight_clues = RandomDistribution("uniform", w_clues) for stimulus in range(self.n_populations): for variable in range(self.variables_number): counter = 0 if variable in self.clues[0]: shift = self.clues[1][self.clues[0].index( variable)] * self.core_size connections = [(m, n + shift, weight_clues.next(), delays.next()) for m in range(self.core_size) for n in range(self.clue_size)] synapses = p.Projection(self.clues_stim[counter], self.var_pops[variable], p.FromListConnector(connections, safe=True), target='excitatory') counter += 1 self.stim_conns.append(synapses) else: synapses = p.Projection( self.stim_pops[stimulus][variable], self.var_pops[variable], p.OneToOneConnector(weights=weights, delays=delays), target='excitatory') self.stim_conns.append(synapses) self.stim_times += self.stims
def do_run(n_neurons, n_cores, new_i_offset): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / n_cores) 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 } populations = list() populations.append( p.Population(n_neurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(2000) populations[0].set('i_offset', new_i_offset) p.run(2000) spikes = populations[0].getSpikes(compatible_output=True) v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) p.end() return (spikes, v, gsyn)
def do_run(nNeurons): cell_params_lif = { 'cm': 0.25, # nF 'i_offset': 0.0, 'tau_m': 10.0, 'tau_refrac': 2.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -55.4 } spike_list = {'spike_times': [float(x) for x in range(0, 599, 50)]} p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core("SpikeSourceArray", 100) # FAILS populations = list() projections = list() populations.append( p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input')) populations.append( p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1')) projections.append( p.Projection(populations[0], populations[1], p.AllToAllConnector())) populations[0].record() p.run(1000) spikes = populations[0].getSpikes(compatible_output=True) p.end() return spikes
import numpy as np import threading from threading import Condition import matplotlib.pyplot as plt from matplotlib import gridspec from pyNN.random import RandomDistribution # as rand #import spynnaker8.spynakker_plotting as splot from pympler.tracker import SummaryTracker import spinn_breakout input_size = 160 * 128 hidden_size = 100 output = 100 p.setup(timestep=1.0) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) poisson_rate = {'rate': 15} tracker = SummaryTracker() tracker.print_diff() input_pop = p.Population(input_size, p.IF_cond_exp, {}, label='input') hidden_pop = p.Population(hidden_size, p.IF_cond_exp, {}, label='hidden') output_pop = p.Population(output, p.IF_cond_exp, {}, label='output') breakout = p.Population(1, spinn_breakout.Breakout, {}, label="breakout") print "after populations" tracker.print_diff() a = p.Projection(input_pop, hidden_pop, p.AllToAllConnector(weights=0.5)) print "after i->h" tracker.print_diff() a = p.Projection(breakout, hidden_pop, p.AllToAllConnector(weights=0.5))
real_time = int(np.ceil(tstep_ms * (hours * 60 * 60 + minutes * 60 + seconds))) sim_time = int(real_time * 1.5) ######################################################################## # S P I K E T I M E S G E N E R A T I O N ######################################################################## spike_times = [10] ######################################################################### # S I M U L A T O R S E T U P ######################################################################### cell = sim.IF_curr_exp if sim.__name__ == 'pyNN.spiNNaker': sim.set_number_of_neurons_per_core(cell, neurons_per_core) sim.setup(timestep=time_step, min_delay=1., max_delay=144.) ######################################################################## # P O P U L A T I O N S ######################################################################## source = sim.Population(num_exc, sim.SpikeSourceArray, {'spike_times': spike_times}, label='Source (EXC)') if test_exc: target = sim.Population(num_exc, cell, exc_params, label='Target (EXC)') else: target = sim.Population(num_exc, cell, inh_params, label='Target (INH)')
def test_va_benchmark(self): try: simulator_name = 'spiNNaker' timer = Timer() # === Define parameters ========================================= rngseed = 98766987 parallel_safe = True n = 1500 # number of cells # number of excitatory cells:number of inhibitory cells r_ei = 4.0 pconn = 0.02 # connection probability dt = 0.1 # (ms) simulation timestep tstop = 200 # (ms) simulaton duration delay = 1 # Cell parameters area = 20000. # (µm²) tau_m = 20. # (ms) cm = 1. # (µF/cm²) g_leak = 5e-5 # (S/cm²) e_leak = -49. # (mV) v_thresh = -50. # (mV) v_reset = -60. # (mV) t_refrac = 5. # (ms) (clamped at v_reset) # (mV) 'mean' membrane potential, for calculating CUBA weights v_mean = -60. tau_exc = 5. # (ms) tau_inh = 10. # (ms) # (nS) #Those weights should be similar to the COBA weights g_exc = 0.27 # (nS) # but the delpolarising drift should be taken into account g_inh = 4.5 e_rev_exc = 0. # (mV) e_rev_inh = -80. # (mV) # === Calculate derived parameters =============================== area *= 1e-8 # convert to cm² cm *= area * 1000 # convert to nF r_m = 1e-6 / (g_leak * area) # membrane resistance in MΩ assert tau_m == cm * r_m # just to check # number of excitatory cells n_exc = int(round((n * r_ei / (1 + r_ei)))) n_inh = n - n_exc # number of inhibitory cells print n_exc, n_inh celltype = p.IF_curr_exp # (nA) weight of excitatory synapses w_exc = 1e-3 * g_exc * (e_rev_exc - v_mean) w_inh = 1e-3 * g_inh * (e_rev_inh - v_mean) # (nA) assert w_exc > 0 assert w_inh < 0 # === Build the network ========================================== p.setup(timestep=dt, min_delay=delay, max_delay=delay) if simulator_name == 'spiNNaker': # this will set 100 neurons per core p.set_number_of_neurons_per_core('IF_curr_exp', 100) # this will set 50 neurons per core p.set_number_of_neurons_per_core('IF_cond_exp', 50) node_id = 1 np = 1 host_name = socket.gethostname() print "Host #%d is on %s" % (np, host_name) cell_params = { 'tau_m': tau_m, 'tau_syn_E': tau_exc, 'tau_syn_I': tau_inh, 'v_rest': e_leak, 'v_reset': v_reset, 'v_thresh': v_thresh, 'cm': cm, 'tau_refrac': t_refrac, 'i_offset': 0 } print cell_params timer.start() print "%s Creating cell populations..." % node_id exc_cells = p.Population(n_exc, celltype, cell_params, label="Excitatory_Cells") inh_cells = p.Population(n_inh, celltype, cell_params, label="Inhibitory_Cells") p.NativeRNG(12345) print "%s Initialising membrane potential to random values..." \ % node_id rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) uniform_distr = RandomDistribution('uniform', [v_reset, v_thresh], rng=rng) exc_cells.initialize('v', uniform_distr) inh_cells.initialize('v', uniform_distr) print "%s Connecting populations..." % node_id exc_conn = p.FixedProbabilityConnector(pconn, weights=w_exc, delays=delay) inh_conn = p.FixedProbabilityConnector(pconn, weights=w_inh, delays=delay) connections = dict() connections['e2e'] = p.Projection(exc_cells, exc_cells, exc_conn, target='excitatory', rng=rng) connections['e2i'] = p.Projection(exc_cells, inh_cells, exc_conn, target='excitatory', rng=rng) connections['i2e'] = p.Projection(inh_cells, exc_cells, inh_conn, target='inhibitory', rng=rng) connections['i2i'] = p.Projection(inh_cells, inh_cells, inh_conn, target='inhibitory', rng=rng) # === Setup recording ============================== print "%s Setting up recording..." % node_id exc_cells.record() # === Run simulation ================================ print "%d Running simulation..." % node_id print "timings: number of neurons:", n print "timings: number of synapses:", n * n * pconn p.run(tstop) exc_spikes = exc_cells.getSpikes() print len(exc_spikes) current_file_path = os.path.dirname(os.path.abspath(__file__)) current_file_path = os.path.join(current_file_path, "spikes.data") exc_cells.printSpikes(current_file_path) pre_recorded_spikes = p.utility_calls.read_spikes_from_file( current_file_path, 0, n_exc, 0, tstop) for spike_element, read_element in zip(exc_spikes, pre_recorded_spikes): self.assertEqual(round(spike_element[0], 1), round(read_element[0], 1)) self.assertEqual(round(spike_element[1], 1), round(read_element[1], 1)) p.end() # System intentional overload so may error except SpinnmanTimeoutException as ex: raise SkipTest(ex)
import time from pacman.model.constraints.placer_constraints.placer_chip_and_core_constraint import \ PlacerChipAndCoreConstraint import spynnaker7.pyNN as sim from function_definitions import * from argparser import * case = args.case print "Case", case, "selected!" # SpiNNaker setup start_time = plt.datetime.datetime.now() sim.setup(timestep=1.0, min_delay=1.0, max_delay=10) sim.set_number_of_neurons_per_core("IF_curr_exp", 50) sim.set_number_of_neurons_per_core("IF_cond_exp", 256 // 10) sim.set_number_of_neurons_per_core("SpikeSourcePoisson", 256 // 13) sim.set_number_of_neurons_per_core("SpikeSourcePoissonVariable", 256 // 13) # +-------------------------------------------------------------------+ # | General Parameters | # +-------------------------------------------------------------------+ # Population parameters model = sim.IF_cond_exp # Membrane v_rest = -70 # mV e_ext = 0 # V v_thr = -54 # mV
import numpy as np import pylab as plt import spynnaker7.pyNN as sim from function_definitions import * from argparser import * # SpiNNaker setup start_time = plt.datetime.datetime.now() sim.setup(timestep=1.0, min_delay=1.0, max_delay=10) sim.set_number_of_neurons_per_core("IF_cond_exp", 256 // 10) sim.set_number_of_neurons_per_core("SpikeSourcePoisson", 256 // 5) # +-------------------------------------------------------------------+ # | General Parameters | # +-------------------------------------------------------------------+ # Population parameters model = sim.IF_cond_exp # Membrane v_rest = -70 # mV e_ext = 0 # V v_thr = -54 # mV g_max = 0.2 tau_m = 20 # ms tau_ex = 5 # ms cell_params = { 'cm': 20.0, # nF 'i_offset': 0.0, 'tau_m': 20.0,
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons / 2) 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 } p.set_number_of_neurons_per_core("IF_cond_exp", nNeurons / 2) cell_params_cond = { '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 = 17 injectionConnection = [(0, 0, weight_to_spike, delay)] sinkConnection = [(0, 0, weight_to_spike, 1)] spikeArray = {'spike_times': [[0]]} populations.append( p.Population(nNeurons, p.IF_cond_exp, cell_params_cond, label='pop_cond')) populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_curr')) populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_2')) populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='sink_pop')) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) projections.append( p.Projection(populations[3], populations[2], p.FromListConnector(injectionConnection))) projections.append( p.Projection(populations[0], populations[4], p.FromListConnector(sinkConnection))) projections.append( p.Projection(populations[2], populations[4], p.FromListConnector(sinkConnection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() populations[2].record_v() populations[2].record_gsyn() populations[2].record() p.run(500) cond_v = populations[0].get_v(compatible_output=True) cond_gsyn = populations[0].get_gsyn(compatible_output=True) cond_spikes = populations[0].getSpikes(compatible_output=True) curr_v = populations[2].get_v(compatible_output=True) curr_gsyn = populations[2].get_gsyn(compatible_output=True) curr_spikes = populations[2].getSpikes(compatible_output=True) p.end() return (cond_v, cond_gsyn, cond_spikes, curr_v, curr_gsyn, curr_spikes)
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons / 2) 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 } p.set_number_of_neurons_per_core("IF_cond_exp", nNeurons / 2) cell_params_cond = { '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. } p.set_number_of_neurons_per_core("IZK_curr_exp", 100) cell_params_izk = { 'a': 0.02, 'b': 0.2, 'c': -65, 'd': 8, 'v_init': -75, 'u_init': 0, 'tau_syn_E': 2, 'tau_syn_I': 2, 'i_offset': 0 } populations = list() projections = list() current_weight_to_spike = 2.0 cond_weight_to_spike = 0.035 delay = 17 # different strangths of connection curr_injection_connection = [(0, 0, current_weight_to_spike, delay)] cond_injection_connection = [(0, 0, cond_weight_to_spike, delay)] izk_injection_connection = [(0, 0, current_weight_to_spike, delay)] sinkConnection = [(0, 0, 0, 1)] # spike time spikeArray = {'spike_times': [[0]]} # curr set up populations.append( p.Population(nNeurons, p.IF_cond_exp, cell_params_cond, label='pop_cond')) # cond setup populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_curr')) # izk setup populations.append( p.Population(nNeurons, p.IZK_curr_exp, cell_params_izk, label='izk pop')) # sink pop for spikes to go to (otherwise they are not recorded as firing) populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='sink_pop')) populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpike')) pop = p.Projection(populations[4], populations[0], p.FromListConnector(cond_injection_connection)) projections.append(pop) pop = p.Projection(populations[4], populations[1], p.FromListConnector(curr_injection_connection)) projections.append(pop) pop = p.Projection(populations[4], populations[2], p.FromListConnector(izk_injection_connection)) projections.append(pop) projections.append( p.Projection(populations[2], populations[3], p.FromListConnector(sinkConnection))) projections.append( p.Projection(populations[1], populations[3], p.FromListConnector(sinkConnection))) projections.append( p.Projection(populations[0], populations[3], p.FromListConnector(sinkConnection))) # record stuff for cond populations[0].record_v() populations[0].record_gsyn() populations[0].record() # record stuff for curr populations[1].record_v() populations[1].record_gsyn() populations[1].record() # record stuff for izk populations[2].record_v() populations[2].record_gsyn() populations[2].record() p.run(500) # get cond cond_v = populations[0].get_v(compatible_output=True) cond_gsyn = populations[0].get_gsyn(compatible_output=True) cond_spikes = populations[0].getSpikes(compatible_output=True) # get curr curr_v = populations[1].get_v(compatible_output=True) curr_gsyn = populations[1].get_gsyn(compatible_output=True) curr_spikes = populations[1].getSpikes(compatible_output=True) # get izk izk_v = populations[2].get_v(compatible_output=True) izk_gsyn = populations[2].get_gsyn(compatible_output=True) izk_spikes = populations[2].getSpikes(compatible_output=True) p.end() return (cond_v, cond_gsyn, cond_spikes, curr_v, curr_gsyn, curr_spikes, izk_v, izk_gsyn, izk_spikes)
def do_run(nNeurons, n_pops, neurons_per_core, runtime=25000): """ :param nNeurons: Number of Neurons in chain :type nNeurons: int :param n_pops: Number of populations ;type n_pops: int :param neurons_per_core: Number of neurons per core :type neurons_per_core: int """ p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core("IF_curr_exp", neurons_per_core) 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 } populations = list() projections = list() weight_to_spike = 2.0 delay = 1 connections = list() for i in range(0, nNeurons - 1): singleConnection = (i, i + 1, weight_to_spike, delay) connections.append(singleConnection) pop_jump_connection = [(nNeurons - 1, 0, weight_to_spike, 1)] injectionConnection = [(0, 0, weight_to_spike, 1)] spikeArray = {'spike_times': [[0]]} for i in range(0, n_pops): populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_{}'.format(i))) populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) for i in range(0, n_pops): projections.append( p.Projection(populations[i], populations[i], p.FromListConnector(connections))) connector = p.FromListConnector(pop_jump_connection) projections.append( p.Projection(populations[i], populations[((i + 1) % n_pops)], connector)) projections.append( p.Projection(populations[n_pops], populations[0], p.FromListConnector(injectionConnection))) for pop_index in range(0, n_pops): populations[pop_index].record() p.run(runtime) total_spikes = None total_spikes = populations[0].getSpikes(compatible_output=True) for pop_index in range(1, n_pops): spikes = populations[pop_index].getSpikes(compatible_output=True) if spikes is not None: for spike in spikes: spike[0] += (nNeurons * pop_index) total_spikes = numpy.concatenate((total_spikes, spikes), axis=0) p.end() return total_spikes
def run_sim(num_pre, num_post, spike_times, run_time, weight=5.6, delay=40., gom=False, conn_type='one2one', use_stdp=False, mad=False, prob=0.5): model = p.IF_curr_exp p.setup( timestep = 1.0, min_delay = 1.0, max_delay = 144.0 ) # if num_pre <= 10: # p.set_number_of_neurons_per_core(model, 4) # p.set_number_of_neurons_per_core(p.SpikeSourceArray, 5) # elif 10 < num_pre <= 50: # p.set_number_of_neurons_per_core(model, 20) # p.set_number_of_neurons_per_core(p.SpikeSourceArray, 21) # elif 50 < num_pre <= 100: # p.set_number_of_neurons_per_core(model, 50) # p.set_number_of_neurons_per_core(p.SpikeSourceArray, 51) # else: if use_stdp: p.set_number_of_neurons_per_core(model, 150) p.set_number_of_neurons_per_core(p.SpikeSourceArray, 2000) cell_params_lif = { 'cm' : 1.0, # nF 'i_offset' : 0.00, 'tau_m' : 10.0, 'tau_refrac': 4.0, 'tau_syn_E' : 1.0, 'tau_syn_I' : 1.0, 'v_reset' : -70.0, 'v_rest' : -65.0, 'v_thresh' : -60.0 } cell_params_pos = { 'spike_times': spike_times, } w2s = weight dly = delay rng = NumpyRNG( seed = 1 ) if use_stdp: td = p.SpikePairRule(tau_minus=1., tau_plus=1.) wd = p.AdditiveWeightDependence(w_min=0, w_max=20., A_plus=0.0, A_minus=0.0) stdp = p.STDPMechanism(timing_dependence=td, weight_dependence=wd) syn_dyn = p.SynapseDynamics(slow=stdp) else: syn_dyn = None sink = p.Population( num_post, model, cell_params_lif, label='sink') # sink1 = p.Population( nNeuronsPost, model, cell_params_lif, label='sink1') source0 = p.Population( num_pre, p.SpikeSourceArray, cell_params_pos, label='source_0') # source1 = p.Population( nNeurons, p.SpikeSourceArray, cell_params_pos, # label='source_1') if conn_type == 'one2one': conn = p.OneToOneConnector(weights=w2s, delays=dly, generate_on_machine=gom) elif conn_type == 'all2all': conn = p.AllToAllConnector(weights=w2s, delays=dly, generate_on_machine=gom) elif conn_type == 'fixed_prob': conn = p.FixedProbabilityConnector(prob, weights=w2s, delays=dly, generate_on_machine=gom) else: raise Exception("Not a valid connector for test") proj = p.Projection( source0, sink, conn, target='excitatory', synapse_dynamics=syn_dyn, label=' source 0 to sink - EXC - delayed') # sink.record_v() # sink.record_gsyn() sink.record() print("Running for {} ms".format(run_time)) t0 = time.time() p.run(run_time) time_to_run = time.time() - t0 v = None gsyn = None spikes = None # v = np.array(sink.get_v(compatible_output=True)) # gsyn = sink.get_gsyn(compatible_output=True) spikes = sink.getSpikes(compatible_output=True) w = proj.getWeights(format='array') p.end() return v, gsyn, spikes, w, time_to_run
def do_run(nNeurons, neurons_per_core): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core("IF_curr_exp", neurons_per_core) nPopulations = 62 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 } populations = list() projections = list() weight_to_spike = 1.5 delay = 5 for i in range(0, nPopulations): populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_' + str(i))) # print "++++++++++++++++" # print "Added population %s" % (i) # print "o-o-o-o-o-o-o-o-" for i in range(0, nPopulations): projections.append( p.Projection(populations[i], populations[(i + 1) % nPopulations], p.OneToOneConnector(weight_to_spike, delay), label="Projection from pop {} to pop " "{}".format(i, (i + 1) % nPopulations))) # print "++++++++++++++++++++++++++++++++++++++++++++++++++++" # print "Added projection from population %s to population %s" \ # % (i, (i + 1) % nPopulations) # print "----------------------------------------------------" # pp(projections) spikeArray = {'spike_times': [[0]]} populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) projections.append( p.Projection(populations[-1], populations[0], p.AllToAllConnector(weight_to_spike, delay))) for i in range(0, nPopulations): populations[i].record_v() populations[i].record_gsyn() populations[i].record() p.run(1500) v = None gsyn = None spikes = None '''' weights = projections[0].getWeights() delays = projections[0].getDelays() ''' v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) p.end() return (v, gsyn, spikes)
def do_run( self, n_neurons, time_step=1, max_delay=144.0, input_class=SpikeSourceArray, spike_times=None, rate=None, start_time=None, duration=None, spike_times_list=None, placement_constraint=None, weight_to_spike=2.0, delay=17, neurons_per_core=10, cell_class=IF_curr_exp, constraint=None, cell_params=CELL_PARAMS_LIF, run_times=None, reset=False, extract_between_runs=True, set_between_runs=None, new_pop=False, record_input_spikes=False, record=True, get_spikes=None, spike_path=None, record_v=True, get_v=None, v_path=None, record_gsyn=True, get_gsyn=None, gsyn_path=None, use_spike_connections=True, use_wrap_around_connections=True, get_weights=False, get_delays=False, end_before_print=False, randomise_v_init=False): """ :param n_neurons: Number of Neurons in chain :type n_neurons: int :param time_step: time step value to be used in p.setup :type time_step: float :param max_delay: max_delay value to be used in p.setup :type max_delay: float :param rate: the rate of the SSP to fire at :type rate: float :param start_time: the start time for the SSP :type start_time: float :param duration: the length of time for the SSP to fire for :type duration: float :param input_class: the class for inputs spikes (SSA or SSP) :type input_class: SpikeSourceArray, SpikeSourcePoisson :param spike_times: times the SSA sends in spikes :type spike_times: matrix of int times the SSA sends in spikes :param spike_times_list: list of times the SSA sends in spikes - must be the same length as run times - If set the spike_time parameter is ignored :type spike_times_list: list of matrix of int times the SSA sends in spikes :param placement_constraint: x, y and p values to add a placement_constraint to population[0] :type (int, int, int) :type weight_to_spike: float :param delay: time delay in the single connectors in the spike chain :type delay: float :param neurons_per_core: Number of neurons per core. If set to None no set_number_of_neurons_per_core call will be made :type neurons_per_core: int or None :param constraint: A Constraint to be place on populations[0] :type constraint: AbstractConstraint :param cell_class: class to be used for the main population Not used by any test at the moment :type cell_class: AbstractPopulationVertex :param cell_params: values for the main population Not used by any test at the moment Note: the values must match what is expected by the cellclass :type cell_params: dict :param run_times: times for each run. A zero will skip run but trigger reset and get date ext as set :type run_times: list of int :param reset: if True will call reset after each run except the last :type reset: bool :param extract_between_runs: If True reads V, gysn and spikes between each run. :type extract_between_runs: bool :param set_between_runs set instuctions to be carried out between runs. Should be a list of tuples. First element of each tuple is 0 or 1 0 for main population 1 for input polulation Second element a String for name of peroperty to change Third element the new value :type set_between_runs: List[(int, String, any)] :param new_pop: If True will add a new population before the second run :type new_pop: bool :param record_input_spikes: check for recording input spikes :type record_input_spikes: bool :param record: If True will aks for spikes to be recorded :type record: bool :param get_spikes: If set overrides the normal behaviour of getting spikes if and only if record is True. If left None the value of record is used. :type get_spikes: bool :param spike_path: The path to print(write) the last spike data too :type spike_path: str or None :param record_v: If True will aks for voltage to be recorded :type record_v: bool :param get_v: If set overrides the normal behaviour of getting v if and only if record_v is True. If left None the value of record_v is used. :type get_v: bool :param v_path: The path to print(write) the last v data too :type v_path: str or None :param record_gsyn: If True will aks for gsyn to be recorded :type record_gsyn: bool :param get_gsyn: If set overrides the normal behaviour of getting gsyn if and only if record_gsyn is True. If left None the value of record_gsyn is used. :type get_v: bool :param gsyn_path: The path to print(write) the last gsyn data too :type gsyn_path: str or None :param get_weights: If True weights will be gotten :type get_weights: bool :param get_delays: If True delays will be gotten :type get_delays: bool :param end_before_print: If True will call end() before running the \ optional print commands. Note: end will always be called twice even if no print path provided WARNING: This is expected to cause an Exception \ if spike_path, v_path or gsyn_path provided :type end_before_print: bool :param randomise_v_init: randomises the v_init of the output pop. :type randomise_v_init: bool :param use_spike_connections: Will put the spike connections in :type use_spike_connections: bool :param use_wrap_around_connections: Will also put in a connector from the last spike neuron back to the first Note: Has no effect if use_spike_connections == False :type use_wrap_around_connections: bool """ self._recorded_v = [] self._recorded_spikes = [] self._recorded_gsyn = [] self._input_spikes_recorded = [] self._weights = [] self._delays = [] if run_times is None: run_times = [1000] if set_between_runs is None: set_between_runs = [] if len(set_between_runs) > 0 and len(run_times) != 2: raise Exception("set_between_runs requires exactly 2 run times") if spike_times is None: spike_times = [[0]] if get_spikes is None: get_spikes = record if get_v is None: get_v = record_v if get_gsyn is None: get_gsyn = record_gsyn p.setup(timestep=time_step, min_delay=1.0, max_delay=max_delay) if neurons_per_core is not None: p.set_number_of_neurons_per_core("IF_curr_exp", neurons_per_core) populations = list() projections = list() loop_connections = list() if use_wrap_around_connections: for i in range(0, n_neurons): single_connection = \ (i, ((i + 1) % n_neurons), weight_to_spike, delay) loop_connections.append(single_connection) else: for i in range(0, n_neurons - 1): single_connection = (i, i + 1, weight_to_spike, delay) loop_connections.append(single_connection) injection_connection = [(0, 0, weight_to_spike, 1)] run_count = 0 if spike_times_list is None: spike_array = {'spike_times': spike_times} else: spike_array = {'spike_times': spike_times_list[run_count]} populations.append(p.Population( n_neurons, cell_class, cell_params, label='pop_1')) if placement_constraint is not None: if len(placement_constraint) == 2: (x, y) = placement_constraint populations[0].add_placement_constraint(x=x, y=y) else: (x, y, proc) = placement_constraint populations[0].add_placement_constraint(x=x, y=y, p=proc) if randomise_v_init: rng = p.NumpyRNG(seed=28375) v_init = p.RandomDistribution('uniform', [-60, -40], rng) populations[0].randomInit(v_init) if constraint is not None: populations[0].set_constraint(constraint) if input_class == SpikeSourceArray: populations.append(p.Population( 1, input_class, spike_array, label='inputSSA_1')) else: populations.append(p.Population( 1, input_class, {'rate': rate, 'start': start_time, 'duration': duration}, label='inputSSP_1')) # handle projections if use_spike_connections: projections.append(p.Projection(populations[0], populations[0], p.FromListConnector(loop_connections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injection_connection))) # handle recording if record or spike_path is not None: populations[0].record() if record_v or v_path is not None: populations[0].record_v() if record_gsyn or gsyn_path is not None: populations[0].record_gsyn() if record_input_spikes: populations[1].record() results = () for runtime in run_times[:-1]: # This looks strange but is to allow getting data before run if runtime > 0: p.run(runtime) run_count += 1 if extract_between_runs: self._get_data( populations[0], populations[1], get_spikes, get_v, get_gsyn, record_input_spikes) if get_weights: self._weights.append(projections[0].getWeights()) if get_delays: self._delays.append(projections[0].getDelays()) if new_pop: populations.append( p.Population(n_neurons, cell_class, cell_params, label='pop_2')) injection_connection = [(n_neurons - 1, 0, weight_to_spike, 1)] new_projection = p.Projection( populations[0], populations[2], p.FromListConnector(injection_connection)) projections.append(new_projection) if spike_times_list is not None: populations[1].tset("spike_times", spike_times_list[run_count]) for (pop, name, value) in set_between_runs: if pop == 0: populations[0].set(name, value) else: populations[1].set(name, value) if reset: p.reset() p.run(run_times[-1]) self._get_data( populations[0], populations[1], get_spikes, get_v, get_gsyn, record_input_spikes) if get_weights: self._weights.append(projections[0].getWeights()) if get_delays: self._delays.append(projections[0].getDelays()) if end_before_print: if v_path is not None or spike_path is not None or \ gsyn_path is not None: print "NOTICE! end is being called before print.. commands " \ "which could cause an exception" p.end() if v_path is not None: populations[0].print_v(v_path) if spike_path is not None: populations[0].printSpikes(spike_path) if gsyn_path is not None: populations[0].print_gsyn(gsyn_path) p.end() return results
def test_agent(weight): # Setup pyNN simulation weight = weight / 100. weight = weight * -1 print "da weight = ", weight p.setup(timestep=1.0) p.set_number_of_neurons_per_core(p.IF_cond_exp, 100) receive_pop_size = 1 hidden_pop_size = 1 output_size = 1 # Create input population and connect break out to it receive_on_pop = p.Population(receive_pop_size, p.IF_cond_exp, {}, label="receive_pop") # Create output population and remaining population output_pop = p.Population(output_size, p.IF_cond_exp, {}, label="output_pop") hidden_node_pop = p.Population(hidden_pop_size, p.IF_cond_exp, {}, label="hidden_pop") hidden_node_pop.record() receive_on_pop.record() output_pop.record() spikes_in = p.Population(1, p.SpikeSourceArray, {'spike_times': [100]}, label='spike') p.Projection(output_pop, receive_on_pop, p.AllToAllConnector(weights=weight)) p.Projection(receive_on_pop, hidden_node_pop, p.AllToAllConnector(weights=weight)) p.Projection(hidden_node_pop, output_pop, p.AllToAllConnector(weights=weight)) p.Projection(spikes_in, receive_on_pop, p.AllToAllConnector(weights=weight)) runtime = 1000 p.run(runtime) pylab.figure() spikes_on = receive_on_pop.getSpikes() ax = pylab.subplot(1, 3, 1) #4, 1) pylab.plot([i[1] for i in spikes_on], [i[0] for i in spikes_on], "r.") pylab.xlabel("Time (ms)") pylab.ylabel("neuron ID") pylab.axis([0, runtime, -1, receive_pop_size + 1]) # pylab.show() # pylab.figure() spikes_on = hidden_node_pop.getSpikes() ax = pylab.subplot(1, 3, 2) #4, 1) pylab.plot([i[1] for i in spikes_on], [i[0] for i in spikes_on], "r.") pylab.xlabel("Time (ms)") pylab.ylabel("neuron ID") pylab.axis([0, runtime, -1, hidden_pop_size + 1]) # pylab.show() # pylab.figure() spikes_on = output_pop.getSpikes() ax = pylab.subplot(1, 3, 3) #4, 1) pylab.plot([i[1] for i in spikes_on], [i[0] for i in spikes_on], "r.") pylab.xlabel("Time (ms)") pylab.ylabel("neuron ID") pylab.axis([0, runtime, -1, output_size + 1]) pylab.show() # End simulation p.end()
import spynnaker7.pyNN as sim import numpy import pylab as plt from signal_prep import * Fs = 22050. audio_data = numpy.load('./audio_data.npy') duration = len(audio_data) / Fs plt.figure() t = numpy.arange(0.0, duration, 1 / Fs) plt.plot(t, audio_data) # Setup pyNN simulation sim.setup(timestep=1.) sim.set_number_of_neurons_per_core(sim.extra_models.IZK_curr_exp, 100) #sim.set_number_of_neurons_per_core(sim.IF_cond_exp, 50) #open AN spike source #spike_trains=numpy.load("/home/rjames/Dropbox (The University of Manchester)/EarProject/spike_trains_kate_a_10kfib.npy") spike_trains = numpy.load( "/home/rjames/Dropbox (The University of Manchester)/EarProject/spike_trains_6k_640fib_50dB.npy" ) #spike_trains=numpy.load("/home/rjames/Dropbox (The University of Manchester)/EarProject/spike_trains_v2.npy") spike_ids = [neuron_id for (neuron_id, spike_time) in spike_trains] spike_ids[:] = [neuron_id + 1 for neuron_id in spike_ids] AN_pop_size = numpy.max(spike_ids) spike_times = [spike_time for (neuron_id, spike_time) in spike_trains] an_scale_factor = duration / numpy.max(spike_times) scaled_times = [spike_time * an_scale_factor for spike_time in spike_times]
def do_run(Neurons, sim_time, record): """ :param Neurons: Number of Neurons :type Neurons: int :param sim_time: times for run :type sim_time: int :param record: If True will aks for spikes to be recorded :type record: bool """ g = 5.0 eta = 2.0 delay = 2.0 epsilon = 0.1 tau_m = 20.0 # ms (20ms will give a FR of 20hz) tau_ref = 2.0 v_reset = 10.0 V_th = 20.0 v_rest = 0.0 tauSyn = 1.0 N_E = int(round(Neurons * 0.8)) N_I = int(round(Neurons * 0.2)) C_E = N_E * 0.1 # Excitatory and inhibitory weights J_E = 0.1 J_I = -g * J_E # The firing rate of a neuron in the external pop # is the product of eta time the threshold rate # the steady state firing rate which is # needed to bring a neuron to threshold. nu_ex = eta * V_th / (J_E * C_E * tau_m) # population rate of the whole external population. # With CE neurons the pop rate is simply the product # nu_ex*C_E the factor 1000.0 changes the units from # spikes per ms to spikes per second. p_rate = 1000.0 * nu_ex * C_E print "Rate is: %f HZ" % (p_rate / 1000) # Neural Parameters pynn.setup(timestep=1.0, min_delay=1.0, max_delay=16.0) if simulator_Name == "spiNNaker": # Makes it easy to scale up the number of cores pynn.set_number_of_neurons_per_core("IF_curr_exp", 100) pynn.set_number_of_neurons_per_core("SpikeSourcePoisson", 100) rng = NumpyRNG(seed=1) RandomDistribution('uniform', [-10.0, 0.0], rng) RandomDistribution('uniform', [-10.0, 0.0], rng) exc_cell_params = { 'cm': 1.0, # pf 'tau_m': tau_m, 'tau_refrac': tau_ref, 'v_rest': v_rest, 'v_reset': v_reset, 'v_thresh': V_th, 'tau_syn_E': tauSyn, 'tau_syn_I': tauSyn, 'i_offset': 0.9 } inh_cell_params = { 'cm': 1.0, # pf 'tau_m': tau_m, 'tau_refrac': tau_ref, 'v_rest': v_rest, 'v_reset': v_reset, 'v_thresh': V_th, 'tau_syn_E': tauSyn, 'tau_syn_I': tauSyn, 'i_offset': 0.9 } # Set-up pynn Populations E_pop = pynn.Population(N_E, pynn.IF_curr_exp, exc_cell_params, label="E_pop") I_pop = pynn.Population(N_I, pynn.IF_curr_exp, inh_cell_params, label="I_pop") Poiss_ext_E = pynn.Population(N_E, pynn.SpikeSourcePoisson, {'rate': 10.0}, label="Poisson_pop_E") Poiss_ext_I = pynn.Population(N_I, pynn.SpikeSourcePoisson, {'rate': 10.0}, label="Poisson_pop_I") # Connectors E_conn = pynn.FixedProbabilityConnector(epsilon, weights=J_E, delays=delay) I_conn = pynn.FixedProbabilityConnector(epsilon, weights=J_I, delays=delay) # Use random delays for the external noise and # set the inital membrance voltage below the resting potential # to avoid the overshoot of activity in the beginning of the simulation rng = NumpyRNG(seed=1) delay_distr = RandomDistribution('uniform', [1.0, 16.0], rng=rng) Ext_conn = pynn.OneToOneConnector(weights=J_E * 10, delays=delay_distr) uniformDistr = RandomDistribution('uniform', [-10, 0], rng) E_pop.initialize('v', uniformDistr) I_pop.initialize('v', uniformDistr) # Projections pynn.Projection(E_pop, E_pop, E_conn, target="excitatory") pynn.Projection(I_pop, E_pop, I_conn, target="inhibitory") pynn.Projection(E_pop, I_pop, E_conn, target="excitatory") pynn.Projection(I_pop, I_pop, I_conn, target="inhibitory") pynn.Projection(Poiss_ext_E, E_pop, Ext_conn, target="excitatory") pynn.Projection(Poiss_ext_I, I_pop, Ext_conn, target="excitatory") # Record stuff if record: E_pop.record() Poiss_ext_E.record() pynn.run(sim_time) esp = None s = None if record: esp = E_pop.getSpikes(compatible_output=True) s = Poiss_ext_E.getSpikes(compatible_output=True) pynn.end() return (esp, s, N_E)
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core("IF_curr_exp", 100) cm = list() i_off = list() tau_m = list() tau_re = list() tau_syn_e = list() tau_syn_i = list() v_reset = list() v_rest = list() v_thresh = list() cell_params_lif = {'cm': cm, 'i_offset': i_off, 'tau_m': tau_m, 'tau_refrac': tau_re, 'tau_syn_E': tau_syn_e, 'tau_syn_I': tau_syn_i, 'v_reset': v_reset, 'v_rest': v_rest, 'v_thresh': v_thresh} for atom in range(0, nNeurons): cm.append(0.25) i_off.append(0.0) tau_m.append(10.0) tau_re.append(2.0) tau_syn_e.append(0.5) tau_syn_i.append(0.5) v_reset.append(-65.0) v_rest.append(-65.0) v_thresh.append(-64.4) gbar_na_distr = RandomDistribution('normal', (20.0, 2.0), rng=NumpyRNG(seed=85524)) cell_params_lif = {'cm': cm, 'i_offset': i_off, 'tau_m': tau_m, 'tau_refrac': tau_re, 'tau_syn_E': tau_syn_e, 'tau_syn_I': tau_syn_i, 'v_reset': v_reset, 'v_rest': v_rest, 'v_thresh': v_thresh} populations = list() projections = list() weight_to_spike = 2 delay = 1 connections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, delay)] spikeArray = {'spike_times': [[0]]} populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append(p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) populations[0].set({'cm': 0.25}) populations[0].set('cm', cm) populations[0].set({'tau_m': tau_m, 'v_thresh': v_thresh}) populations[0].set('i_offset', gbar_na_distr) populations[0].set('i_offset', i_off) projections.append(p.Projection(populations[0], populations[0], p.FromListConnector(connections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(100) v = populations[0].get_v(compatible_output=True) gsyn = populations[0].get_gsyn(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True) p.end() return (v, gsyn, spikes)
extra = { 'threads': threads, 'filename': "va_%s.xml" % benchmark, 'label': 'VA' } if simulator_name == "neuroml": extra["file"] = "VAbenchmarks.xml" node_id = p.setup(timestep=dt, min_delay=delay, max_delay=delay, db_name='va_benchmark.sqlite', **extra) if simulator_name == 'spiNNaker': p.set_number_of_neurons_per_core('IF_curr_exp', 100) # this will set 100 neurons per core p.set_number_of_neurons_per_core('IF_cond_exp', 50) # this will set 50 neurons per core node_id = 1 np = 1 host_name = socket.gethostname() print "Host #%d is on %s" % (np, host_name) print "%s Initialising the simulator with %d thread(s)..." \ "" % (node_id, extra['threads']) cell_params = { 'tau_m': tau_m,