def build_network(self, dynamics, cell_params): """ Function to build the basic network - dynamics should be a PyNN synapse dynamics object :param dynamics: :return: """ # SpiNNaker setup model = sim.IF_curr_exp sim.setup(timestep=0.1, min_delay=1.0, max_delay=10.0) # Create excitatory and inhibitory populations of neurons ex_pop = sim.Population(NUM_EXCITATORY, model, cell_params) in_pop = sim.Population(NUM_EXCITATORY / 4, model, cell_params) # Record excitatory spikes ex_pop.record() # Make excitatory->inhibitory projections sim.Projection(ex_pop, in_pop, sim.FixedProbabilityConnector( 0.02, weights=0.03), target='excitatory') sim.Projection(ex_pop, ex_pop, sim.FixedProbabilityConnector( 0.02, weights=0.03), target='excitatory') # Make inhibitory->inhibitory projections sim.Projection(in_pop, in_pop, sim.FixedProbabilityConnector( 0.02, weights=-0.3), target='inhibitory') # Make inhibitory->excitatory projections ie_projection = sim.Projection( in_pop, ex_pop, sim.FixedProbabilityConnector(0.02, weights=0), target='inhibitory', synapse_dynamics=dynamics) return ex_pop, ie_projection
def test_invalid_min_delay_1_millisecond_timestep(self): """ tests if with invalid user min, the min raises exefpetiosn :return: """ with self.assertRaises(ConfigurationException): p.setup(1, min_delay=0.1)
def test_invalid_max_delay(self): """ tests that with invalid user input the max delay raises correctly :return: """ with self.assertRaises(ConfigurationException): p.setup(1, max_delay=100000)
def test_valid_max_delay_0_1_millisecond_timestep(self): """ tests if with valid user min, the min is set correctly :return: """ p.setup(0.1, max_delay=0.4) max_delay = p.get_max_delay() self.assertEqual(max_delay, 0.4)
def test_get_min_delay_0_1_milisecond_timestep(self): """ tests if with no user min, the min is set to 1 timestep in millisencsd :return: """ p.setup(0.1) min_delay = p.get_min_delay() self.assertEqual(min_delay, 0.1)
def test_max_delay_no_user_input_1_millisecond_timestep(self): """ Tests that with no user input, the max delay is correct :return: """ p.setup(1) max_delay = p.get_max_delay() self.assertEqual(max_delay, 144)
def test_script(self): """ test that tests the printing of v from a pre determined recording :return: """ p.setup(timestep=1.0, min_delay=1.0, max_delay=144.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 = 17 spikes = read_spikefile('test.spikes', n_neurons) print spikes 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) if spikes is not None: print spikes pylab.figure() pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes') pylab.show() else: print "No spikes received" p.end()
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 random_time in range(0, 20): random_time2 = random.randint(0, 5000) boxed_array = numpy.append(boxed_array, [[neuron_id, random_time2]], 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 __init__(self, simulation_time=1000, simulation_time_step=0.2, n_chips_required=48 * 6, threads_count=4): self.simulation_time = simulation_time self.time_step = simulation_time_step # setup timestep of simulation and minimum and maximum synaptic delays ps.setup(timestep=simulation_time_step, min_delay=simulation_time_step, max_delay=10 * simulation_time_step, n_chips_required=n_chips_required, threads=threads_count)
def test_recording_numerious_element_over_limit(self): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 2000 # 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 random_time in range(0, 200000): random_time2 = random.randint(0, 50000) boxed_array = numpy.append( boxed_array, [[neuron_id, random_time2]], 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(50000) 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 test_initial_setup(self): import spynnaker.pyNN as pynn self.assertEqual(pynn.setup(timestep=1, min_delay=1, max_delay=15.0), 0) self.assertEqual(conf.config.getint("Machine", "machineTimeStep"), 1 * 1000) self.assertEqual(pynn.get_min_delay(), 1) self.assertEqual(pynn.get_max_delay(), 15.0)
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 test_initial_setup(self): import spynnaker.pyNN as pynn self.assertEqual(pynn.setup(timestep=1, min_delay=1, max_delay=15.0), None) self.assertEqual(conf.config.getint("Machine", "machineTimeStep"), 1 * 1000) self.assertEqual(pynn.get_min_delay(), 1) self.assertEqual(pynn.get_max_delay(), 15.0)
def build_network(self, dynamics, cell_params): """ Function to build the basic network - dynamics should be a PyNN synapse dynamics object :param dynamics: :return: """ # SpiNNaker setup model = sim.IF_curr_exp sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # Create excitatory and inhibitory populations of neurons ex_pop = sim.Population(NUM_EXCITATORY, model, cell_params) in_pop = sim.Population(NUM_EXCITATORY / 4, model, cell_params) # Record excitatory spikes ex_pop.record() # Make excitatory->inhibitory projections sim.Projection(ex_pop, in_pop, sim.FixedProbabilityConnector(0.02, weights=0.03), target='excitatory') sim.Projection(ex_pop, ex_pop, sim.FixedProbabilityConnector(0.02, weights=0.03), target='excitatory') # Make inhibitory->inhibitory projections sim.Projection(in_pop, in_pop, sim.FixedProbabilityConnector(0.02, weights=-0.3), target='inhibitory') # Make inhibitory->excitatory projections ie_projection = sim.Projection(in_pop, ex_pop, sim.FixedProbabilityConnector( 0.02, weights=0), target='inhibitory', synapse_dynamics=dynamics) return ex_pop, ie_projection
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 simulate(self, spinnaker, input_spike_times): # Cell parameters cell_params = { 'tau_m': 20.0, 'v_rest': -60.0, 'v_reset': -60.0, 'v_thresh': -40.0, 'tau_syn_E': 2.0, 'tau_syn_I': 2.0, 'tau_refrac': 2.0, 'cm': 0.25, 'i_offset': 0.0, } rng = p.NumpyRNG(seed=28375) v_init = p.RandomDistribution('uniform', [-60, -40], rng) p.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) pop = p.Population(1, p.IF_curr_exp, cell_params, label='population') pop.randomInit(v_init) pop.record() pop.record_v() noise = p.Population(1, p.SpikeSourceArray, {"spike_times": input_spike_times}) p.Projection(noise, pop, p.OneToOneConnector(weights=0.4, delays=1), target='excitatory') # Simulate p.run(self.simtime) pop_voltages = pop.get_v(compatible_output=True) pop_spikes = pop.getSpikes(compatible_output=True) p.end() return pop_voltages, pop_spikes
def main(): # setup timestep of simulation and minimum and maximum synaptic delays Frontend.setup(timestep=simulationTimestep, min_delay=minSynapseDelay, max_delay=maxSynapseDelay, threads=4) # create a spike sources retinaLeft = createSpikeSource("RetL") retinaRight = createSpikeSource("RetR") # create network and attach the spike sources network, (liveConnectionNetwork, liveConnectionRetinas) = createCooperativeNetwork(retinaLeft=retinaLeft, retinaRight=retinaRight) # non-blocking run for time in milliseconds print "Simulation started..." Frontend.run(simulationTime) print "Simulation ended." # plot results # # plotExperiment(retinaLeft, retinaRight, network) # finalise program and simulation Frontend.end()
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[0], populations[0], p.OneToOneConnector())) 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 build_network(dynamics): # SpiNNaker setup sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # Create excitatory and inhibitory populations of neurons ex_pop = sim.Population(NUM_EXCITATORY, model, cell_params) in_pop = sim.Population(NUM_EXCITATORY / 4, model, cell_params) # Record excitatory spikes ex_pop.record() # Make excitatory->inhibitory projections sim.Projection(ex_pop, in_pop, sim.FixedProbabilityConnector(0.02, weights=0.03), target='excitatory') sim.Projection(ex_pop, ex_pop, sim.FixedProbabilityConnector(0.02, weights=0.03), target='excitatory') # Make inhibitory->inhibitory projections sim.Projection(in_pop, in_pop, sim.FixedProbabilityConnector(0.02, weights=-0.3), target='inhibitory') # Make inhibitory->excitatory projections ie_projection = sim.Projection(in_pop, ex_pop, sim.FixedProbabilityConnector(0.02, weights=0), target='inhibitory', synapse_dynamics = dynamics) return ex_pop, ie_projection
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 main(): # setup timestep of simulation and minimum and maximum synaptic delays Frontend.setup(timestep=simulationTimestep, min_delay=minSynapseDelay, max_delay=maxSynapseDelay, threads=4) # create a spike sources retinaLeft = createSpikeSource("RetL") retinaRight = createSpikeSource("RetR") # create network and attach the spike sources network = createCooperativeNetwork(retinaLeft=retinaLeft, retinaRight=retinaRight) # run simulation for time in milliseconds print "Simulation started..." Frontend.run(simulationTime) # print network[0][1].label # spikeList = network[0][1].getSpikes() # print spikeList # finalise program and simulation Frontend.end() print "Simulation ended." from NetworkVisualiser import logFile logFile.close()
def start_sim(self,sim_time): #simulation setup self.simtime = sim_time sim.setup(timestep=self.setup_cond["timestep"], min_delay=self.setup_cond["min_delay"], max_delay=self.setup_cond["max_delay"]) #initialise the neuron population spikeArrayOn = {'spike_times': self.in_spike} pre_pop = sim.Population(self.pre_pop_size, sim.SpikeSourceArray, spikeArrayOn, label='inputSpikes_On') post_pop= sim.Population(self.post_pop_size,sim.IF_curr_exp, self.cell_params_lif, label='post_1') stdp_model = sim.STDPMechanism(timing_dependence=sim.SpikePairRule(tau_plus= self.stdp_param["tau_plus"], tau_minus= self.stdp_param["tau_minus"], nearest=True), weight_dependence=sim.MultiplicativeWeightDependence(w_min= self.stdp_param["w_min"], w_max= self.stdp_param["w_max"], A_plus= self.stdp_param["A_plus"], A_minus= self.stdp_param["A_minus"])) #initialise connectiviity of neurons #exitatory connection between pre-synaptic and post-synaptic neuron population if(self.inhibitory_spike_mode): connectionsOn = sim.Projection(pre_pop, post_pop, sim.AllToAllConnector(weights = self.I_syn_weight,delays=1, allow_self_connections=False), target='inhibitory') else: if(self.STDP_mode): if(self.allsameweight): connectionsOn = sim.Projection(pre_pop, post_pop, sim.AllToAllConnector(weights = self.E_syn_weight,delays=1), synapse_dynamics=sim.SynapseDynamics(slow=stdp_model),target='excitatory') else: connectionsOn = sim.Projection(pre_pop, post_pop, sim.FromListConnector(self.conn_list), synapse_dynamics=sim.SynapseDynamics(slow=stdp_model),target='excitatory') else: if(self.allsameweight): connectionsOn = sim.Projection(pre_pop, post_pop, sim.AllToAllConnector(weights = self.E_syn_weight,delays=1), target='excitatory') else: connectionsOn = sim.Projection(pre_pop, post_pop, sim.FromListConnector(self.conn_list), target='excitatory') #sim.Projection.setWeights(self.E_syn_weight) #inhibitory between the neurons post-synaptic neuron population connection_I = sim.Projection(post_pop, post_pop, sim.AllToAllConnector(weights = self.I_syn_weight,delays=1, allow_self_connections=False), target='inhibitory') pre_pop.record() post_pop.record() post_pop.record_v() sim.run(self.simtime) self.pre_spikes = pre_pop.getSpikes(compatible_output=True) self.post_spikes = post_pop.getSpikes(compatible_output=True) self.post_spikes_v = post_pop.get_v(compatible_output=True) self.trained_weights = connectionsOn.getWeights(format='array') sim.end() #print self.conn_list #print self.trained_weights '''scipy.io.savemat('trained_weight.mat',{'initial_weight':self.init_weights, 'trained_weight':self.trained_weights })''' scipy.io.savemat('trained_weight0.mat',{'trained_weight':self.trained_weights })
def test_get_voltage(self): """ test that tests the getting of v from a pre determined recording :return: """ p.setup(timestep=1, min_delay=1.0, max_delay=14.40) n_neurons = 200 # number of neurons in each population runtime = 500 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() weight_to_spike = 2.0 delay = 1.7 loop_connections = list() for i in range(0, n_neurons): single_connection = (i, ((i + 1) % n_neurons), weight_to_spike, delay) loop_connections.append(single_connection) injection_connection = [(0, 0, weight_to_spike, 1)] 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[0], populations[0], p.FromListConnector(loop_connections))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injection_connection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(runtime) v = populations[0].get_v(compatible_output=True) current_file_path = os.path.dirname(os.path.abspath(__file__)) current_file_path = os.path.join(current_file_path, "v.data") pre_recorded_data = p.utility_calls.read_in_data_from_file( current_file_path, 0, n_neurons, 0, runtime) p.end() for spike_element, read_element in zip(v, pre_recorded_data): self.assertEqual(round(spike_element[0], 1), round(read_element[0], 1)) self.assertEqual(round(spike_element[1], 1), round(read_element[1], 1)) self.assertEqual(round(spike_element[2], 1), round(read_element[2], 1))
def estimate_kb(cell_params_lif): cell_para = copy.deepcopy(cell_params_lif) random.seed(0) p.setup(timestep=1.0, min_delay=1.0, max_delay=16.0) run_s = 10. runtime = 1000. * run_s max_rate = 1000. ee_connector = p.OneToOneConnector(weights=1.0, delays=2.0) pop_list = [] pop_output = [] pop_source = [] x = np.arange(0., 1.01, 0.1) count = 0 trail = 10 for i in x: for j in range(trail): #trails for average pop_output.append(p.Population(1, p.IF_curr_exp, cell_para)) poisson_spikes = poisson_generator(i * max_rate, 0, runtime) pop_source.append( p.Population(1, p.SpikeSourceArray, {'spike_times': poisson_spikes})) p.Projection(pop_source[count], pop_output[count], ee_connector, target='excitatory') pop_output[count].record() count += 1 count = 0 for i in x: cell_para['i_offset'] = i pop_list.append(p.Population(1, p.IF_curr_exp, cell_para)) pop_list[count].record() count += 1 pop_list[count - 1].record_v() p.run(runtime) rate_I = np.zeros(count) rate_P = np.zeros(count) rate_P_max = np.zeros(count) rate_P_min = np.ones(count) * 1000. for i in range(count): spikes = pop_list[i].getSpikes(compatible_output=True) rate_I[i] = len(spikes) / run_s for j in range(trail): spikes = pop_output[i * trail + j].getSpikes(compatible_output=True) spike_num = len(spikes) / run_s rate_P[i] += spike_num if spike_num > rate_P_max[i]: rate_P_max[i] = spike_num if spike_num < rate_P_min[i]: rate_P_min[i] = spike_num rate_P[i] /= trail ''' #plot_spikes(spikes, 'Current = 10. mA') plt.plot(x, rate_I, label='current',) plt.plot(x, rate_P, label='Poisson input') plt.fill_between(x, rate_P_min, rate_P_max, facecolor = 'green', alpha=0.3) ''' x0 = np.where(rate_P > 1.)[0][0] x1 = 4 k = (rate_P[x1] - rate_P[x0]) / (x[x1] - x[x0]) ''' plt.plot(x, k*(x-x[x0])+rate_P[x0], label='linear') plt.legend(loc='upper left', shadow=True) plt.grid('on') plt.show() ''' p.end() return k, x[x0], rate_P[x0]
import unittest from spynnaker.pyNN.models.neuron.builds.if_curr_dual_exp import IFCurrDualExp import spynnaker.pyNN as pyNN if not pyNN: pyNN.setup(1, 1, 15) class TestIFCurrDualExpModel(unittest.TestCase): def test_new_if_curr_dual_exp_model(self): 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_E2': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0} n_neurons = 10 if_curr_dual_exp = IFCurrDualExp( n_neurons, 1000, 1.0, **cell_params_lif) self.assertEqual(if_curr_dual_exp.model_name, "IF_curr_dual_exp") self.assertEqual(len(if_curr_dual_exp.get_parameters()), 10) self.assertEqual(if_curr_dual_exp._v_thresh, cell_params_lif['v_thresh']) self.assertEqual(if_curr_dual_exp._v_reset, cell_params_lif['v_reset']) self.assertEqual(if_curr_dual_exp._v_rest, cell_params_lif['v_rest']) self.assertEqual(if_curr_dual_exp._tau_m, cell_params_lif['tau_m']) self.assertEqual(if_curr_dual_exp._tau_refrac,
def test_from_file_connector(self): # create files as needed for tests # From_File_Generator.create_files() pop_size = 32 min_weight = 0.1 max_weight = 5.0 rng_weights = p.NumpyRNG(seed=369121518) weight_dependence_n = \ p.RandomDistribution( distribution='uniform', parameters=[1.0 + min_weight, 1.0 + max_weight], rng=rng_weights) weight_dependence_e = \ p.RandomDistribution(distribution='uniform', parameters=[min_weight, max_weight], rng=rng_weights) file_num_i_p2 = 2 file_num_p1_p2 = 2 runtime = 10000.0 stim_start = 0.0 stim_rate = 10 pops_to_observe = ['mapped_pop_1', 'mapped_pop_2'] # Simulation Setup p.setup(timestep=1.0, min_delay=1.0, max_delay=11.0) # Neural Parameters tau_m = 24.0 # (ms) cm = 1 v_rest = -65.0 # (mV) v_thresh = -45.0 # (mV) v_reset = -65.0 # (mV) t_refrac = 3.0 # (ms) (clamped at v_reset) tau_syn_exc = 3.0 tau_syn_inh = tau_syn_exc * 3 # cell_params will be passed to the constructor of the Population Object cell_params = {'tau_m': tau_m, 'cm': cm, 'v_init': v_reset, 'v_rest': v_rest, 'v_reset': v_reset, 'v_thresh': v_thresh, 'tau_syn_E': tau_syn_exc, 'tau_syn_I': tau_syn_inh, 'tau_refrac': t_refrac, 'i_offset': 0} observed_pop_list = [] inputs = p.Population(pop_size, p.SpikeSourcePoisson, {'duration': runtime, 'start': stim_start, 'rate': stim_rate}, label="inputs") if 'inputs' in pops_to_observe: inputs.record() observed_pop_list.append(inputs) mapped_pop_1 = p.Population(pop_size, p.IF_curr_exp, cell_params, label="mapped_pop_1") if 'mapped_pop_1' in pops_to_observe: mapped_pop_1.record() observed_pop_list.append(mapped_pop_1) pop_inhibit = p.Population(pop_size, p.IF_curr_exp, cell_params, label="pop_inhibit") if 'pop_inhibit' in pops_to_observe: pop_inhibit.record() observed_pop_list.append(pop_inhibit) mapped_pop_2 = p.Population(pop_size, p.IF_curr_exp, cell_params, label="mapped_pop_2") if 'mapped_pop_2' in pops_to_observe: mapped_pop_2.record() observed_pop_list.append(mapped_pop_2) p.Projection(inputs, mapped_pop_1, p.OneToOneConnector(weights=weight_dependence_n, delays=1.0), target='excitatory') p.Projection(mapped_pop_1, pop_inhibit, p.OneToOneConnector( weights=weight_dependence_e, delays=1.0), target='excitatory') p.Projection(pop_inhibit, mapped_pop_2, p.FromFileConnector(conn_file="List_I_p2_form_%d.txt" % file_num_i_p2), target='inhibitory') p.Projection(mapped_pop_1, mapped_pop_2, p.FromFileConnector(conn_file="List_I_p2_form_%d.txt" % file_num_p1_p2), target='excitatory') # From_File_Generator.remove_files() p.run(runtime) for pop in observed_pop_list: data = numpy.asarray(pop.getSpikes()) current_file_path = os.path.dirname(os.path.abspath(__file__)) current_pop_file_path = os.path.join(current_file_path, "{}.data".format(pop.label)) # pop.printSpikes(current_pop_file_path) pre_recorded_data = p.utility_calls.read_spikes_from_file( current_pop_file_path, 0, pop_size, 0, runtime) for spike_element, read_element in zip(data, pre_recorded_data): self.assertEqual(round(spike_element[0], 1), round(read_element[0], 1)) self.assertEqual(round(spike_element[1], 1), round(read_element[1], 1))
threads = 1 rngseed = 98766987 parallel_safe = True ts = 0.1 # simulation timestep in ms simulation_time = 2000 # ms n_input_neurons = 4 n_readout_neurons = 2 # n_reservoir_neurons = 59 exc_rate = 0.8 # 80% of reservoir neurons are excitatory n_reservoir_exc = int(np.ceil(n_reservoir_neurons * exc_rate)) n_reservoir_inh = n_reservoir_neurons - n_reservoir_exc pynn.setup(timestep=ts, min_delay=ts, max_delay=2.0 * ts) pynn.set_number_of_neurons_per_core('IF_curr_exp', 100) # this will set 100 neurons per core #====================================================== #=== #=== Define Neural Populations #=== #====================================================== ############# Reservoir ################# # set up the reservoir population celltype = pynn.IZK_cond_exp() cell_params = {}
def test_get_spikes(self): """ test for get spikes :return: """ p.setup(timestep=1, min_delay=1.0, max_delay=14.40) 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() weight_to_spike = 2.0 delay = 1.7 loop_connections = list() for i in range(0, n_neurons): single_connection = (i, ((i + 1) % n_neurons), weight_to_spike, delay) loop_connections.append(single_connection) injection_connection = [(0, 0, weight_to_spike, 1)] 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[0], populations[0], p.FromListConnector(loop_connections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injection_connection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(500) spikes = populations[0].getSpikes(compatible_output=True) pre_recorded_spikes = [ [0, 3.5], [1, 6.7], [2, 9.9], [3, 13.1], [4, 16.3], [5, 19.5], [6, 22.7], [7, 25.9], [8, 29.1], [9, 32.3], [10, 35.5], [11, 38.7], [12, 41.9], [13, 45.1], [14, 48.3], [15, 51.5], [16, 54.7], [17, 57.9], [18, 61.1], [19, 64.3], [20, 67.5], [21, 70.7], [22, 73.9], [23, 77.1], [24, 80.3], [25, 83.5], [26, 86.7], [27, 89.9], [28, 93.1], [29, 96.3], [30, 99.5], [31, 102.7], [32, 105.9], [33, 109.1], [34, 112.3], [35, 115.5], [36, 118.7], [37, 121.9], [38, 125.1], [39, 128.3], [40, 131.5], [41, 134.7], [42, 137.9], [43, 141.1], [44, 144.3], [45, 147.5], [46, 150.7], [47, 153.9], [48, 157.1], [49, 160.3], [50, 163.5], [51, 166.7], [52, 169.9], [53, 173.1], [54, 176.3], [55, 179.5], [56, 182.7], [57, 185.9], [58, 189.1], [59, 192.3], [60, 195.5]] p.end() for spike_element, read_element in zip(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))
def test_something(self): #!/usr/bin/python import pylab import spynnaker.pyNN as p p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) nNeurons = 200 # number of neurons in each population p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons / 2) cell_params_lif = {'cm' : 0.25, # nF '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 = 17 loop_connections = list() for i in range(0, nNeurons): single_connection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) loop_connections.append(single_connection) injection_connection = [(0, 0, weight_to_spike, 1)] spike_array = {'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, spike_array, label='inputSpikes_1')) projections.append( p.Projection(populations[0], populations[0], p.FromListConnector(loop_connections))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injection_connection))) populations[0].record_v() #populations[0].record_gsyn() #populations[0].record(visualiser_mode=p.VISUALISER_MODES.RASTER) p.run(5000) v = None gsyn = None spikes = None v = populations[0].get_v(compatible_output=True) #assert(v == ) #gsyn = populations[0].get_gsyn(compatible_output=True) #spikes = populations[0].getSpikes(compatible_output=True) if spikes is not None: print spikes pylab.figure() pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes') pylab.show() else: print "No spikes received" # Make some graphs if v is not None: ticks = len(v) / nNeurons pylab.figure() pylab.xlabel('Time/ms') pylab.ylabel('v') pylab.title('v') for pos in range(0, nNeurons, 20): v_for_neuron = v[pos * ticks : (pos + 1) * ticks] pylab.plot([i[1] for i in v_for_neuron], [i[2] for i in v_for_neuron]) pylab.show() if gsyn is not None: ticks = len(gsyn) / nNeurons pylab.figure() pylab.xlabel('Time/ms') pylab.ylabel('gsyn') pylab.title('gsyn') for pos in range(0, nNeurons, 20): gsyn_for_neuron = gsyn[pos * ticks : (pos + 1) * ticks] pylab.plot([i[1] for i in gsyn_for_neuron], [i[2] for i in gsyn_for_neuron]) pylab.show() p.end(stop_on_board=True)
import spinnman.messages.eieio.eieio_type as eieio_type import numpy import pylab # host_IP = '192.169.110.2' # when Spinn-3 is connected # host_IP = '192.168.1.2' # when Spinn-5 is connected # Base code from: # http://spinnakermanchester.github.io/2015.005.Arbitrary/workshop_material/ simulation_timestep = 0.2 sim.setup(timestep=simulation_timestep, min_delay=simulation_timestep, max_delay=simulation_timestep * 144) # Generate the connections matrix inside the Liquid (Liquid->Liquid) - according to Maass2002 # print "Liquid->Liquid connections..." Number_of_neurons_lsm = numpy.load("Number_of_neurons_lsm.npy") # # These are the cell (neuron) parameters according to Maass 2002 # cell_params_lsm = { 'cm': 30, # Capacitance of the membrane # =>>>> MAASS PAPER DOESN'T MENTION THIS PARAMETER DIRECTLY # but the paper mentions a INPUT RESISTANCE OF 1MEGA Ohms and tau_m=RC=30ms, so cm=30nF
""" Synfirechain-like example """ import spynnaker.pyNN as p import pylab p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) nNeurons = 200 # number of neurons in each population p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons / 2) runtime = 1000 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 = 17 loopConnections = list() for i in range(0, nNeurons):
def __init__(self): # initial call to set up the front end (pynn requirement) Frontend.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) use_c_visualiser = True use_spike_injector = True # neurons per population and the length of runtime in ms for the # simulation, as well as the expected weight each spike will contain self.n_neurons = 100 # set up gui p = None if use_spike_injector: from multiprocessing import Process from multiprocessing import Event ready = Event() p = Process(target=GUI, args=[self.n_neurons, ready]) p.start() ready.wait() # different runtimes for demostration purposes run_time = None if not use_c_visualiser and not use_spike_injector: run_time = 1000 elif use_c_visualiser and not use_spike_injector: run_time = 10000 elif use_c_visualiser and use_spike_injector: run_time = 100000 elif not use_c_visualiser and use_spike_injector: run_time = 10000 weight_to_spike = 2.0 # neural parameters of the IF_curr model used to respond to injected # spikes. # (cell params for a synfire chain) 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 } ################################## # Parameters for the injector population. This is the minimal set of # parameters required, which is for a set of spikes where the key is # not important. Note that a virtual key *will* be assigned to the # population, and that spikes sent which do not match this virtual key # will be dropped; however, if spikes are sent using 16-bit keys, they # will automatically be made to match the virtual key. The virtual # key assigned can be obtained from the database. ################################## cell_params_spike_injector = { # The port on which the spiNNaker machine should listen for # packets. Packets to be injected should be sent to this port on # the spiNNaker machine 'port': 12345 } ################################## # Parameters for the injector population. Note that each injector # needs to be given a different port. The virtual key is assigned # here, rather than being allocated later. As with the above, spikes # injected need to match this key, and this will be done automatically # with 16-bit keys. ################################## cell_params_spike_injector_with_key = { # The port on which the spiNNaker machine should listen for # packets. Packets to be injected should be sent to this port on # the spiNNaker machine 'port': 12346, # This is the base key to be used for the injection, which is used # to allow the keys to be routed around the spiNNaker machine. # This assignment means that 32-bit keys must have the high-order # 16-bit set to 0x7; This will automatically be prepended to # 16-bit keys. 'virtual_key': 0x70000 } # create synfire populations (if cur exp) pop_forward = Frontend.Population( self.n_neurons, Frontend.IF_curr_exp, cell_params_lif, label='pop_forward') pop_backward = Frontend.Population( self.n_neurons, Frontend.IF_curr_exp, cell_params_lif, label='pop_backward') # Create injection populations injector_forward = None injector_backward = None if use_spike_injector: injector_forward = Frontend.Population( self.n_neurons, ExternalDevices.SpikeInjector, cell_params_spike_injector_with_key, label='spike_injector_forward') injector_backward = Frontend.Population( self.n_neurons, ExternalDevices.SpikeInjector, cell_params_spike_injector, label='spike_injector_backward') else: spike_times = [] for _ in range(0, self.n_neurons): spike_times.append([]) spike_times[0] = [0] spike_times[20] = [(run_time / 100) * 20] spike_times[40] = [(run_time / 100) * 40] spike_times[60] = [(run_time / 100) * 60] spike_times[80] = [(run_time / 100) * 80] cell_params_forward = {'spike_times': spike_times} spike_times_backwards = [] for _ in range(0, self.n_neurons): spike_times_backwards.append([]) spike_times_backwards[0] = [(run_time / 100) * 80] spike_times_backwards[20] = [(run_time / 100) * 60] spike_times_backwards[40] = [(run_time / 100) * 40] spike_times_backwards[60] = [(run_time / 100) * 20] spike_times_backwards[80] = [0] cell_params_backward = {'spike_times': spike_times_backwards} injector_forward = Frontend.Population( self.n_neurons, Frontend.SpikeSourceArray, cell_params_forward, label='spike_injector_forward') injector_backward = Frontend.Population( self.n_neurons, Frontend.SpikeSourceArray, cell_params_backward, label='spike_injector_backward') # Create a connection from the injector into the populations Frontend.Projection( injector_forward, pop_forward, Frontend.OneToOneConnector(weights=weight_to_spike)) Frontend.Projection( injector_backward, pop_backward, Frontend.OneToOneConnector(weights=weight_to_spike)) # Synfire chain connections where each neuron is connected to its next # neuron # NOTE: there is no recurrent connection so that each chain stops once # it reaches the end loop_forward = list() loop_backward = list() for i in range(0, self.n_neurons - 1): loop_forward.append((i, (i + 1) % self.n_neurons, weight_to_spike, 3)) loop_backward.append(((i + 1) % self.n_neurons, i, weight_to_spike, 3)) Frontend.Projection(pop_forward, pop_forward, Frontend.FromListConnector(loop_forward)) Frontend.Projection(pop_backward, pop_backward, Frontend.FromListConnector(loop_backward)) # record spikes from the synfire chains so that we can read off valid # results in a safe way afterwards, and verify the behavior pop_forward.record() pop_backward.record() # Activate the sending of live spikes ExternalDevices.activate_live_output_for( pop_forward, database_notify_host="localhost", database_notify_port_num=19996) ExternalDevices.activate_live_output_for( pop_backward, database_notify_host="localhost", database_notify_port_num=19996) if not use_c_visualiser: # if not using the c visualiser, then a new spynnaker live spikes # connection is created to define that there are python code which # receives the outputted spikes. live_spikes_connection_receive = SpynnakerLiveSpikesConnection( receive_labels=["pop_forward", "pop_backward"], local_port=19999, send_labels=None) # Set up callbacks to occur when spikes are received live_spikes_connection_receive.add_receive_callback( "pop_forward", receive_spikes) live_spikes_connection_receive.add_receive_callback( "pop_backward", receive_spikes) # Run the simulation on spiNNaker Frontend.run(run_time) # Retrieve spikes from the synfire chain population spikes_forward = pop_forward.getSpikes() spikes_backward = pop_backward.getSpikes() # If there are spikes, plot using matplotlib if len(spikes_forward) != 0 or len(spikes_backward) != 0: pylab.figure() if len(spikes_forward) != 0: pylab.plot([i[1] for i in spikes_forward], [i[0] for i in spikes_forward], "b.") if len(spikes_backward) != 0: pylab.plot([i[1] for i in spikes_backward], [i[0] for i in spikes_backward], "r.") pylab.ylabel('neuron id') pylab.xlabel('Time/ms') pylab.title('spikes') pylab.show() else: print "No spikes received" # Clear data structures on spiNNaker to leave the machine in a clean # state for future executions Frontend.end() if use_spike_injector: p.join()
def test_print_spikes(self): machine_time_step = 0.1 p.setup(timestep=machine_time_step, min_delay=1.0, max_delay=14.40) 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() weight_to_spike = 2.0 delay = 1.7 loop_connections = list() for i in range(0, n_neurons): single_connection = (i, ((i + 1) % n_neurons), weight_to_spike, delay) loop_connections.append(single_connection) injection_connection = [(0, 0, weight_to_spike, 1)] 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[0], populations[0], p.FromListConnector(loop_connections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injection_connection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(500) spikes = populations[0].getSpikes(compatible_output=True) current_file_path = os.path.dirname(os.path.abspath(__file__)) current_file_path = os.path.join(current_file_path, "spikes.data") spike_file = populations[0].printSpikes(current_file_path) spike_reader = p.utility_calls.read_spikes_from_file( current_file_path, min_atom=0, max_atom=n_neurons, min_time=0, max_time=500) read_in_spikes = spike_reader.spike_times p.end() os.remove(current_file_path) for spike_element, read_element in zip(spikes, read_in_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))
import numpy import pylab from pprint import pprint delay = 1.0 sim_length = 100 num_neurons = 100 spike_weight = 2.0 delay = 17 p.setup( timestep=1.0, min_delay=1.0, max_delay=100.0, debug=True ) cell_params = {'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 } cell_params_spike_injector_with_prefix = {
# imports of both spynnaker and external device plugin. import spynnaker.pyNN as Frontend import spynnaker_external_devices_plugin.pyNN as ExternalDevices # plotter in python import pylab import time import random from threading import Condition # boolean allowing users to use python or c vis using_c_vis = False # initial call to set up the front end (pynn requirement) Frontend.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) # neurons per population and the length of runtime in ms for the simulation, # as well as the expected weight each spike will contain n_neurons = 100 run_time = 8000 weight_to_spike = 2.0 # neural parameters of the ifcur model used to respond to injected spikes. # (cell params for a synfire chain) 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,
def test_script(self): """ test that tests the printing of v from a pre determined recording :return: """ p.setup(timestep=0.1, min_delay=1.0, max_delay=14.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 spikes = read_spikefile('test.spikes', n_neurons) print spikes 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(100) spikes = populations[1].getSpikes(compatible_output=True) if spikes is not None: print spikes pylab.figure() pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes') pylab.show() else: print "No spikes received" p.end()
# Set the run time of the execution run_time = 3300 # Set the time step of the simulation in milliseconds time_step = 1.0 # Set the number of neurons to simulate n_fibers = 100 # Set the i_offset current i_offset = 1.0 # Set the weight of input spikes weight = 1.0 p.setup(time_step) # spindle population spindle_pop = p.Population(n_fibers * 2, MuscleSpindle, { "primary": [1] * n_fibers + [0] * n_fibers, "v_thresh": 100.0, "receive_port": 12345 }, label="spindle_pop") spindle_pop.record() # dynamic fusimotor drive gamma_dyn = p.Population(1, p.SpikeSourcePoisson, {'rate': 70.0}) p.Projection(gamma_dyn,
model = cer.IFCurrExpSupervision cell_params = { '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 } # SpiNNaker setup ts = 0.5 # does not work at 0.4, 0.6, 0.8, why?? sim.setup(timestep=ts, min_delay=ts, max_delay=15 * ts) sim_time = 2000. pre_stim = [] spike_times = [] for t in pylab.arange(0, teaching_time, 2.): print t spike_times.append([t, sim_time - ts]) print spike_times, len(spike_times) pre_stim = sim.Population(len(spike_times), sim.SpikeSourceArray, {'spike_times': spike_times}) teaching_stim = sim.Population(1, sim.SpikeSourceArray, {'spike_times': [teaching_time]})
""" Synfirechain-like example """ #!/usr/bin/python import spynnaker.pyNN as p #import pyNN.nest as p import numpy, pylab p.setup(timestep=1, min_delay=1, max_delay=15) nNeurons = 1 # number of neurons in each population nSources = 1 # Number of Poisson sources neuron_parameters = {'cm' : 0.25, # nF 'i_offset' : 2, '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' : -50.0} populations = list() projections = list() poisson_params = {'rate': 100, 'start':0, 'duration' : 100000000} poisson_params2 = {'rate': 10, 'start':0, 'duration' : 100000000} populations.append(p.Population(nNeurons, p.IF_curr_exp, neuron_parameters, label='pop_1')) populations.append(p.Population(nNeurons, p.IF_curr_exp, neuron_parameters, label='pop_2')) populations[1].set_constraint(p.PlacerChipAndCoreConstraint(x=1,y=0))#{"x": 1, "y": 0})
# imports of both spynnaker and external device plugin. import spynnaker.pyNN as Frontend import spynnaker_external_devices_plugin.pyNN as ExternalDevices from spynnaker_external_devices_plugin.pyNN.connections.spynnaker_live_spikes_connection import SpynnakerLiveSpikesConnection from threading import Thread import time # plotter in python import pylab # initial call to set up the front end (pynn requirement) Frontend.setup(timestep=0.2, min_delay=0.2, max_delay=2.0) # neurons per population and the length of runtime in ms for the simulation, # as well as the expected weight each spike will contain # n_neurons = 100 run_time = 3000 # weight_to_spike = 2.0 # neural parameters of the ifcur model used to respond to injected spikes. # (cell params for a synfire chain) cell_params_inh = {'tau_m': 2.07, 'tau_refrac': 2.0,'tau_syn_E': 2.0, 'tau_syn_I': 2.0, 'v_reset': -84.0} cell_params_col = {'tau_m': 2.07, 'tau_refrac': 2.0,'tau_syn_E': 2.0, 'tau_syn_I': 2.0, 'v_reset': -90.0} # create synfire populations (if cur exp) collector = Frontend.Population(1, Frontend.IF_curr_exp, cell_params_col, label='collector') inh_left = Frontend.Population(1, Frontend.IF_curr_exp, cell_params_inh, label='inh_left') inh_right = Frontend.Population(1, Frontend.IF_curr_exp, cell_params_inh, label='inh_right') # Create injection populations ret_left = Frontend.Population(1, ExternalDevices.SpikeInjector,{'port':12345}, label='ret_left') # rets = [] # for x in range(0, 13): # rets.append(Frontend.Population(1, ExternalDevices.SpikeInjector,{'port':13400+x,}, label='ret_left_'.format(x))) ret_right = Frontend.Population(1, ExternalDevices.SpikeInjector,{'port':12346}, label='ret_right')
import spynnaker.pyNN as sim sim.setup(timestep=1.0, min_delay=1.0, max_delay=1.0) simtime = 1000 pg_pop1 = sim.Population(2, sim.SpikeSourcePoisson, {'rate': 10.0, 'start':0, 'duration':simtime}, label="pg_pop1") pg_pop2 = sim.Population(2, sim.SpikeSourcePoisson, {'rate': 10.0, 'start':0, 'duration':simtime}, label="pg_pop2") pg_pop1.record() pg_pop2.record() sim.run(simtime) spikes1 = pg_pop1.getSpikes(compatible_output=True) spikes2 = pg_pop2.getSpikes(compatible_output=True) print spikes1 print spikes2 sim.end()
def run_test(w_list, cell_para, spike_source_data): #Du.set_trace() pop_list = [] p.setup(timestep=1.0, min_delay=1.0, max_delay=3.0) #input poisson layer input_size = w_list[0].shape[0] #print w_list[0].shape[0] #print w_list[1].shape[0] list = [] for j in range(input_size): list.append(spike_source_data[j]) pop_in = p.Population(input_size, p.SpikeSourceArray, {'spike_times': list}) pop_list.append(pop_in) #for j in range(input_size): #pop_in[j].spike_times = spike_source_data[j] #pop_in = p.Population(input_size, p.SpikeSourceArray, {'spike_times' : []}) #for j in range(input_size): # pop_in[j].spike_times = spike_source_data[j] #pop_list.append(pop_in) #count =0 #print w_list[0].shape[0] for w in w_list: input_size = w.shape[0] #count = count+1 #print count output_size = w.shape[1] #pos_w = np.copy(w) #pos_w[pos_w < 0] = 0 #neg_w = np.copy(w) #neg_w[neg_w > 0] = 0 conn_list_exci = [] conn_list_inhi = [] #k_size=in_size-out_size+1 for x_ind in range(input_size): for y_ind in range(output_size): weights = w[x_ind][y_ind] #for i in range(w.shape[1]): if weights > 0: conn_list_exci.append((x_ind, y_ind, weights, 1.)) elif weights < 0: conn_list_inhi.append((x_ind, y_ind, weights, 1.)) #print output_size pop_out = p.Population(output_size, p.IF_curr_exp, cell_para) if len(conn_list_exci) > 0: p.Projection(pop_in, pop_out, p.FromListConnector(conn_list_exci), target='excitatory') if len(conn_list_inhi) > 0: p.Projection(pop_in, pop_out, p.FromListConnector(conn_list_inhi), target='inhibitory') #p.Projection(pop_in, pop_out, p.AllToAllConnector(weights = pos_w), target='excitatory') #p.Projection(pop_in, pop_out, p.AllToAllConnector(weights = neg_w), target='inhibitory') pop_list.append(pop_out) pop_in = pop_out pop_out.record() run_time = np.ceil(np.max(spike_source_data)[0] / 1000.) * 1000 #print run_time p.run(run_time) spikes = pop_out.getSpikes(compatible_output=True) return spikes
# imports of both spynnaker and external device plugin. import spynnaker.pyNN as Frontend import spynnaker_external_devices_plugin.pyNN as ExternalDevices from spynnaker_external_devices_plugin.pyNN.connections\ .spynnaker_live_spikes_connection import SpynnakerLiveSpikesConnection # plotter in python import pylab # initial call to set up the front end (pynn requirement) Frontend.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) # neurons per population and the length of runtime in ms for the simulation, # as well as the expected weight each spike will contain n_neurons = 100 run_time = 8000 weight_to_spike = 2.0 # neural parameters of the ifcur model used to respond to injected spikes. # (cell params for a synfire chain) 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} # create synfire populations (if cur exp) pop_forward = Frontend.Population(n_neurons, Frontend.IF_curr_exp, cell_params_lif, label='pop_forward') # Create injection populations injector_forward = Frontend.Population( n_neurons, ExternalDevices.SpikeInjector, {'port':12365}, label='spike_injector_forward') # Create a connection from the injector into the populations Frontend.Projection(injector_forward, pop_forward, Frontend.OneToOneConnector(weights=weight_to_spike)) # Synfire chain connections where each neuron is connected to its next neuron # NOTE: there is no recurrent connection so that each chain stops once it
import spynnaker.pyNN as FrontEnd import spynnaker_external_devices_plugin.pyNN as ExternalDevices import pylab FrontEnd.setup(timestep=1.0) nNeurons = 100 run_time = 10000 cell_params_lif = { "cm": 0.25, # nF "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, } cell_params_spike_injector_new = {"virtual_key": 0x70800, "port": 12345} populations = list() projections = list() weight_to_spike = 2.0 populations.append(FrontEnd.Population(nNeurons, FrontEnd.IF_curr_exp, cell_params_lif, label="pop_1")) populations.append(
""" Synfirechain-like example """ #!/usr/bin/python import spynnaker.pyNN as p #import pyNN.nest as p import numpy, pylab p.setup(timestep=1, min_delay=1, max_delay=15) nNeurons = 1 # number of neurons in each population nSources = 1 # Number of Poisson sources neuron_parameters = { 'cm': 0.25, # nF 'i_offset': 2, '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': -50.0 } populations = list() projections = list() poisson_params = {'rate': 100, 'start': 0, 'duration': 100000000} poisson_params2 = {'rate': 10, 'start': 0, 'duration': 100000000} populations.append(
$ python IF_cond_exp.py <simulator> where <simulator> is 'neuron', 'nest', etc Andrew Davison, UNIC, CNRS May 2006 $Id: IF_cond_exp.py 917 2011-01-31 15:23:34Z apdavison $ """ from pyNN.utility import get_script_args from pyNN.errors import RecordingError import spynnaker.pyNN as p p.setup(timestep=1.0, min_delay=1.0, max_delay=10.0, db_name='if_cond.sqlite') cell_params = { 'i_offset': .1, 'tau_refrac': 3.0, 'v_rest': -65.0, 'v_thresh': -51.0, 'tau_syn_E': 2.0, 'tau_syn_I': 5.0, 'v_reset': -70.0 } ifcell = p.Population(1, p.IF_curr_exp, cell_params, label='IF_curr_exp') spike_sourceE = p.Population( 1,
def test_get_voltage(self): """ test that tests the getting of v from a pre determined recording :return: """ p.setup(timestep=0.1, min_delay=1.0, max_delay=14.40) n_neurons = 200 # number of neurons in each population runtime = 500 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() weight_to_spike = 2.0 delay = 1.7 loop_connections = list() for i in range(0, n_neurons): single_connection = (i, ((i + 1) % n_neurons), weight_to_spike, delay) loop_connections.append(single_connection) injection_connection = [(0, 0, weight_to_spike, 1)] 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[0], populations[0], p.FromListConnector(loop_connections))) projections.append(p.Projection(populations[1], populations[0], p.FromListConnector(injection_connection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(runtime) v = populations[0].get_v(compatible_output=True) current_file_path = os.path.dirname(os.path.abspath(__file__)) current_file_path = os.path.join(current_file_path, "v.data") pre_recorded_data = p.utility_calls.read_in_data_from_file( current_file_path, 0, n_neurons, 0, runtime) p.end() for spike_element, read_element in zip(v, pre_recorded_data): self.assertEqual(round(spike_element[0], 1), round(read_element[0], 1)) self.assertEqual(round(spike_element[1], 1), round(read_element[1], 1)) self.assertEqual(round(spike_element[2], 1), round(read_element[2], 1))
def test_inhibitory_connector_memory(self): p.setup(timestep=0.1, min_delay=1, max_delay=10.0) weight_to_spike = 10 delay = 1 cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 1.0, 'tau_syn_E': 5.0, 'tau_syn_I': 8.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } spike_array = {'spike_times': [0]} mem_access = {'spike_times': [10]} p_initial_spike = p.Population(1, p.SpikeSourceArray, spike_array, label="Initial spike pop") p_mem = p.Population(1, p.IF_curr_exp, cell_params_lif, label="Memory") p_out = p.Population(1, p.IF_curr_exp, cell_params_lif, label="Output") p_bridge = p.Population(1, p.IF_curr_exp, cell_params_lif, label="Bridge") p_inhibitor = p.Population(1, p.IF_curr_exp, cell_params_lif, label="Inhibitor") p_access = p.Population(1, p.SpikeSourceArray, mem_access, label="Access memory spike pop") p_out.record() p_mem.record() p_inhibitor.record() p_initial_spike.record() p_access.record() pr_initial_spike1 = p.Projection( p_initial_spike, p_mem, p.OneToOneConnector(weight_to_spike, delay)) pr_initial_spike2 = p.Projection( p_initial_spike, p_inhibitor, p.OneToOneConnector(weight_to_spike, delay)) pr_mem_access = p.Projection(p_access, p_inhibitor, p.OneToOneConnector( weight_to_spike, delay), target='inhibitory') pr_inhibitor_self = p.Projection( p_inhibitor, p_inhibitor, p.OneToOneConnector(weight_to_spike, delay)) pr_inhibitor_bridge = p.Projection(p_inhibitor, p_bridge, p.OneToOneConnector( weight_to_spike, delay), target='inhibitory') pr_mem_self = p.Projection(p_mem, p_mem, p.OneToOneConnector(weight_to_spike, delay)) pr_mem_bridge = p.Projection( p_mem, p_bridge, p.OneToOneConnector(weight_to_spike, delay)) pr_bridge_output = p.Projection( p_bridge, p_out, p.OneToOneConnector(weight_to_spike, delay)) pr_bridge_inhibitor = p.Projection( p_bridge, p_inhibitor, p.OneToOneConnector(weight_to_spike, delay)) p_mem.record_v() p_mem.record_gsyn() p_mem.record() p.run(30) v = None gsyn = None spikes = None v = p_mem.get_v(compatible_output=True) gsyn = p_mem.get_gsyn(compatible_output=True) spikes = p_mem.getSpikes(compatible_output=True) if spikes != None: print spikes pylab.figure() pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], ".") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes') pylab.show() else: print "No spikes received" # Make some graphs ticks = len(v) / 1 if v != None: pylab.figure() pylab.xlabel('Time/ms') pylab.ylabel('v') pylab.title('v') for pos in range(0, 1, 20): v_for_neuron = v[pos * ticks:(pos + 1) * ticks] pylab.plot([i[1] for i in v_for_neuron], [i[2] for i in v_for_neuron]) pylab.show() if gsyn != None: pylab.figure() pylab.xlabel('Time/ms') pylab.ylabel('gsyn') pylab.title('gsyn') for pos in range(0, 1, 20): gsyn_for_neuron = gsyn[pos * ticks:(pos + 1) * ticks] pylab.plot([i[1] for i in gsyn_for_neuron], [i[2] for i in gsyn_for_neuron]) pylab.show() p.end()
""" Synfirechain-like example """ #!/usr/bin/python import spynnaker.pyNN as p import numpy, pylab p.setup(timestep=0.1, min_delay=1.0, max_delay=7.5) p.set_number_of_neurons_per_core("IF_curr_exp", 100) nNeurons = 3 # number of neurons in each population input_cell_params = { 'cm': 0.25, # nF 'i_offset': 5.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 } ''' cell_params_lif = {'cm' : 0.25, # nF '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,
def test_get_spikes(self): """ test for get spikes :return: """ p.setup(timestep=0.1, min_delay=1.0, max_delay=14.40) 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() weight_to_spike = 2.0 delay = 1.7 loop_connections = list() for i in range(0, n_neurons): single_connection = (i, ((i + 1) % n_neurons), weight_to_spike, delay) loop_connections.append(single_connection) injection_connection = [(0, 0, weight_to_spike, 1)] 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[0], populations[0], p.FromListConnector(loop_connections))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injection_connection))) populations[0].record_v() populations[0].record_gsyn() populations[0].record() p.run(500) spikes = populations[0].getSpikes(compatible_output=True) pre_recorded_spikes = [[0, 3.5], [1, 6.7], [2, 9.9], [3, 13.1], [4, 16.3], [5, 19.5], [6, 22.7], [7, 25.9], [8, 29.1], [9, 32.3], [10, 35.5], [11, 38.7], [12, 41.9], [13, 45.1], [14, 48.3], [15, 51.5], [16, 54.7], [17, 57.9], [18, 61.1], [19, 64.3], [20, 67.5], [21, 70.7], [22, 73.9], [23, 77.1], [24, 80.3], [25, 83.5], [26, 86.7], [27, 89.9], [28, 93.1], [29, 96.3], [30, 99.5], [31, 102.7], [32, 105.9], [33, 109.1], [34, 112.3], [35, 115.5], [36, 118.7], [37, 121.9], [38, 125.1], [39, 128.3], [40, 131.5], [41, 134.7], [42, 137.9], [43, 141.1], [44, 144.3], [45, 147.5], [46, 150.7], [47, 153.9], [48, 157.1], [49, 160.3], [50, 163.5], [51, 166.7], [52, 169.9], [53, 173.1], [54, 176.3], [55, 179.5], [56, 182.7], [57, 185.9], [58, 189.1], [59, 192.3], [60, 195.5]] p.end() for spike_element, read_element in zip(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))
""" Synfirechain-like example """ import spynnaker.pyNN as p import pylab p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) nNeurons = 200 # number of neurons in each population 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 = 17 loopConnections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay)
return build_list(connected_indices) def Plot_WeightDistribution(weight, bin_num, title): hist, bins = np.histogram(weight, bins=bin_num) center = (bins[:-1] + bins[1:]) / 2 width = (bins[1] - bins[0]) * 0.7 plt.bar(center, hist, align='center', width=width) plt.xlabel('Weight') plt.title(title) plt.show() #Plot_WeightDistribution(weights_import,200,'trained weight') sim.setup(timestep=1, min_delay=1, max_delay=144) synapses_to_spike = 1 delay = 2 prepop_size = 256 postpop_size = 40 animation_time = 200 episode = 200 order = np.array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]) test_order = np.array([0, 1, 2, 3]) simtime = len(test_order) * animation_time def concatenate_time(time, iter): temp_time = [] spike_time = [] for kk in range(0, iter):
def main(): minutes = 0 seconds = 30 milliseconds = 0 run_time = minutes*60*1000 + seconds*1000 + milliseconds weight_to_spike = 4. model = sim.IF_curr_exp cell_params = {'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 } # Available resolutions # 16, 32, 64, 128 mode = ExternalDvsEmulatorDevice.MODE_64 cam_res = int(mode) cam_fps = 90 frames_per_saccade = cam_fps/3 - 1 polarity = ExternalDvsEmulatorDevice.MERGED_POLARITY output_type = ExternalDvsEmulatorDevice.OUTPUT_TIME history_weight = 1.0 behaviour = VirtualCam.BEHAVE_ATTENTION vcam = VirtualCam("./mnist", behaviour=behaviour, fps=cam_fps, resolution=cam_res, frames_per_saccade=frames_per_saccade) cam_params = {'mode': mode, 'polarity': polarity, 'threshold': 12, 'adaptive_threshold': False, 'fps': cam_fps, 'inhibition': False, 'output_type': output_type, 'save_spikes': "./spikes_from_cam.pickle", 'history_weight': history_weight, #'device_id': 0, # for an OpenCV webcam device #'device_id': 'path/to/video/file', # to encode pre-recorded video 'device_id': vcam, } if polarity == ExternalDvsEmulatorDevice.MERGED_POLARITY: num_neurons = 2*(cam_res**2) else: num_neurons = cam_res**2 sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) target = sim.Population(num_neurons, model, cell_params) stimulation = sim.Population(num_neurons, DvsEmulatorDevice, cam_params, label="Webcam population") connector = sim.OneToOneConnector(weights=weight_to_spike) projection = sim.Projection(stimulation, target, connector) target.record() sim.run(run_time) spikes = target.getSpikes(compatible_output=True) sim.end() #stimulation._vertex.stop() print ("Raster plot of the spikes that Spinnaker echoed back") fig = pylab.figure() spike_times = [spike_time for (neuron_id, spike_time) in spikes] spike_ids = [neuron_id for (neuron_id, spike_time) in spikes] pylab.plot(spike_times, spike_ids, ".", markerfacecolor="None", markeredgecolor="Blue", markersize=3) pylab.show()
import spynnaker.pyNN as spynn import spynnaker_external_devices_plugin.pyNN as ExternalDevices import sys import pylab spynn.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) print sys.argv numArgumentsProvided = len(sys.argv) - 1 if numArgumentsProvided == 7: spikeInjectionPort1 = int(sys.argv[1]) spikeInjectionPopLabel1 = sys.argv[2] nNeurons1 = int(sys.argv[3]) spikeInjectionPort2 = int(sys.argv[4]) spikeInjectionPopLabel2 = sys.argv[5] nNeurons2 = int(sys.argv[6]) runTimeMs = int(sys.argv[7]) else: print 'usage: ', sys.argv[ 0], ' <spikeInjectionPort1> <spikeInjectionPopLabel1> <nNeurons1> <spikeInjectionPort2> <spikeInjectionPopLabel2> <nNeurons2> <runTimeMs>' sys.exit(0) #nNeurons = 784 # * 8; #MNIST 28 x 28 pixels , 8 neurons each #runTimeMs = 1000 cell_params_lif = { 'cm': 0.25, # nF 'i_offset': 0.0, 'tau_m': 20.0,
#!/usr/bin/env python import unittest from spynnaker.pyNN.exceptions import ConfigurationException import spynnaker.pyNN as pyNN from pprint import pprint as pp if pyNN._spinnaker is None: pyNN.setup(timestep=1, min_delay=1, max_delay=10.0) nNeurons = 10 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} spike_array = {'spike_times': [0]} class TestingFromListConnector(unittest.TestCase): def test_generate_synapse_list_simulated_all_to_all(self): number_of_neurons = 5 first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp, cell_params_lif, label="One pop") weight = 2 delay = 1 connection_list = list() for i in range(5): for j in range(5): connection_list.append((i, j, weight, delay))
# Population parameters model = sim.IF_curr_exp cell_params = { '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 } # SpiNNaker setup sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # Sweep times and frequencies projections = [] sim_time = 0 for t in delta_t: projections.append([]) for f in frequencies: # Neuron populations pre_pop = sim.Population(1, model, cell_params) post_pop = sim.Population(1, model, cell_params) # Stimulating populations pre_times = generate_fixed_frequency_test_data(f, start_time - 1, num_pairs + 1) post_times = generate_fixed_frequency_test_data(