def test_simple_spikes(self): sim.setup(timestep=1.0) pop = sim.Population(4, sim.IF_curr_exp(), label="a label") pop._get_spikes = mock_spikes pop._get_recorded_matrix = mock_v_all get_simulator().get_current_time = mock_time neo = pop.getSpikes() spikes = neo_convertor.convert_spikes(neo) assert numpy.array_equal(spikes, mock_spikes()) spiketrains = neo.segments[0].spiketrains assert 4 == len(spiketrains) # gather False has not effect testing that here neo = pop.get_data("spikes", gather=False) spikes = neo_convertor.convert_spikes(neo) assert numpy.array_equal(spikes, mock_spikes()) spiketrains = neo.segments[0].spiketrains assert 4 == len(spiketrains) neo = pop.get_v() v = neo.segments[0].filter(name='v')[0].magnitude (target, _, _) = mock_v_all("any") assert numpy.array_equal(v, target) neo = pop.get_gsyn() exc = neo.segments[0].filter(name='gsyn_exc')[0].magnitude assert numpy.array_equal(exc, target) inh = neo.segments[0].filter(name='gsyn_inh')[0].magnitude assert numpy.array_equal(inh, target) sim.end()
def a_run(self): v, spikes, v2, spikes2 = do_run(plot=False) # any checks go here spikes_test = neo_convertor.convert_spikes(spikes) spikes_test2 = neo_convertor.convert_spikes(spikes2) self.assertEqual(263, len(spikes_test)) self.assertEqual(263, len(spikes_test2))
def test_run(self): synfire_run.do_run(nNeurons, run_times=run_times, reset=reset, get_all=True) neos = synfire_run.get_output_pop_all_list() spikes_0_0 = neo_convertor.convert_spikes(neos[0], 0) spikes_1_1 = neo_convertor.convert_spikes(neos[1], 1) self.assertEquals(53, len(spikes_0_0)) self.assertEquals(27, len(spikes_1_1)) spike_checker.synfire_spike_checker(spikes_0_0, nNeurons) spike_checker.synfire_spike_checker(spikes_1_1, nNeurons) # v + gsyn_exc + gsyn_ihn = 3 (spikes not in analogsignalarrays if pynn8_syntax: self.assertEquals(3, len(neos[0].segments[0].analogsignalarrays)) self.assertEquals(3, len(neos[1].segments[1].analogsignalarrays)) else: self.assertEquals(3, len(neos[0].segments[0].analogsignals)) self.assertEquals(3, len(neos[1].segments[1].analogsignals)) neo_compare.compare_segments(neos[0].segments[0], neos[1].segments[0]) # neo compare does all the compares so just some safety come once v_0_0 = neo_convertor.convert_data(neos[0], "v", 0) v_1_1 = neo_convertor.convert_data(neos[1], "v", 1) self.assertEquals(nNeurons * run_times[0], len(v_0_0)) self.assertEquals(nNeurons * run_times[1], len(v_1_1)) gsyn_exc_0_0 = neo_convertor.convert_data(neos[0], "gsyn_exc", 0) gsyn_exc_1_1 = neo_convertor.convert_data(neos[1], "gsyn_exc", 1) self.assertEquals(nNeurons * run_times[0], len(gsyn_exc_0_0)) self.assertEquals(nNeurons * run_times[1], len(gsyn_exc_1_1)) gsyn_inh_0_0 = neo_convertor.convert_data(neos[0], "gsyn_inh", 0) gsyn_inh_1_1 = neo_convertor.convert_data(neos[1], "gsyn_inh", 1) self.assertEquals(nNeurons * run_times[0], len(gsyn_inh_0_0)) self.assertEquals(nNeurons * run_times[1], len(gsyn_inh_1_1))
def test_many(self): nNeurons = 100 # number of neurons in each population neo = do_run(nNeurons, timestep=1.0) spikes = neo_convertor.convert_spikes(neo) spikes = neo_convertor.convert_spikes(neo) self.assertEqual(nNeurons * len(SPIKE_TIMES), len(spikes)) for i in range(0, len(spikes), 2): self.assertEqual(i / 2, spikes[i][0]) self.assertEqual(11, spikes[i][1]) self.assertEqual(i / 2, spikes[i + 1][0]) self.assertEqual(22, spikes[i + 1][1])
def test_run(self): self.assert_not_spin_three() (esp, s, N_E) = script.do_run( Neurons, sim_time, record=True, seed=1) esp_numpy = neo_convertor.convert_spikes(esp) s_numpy = neo_convertor.convert_spikes(s) self.assertEqual(2400, N_E) # Range required, because random delays are used, and although these # are seeded, the order of generation is not consistent self.assertLessEqual(210, len(esp_numpy)) self.assertGreaterEqual(230, len(esp_numpy)) self.assertEqual(23888, len(s_numpy))
def do_run(nNeurons): p.setup(timestep=0.1, min_delay=1.0, max_delay=7.5) p.set_number_of_neurons_per_core(p.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 = 0.5 injection_delay = 2 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() synapse_type = p.StaticSynapse(weight=weight_to_spike, delay=injection_delay) projections.append( p.Projection(populations[0], populations[1], connector, synapse_type=synapse_type)) connector = p.AllToAllConnector() projections.append( p.Projection(populations[1], populations[2], connector, synapse_type=synapse_type)) populations[2].record("v") populations[2].record("spikes") p.run(100) neo = populations[2].get_data(["v", "spikes"]) v = neo_convertor.convert_data(neo, name="v") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, spikes)
def test_write(self): sim.setup(timestep=1.0) pop = sim.Population(4, sim.IF_curr_exp(), label="a label") pop._get_spikes = mock_spikes pop._get_recorded_matrix = mock_v_all get_simulator().get_current_time = mock_time # Note gather=False will be ignored just testing it can be pop.write_data("spikes.pkl", "spikes", gather=False) try: with open("spikes.pkl") as pkl: neo = pickle.load(pkl) spikes = neo_convertor.convert_spikes(neo) assert numpy.array_equal(spikes, mock_spikes()) except UnicodeDecodeError: raise SkipTest( "https://github.com/NeuralEnsemble/python-neo/issues/529") pop.printSpikes("spikes.pkl") try: with open("spikes.pkl") as pkl: neo = pickle.load(pkl) spikes = neo_convertor.convert_spikes(neo) assert numpy.array_equal(spikes, mock_spikes()) except UnicodeDecodeError: raise SkipTest( "https://github.com/NeuralEnsemble/python-neo/issues/529") (target, _, _) = mock_v_all("any") pop.print_v("v.pkl") with open("v.pkl") as pkl: neo = pickle.load(pkl) v = neo.segments[0].filter(name='v')[0].magnitude assert v.shape == target.shape assert numpy.array_equal(v, target) pop.print_gsyn("gsyn.pkl") with open("gsyn.pkl") as pkl: neo = pickle.load(pkl) exc = neo.segments[0].filter(name='gsyn_exc')[0].magnitude assert numpy.array_equal(exc, target) inh = neo.segments[0].filter(name='gsyn_inh')[0].magnitude assert numpy.array_equal(inh, target) sim.end()
def test_run(self): self.assert_not_spin_three() (esp, s, N_E) = script.do_run(Neurons, sim_time, record=True, seed=self._test_seed) esp_numpy = neo_convertor.convert_spikes(esp) s_numpy = neo_convertor.convert_spikes(s) self.assertEquals(2400, N_E) try: self.assertLess(200, len(esp_numpy)) self.assertGreater(300, len(esp_numpy)) self.assertLess(22000, len(s_numpy)) self.assertGreater(26000, len(s_numpy)) except Exception as ex: # Just in case the range failed raise SkipTest(ex)
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core(p.Izhikevich, 100) cell_params_izk = { 'a': 0.02, 'b': 0.2, 'c': -65, 'd': 8, 'v': -75, 'u': 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, p.Izhikevich, 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_exc") populations[0].record("spikes") p.run(500) neo = populations[0].get_data(["v", "spikes", "gsyn_exc"]) v = neo_convertor.convert_data(neo, name="v") gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, gsyn, spikes)
def do_run(seed=None): sim.setup(timestep=1.0, min_delay=1.0, max_delay=1.0) simtime = 1000 if seed is None: 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") else: pg_pop1 = sim.Population(2, sim.SpikeSourcePoisson(rate=10.0, start=0, duration=simtime, seed=seed), label="pg_pop1") pg_pop2 = sim.Population(2, sim.SpikeSourcePoisson(rate=10.0, start=0, duration=simtime, seed=seed + 1), label="pg_pop2") pg_pop1.record("spikes") pg_pop2.record("spikes") sim.run(simtime) neo = pg_pop1.get_data("spikes") spikes1 = neo_convertor.convert_spikes(neo) neo = pg_pop2.get_data("spikes") spikes2 = neo_convertor.convert_spikes(neo) sim.end() return (spikes1, spikes2)
def check_results(self, neo, expected_spikes): spikes = neo_convertor.convert_spikes(neo) v = neo_convertor.convert_data(neo, name="v") print(spikes) for i, spike in enumerate(expected_spikes): self.assertEqual(spikes[i][1], spike) self.assertEqual(spikes.shape, (len(spikes), 2)) for spike in expected_spikes: print(spike, v[spike][2], v[spike + 1][2]) self.assertTrue(v[spike][2] > v[spike + 1][2])
def test_slow(self): nNeurons = 1 # number of neurons in each population neo = do_run(nNeurons, timestep=10.0) spikes = neo_convertor.convert_spikes(neo) self.assertEqual(nNeurons * len(SPIKE_TIMES), len(spikes)) for i in range(0, len(spikes), 2): self.assertEqual(i / 2, spikes[i][0]) # Note spike times rounded up to next timestep self.assertEqual(20, spikes[i][1]) self.assertEqual(i / 2, spikes[i + 1][0]) self.assertEqual(30, spikes[i + 1][1])
def test_get_spikes_by_view(self): sim.setup(timestep=1.0) pop = sim.Population(4, sim.IF_curr_exp(), label="a label") pop._get_spikes = mock_spikes get_simulator().get_current_time = mock_time view = pop[1:3] view.record("spikes") neo = view.get_data("spikes", gather=False) spikes = neo_convertor.convert_spikes(neo) target = trim_spikes(mock_spikes(), [1, 2]) assert numpy.array_equal(spikes, target) spiketrains = neo.segments[0].spiketrains assert 2 == len(spiketrains) sim.end()
def test_get_spikes_view_missing(self): sim.setup(timestep=1.0) pop = sim.Population(4, sim.IF_curr_exp(), label="a label") pop._get_spikes = mock_spikes pop._get_recorded_matrix = mock_v_all get_simulator().get_current_time = mock_time view = pop[2:4] neo = view.get_data("spikes") spikes = neo_convertor.convert_spikes(neo) target = trim_spikes(mock_spikes(), [2]) assert numpy.array_equal(spikes, target) spiketrains = neo.segments[0].spiketrains assert 2 == len(spiketrains) assert 2 == len(spiketrains[0]) assert 2 == spiketrains[0].annotations['source_index'] assert 0 == len(spiketrains[1]) assert 3 == spiketrains[1].annotations['source_index'] sim.end()
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=8.0) cell_params_lif_in = { 'tau_m': 333.33, 'cm': 208.33, 'v': [0.0, 0.0146789550781, 0.029296875, 0.0438842773438, 0.0584106445312], 'v_rest': 0.1, 'v_reset': 0.0, 'v_thresh': 1.0, 'tau_syn_E': 1, 'tau_syn_I': 2, 'tau_refrac': 2.5, 'i_offset': 3.0 } pop1 = p.Population(nNeurons, p.IF_curr_exp, cell_params_lif_in, label='pop_0') pop1.record("v") pop1.record("gsyn_exc") pop1.record("spikes") p.run(100) neo = pop1.get_data(["v", "spikes", "gsyn_exc"]) v = neo_convertor.convert_data(neo, name="v") gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, gsyn, spikes)
def do_run(seed=None): random.seed(seed) # SpiNNaker setup sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0) # +-------------------------------------------------------------------+ # | General Parameters | # +-------------------------------------------------------------------+ # Population parameters model = sim.IF_curr_exp cell_params = { 'cm': 0.25, '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 } # Other simulation parameters e_rate = 200 in_rate = 350 n_stim_test = 5 n_stim_pairing = 10 dur_stim = 20 pop_size = 40 ISI = 150. start_test_pre_pairing = 200. start_pairing = 1500. start_test_post_pairing = 700. simtime = start_pairing + start_test_post_pairing + \ ISI*(n_stim_pairing + n_stim_test) + 550. # let's make it 5000 # Initialisations of the different types of populations IAddPre = [] IAddPost = [] # +-------------------------------------------------------------------+ # | Creation of neuron populations | # +-------------------------------------------------------------------+ # Neuron populations pre_pop = sim.Population(pop_size, model(**cell_params)) post_pop = sim.Population(pop_size, model(**cell_params)) # Test of the effect of activity of the pre_pop population on the post_pop # population prior to the "pairing" protocol : only pre_pop is stimulated for i in range(n_stim_test): IAddPre.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start_test_pre_pairing + ISI * (i), duration=dur_stim, seed=random.randint(0, 100000000)))) # Pairing protocol : pre_pop and post_pop are stimulated with a 10 ms # difference for i in range(n_stim_pairing): IAddPre.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start_pairing + ISI * (i), duration=dur_stim, seed=random.randint(0, 100000000)))) IAddPost.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start_pairing + ISI * (i) + 10., duration=dur_stim, seed=random.randint(0, 100000000)))) # Test post pairing : only pre_pop is stimulated # (and should trigger activity in Post) for i in range(n_stim_test): start = start_pairing + ISI * n_stim_pairing + \ start_test_post_pairing + ISI * i IAddPre.append( sim.Population( pop_size, sim.SpikeSourcePoisson(rate=in_rate, start=start, duration=dur_stim, seed=random.randint(0, 100000000)))) # Noise inputs INoisePre = sim.Population(pop_size, sim.SpikeSourcePoisson(rate=e_rate, start=0, duration=simtime, seed=random.randint( 0, 100000000)), label="expoisson") INoisePost = sim.Population(pop_size, sim.SpikeSourcePoisson(rate=e_rate, start=0, duration=simtime, seed=random.randint( 0, 100000000)), label="expoisson") # +-------------------------------------------------------------------+ # | Creation of connections | # +-------------------------------------------------------------------+ # Connection parameters JEE = 3. # Connection type between noise poisson generator and # excitatory populations ee_connector = sim.OneToOneConnector() # Noise projections sim.Projection(INoisePre, pre_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) sim.Projection(INoisePost, post_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) # Additional Inputs projections for i in range(len(IAddPre)): sim.Projection(IAddPre[i], pre_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) for i in range(len(IAddPost)): sim.Projection(IAddPost[i], post_pop, ee_connector, receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=JEE * 0.05)) # Plastic Connections between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=20., tau_minus=50.0, A_plus=0.02, A_minus=0.02), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=0.9)) rng = NumpyRNG(seed=seed, parallel_safe=True) plastic_projection = \ sim.Projection(pre_pop, post_pop, sim.FixedProbabilityConnector( p_connect=0.5, rng=rng), synapse_type=stdp_model) # +-------------------------------------------------------------------+ # | Simulation and results | # +-------------------------------------------------------------------+ # Record spikes and neurons' potentials pre_pop.record(['v', 'spikes']) post_pop.record(['v', 'spikes']) # Run simulation sim.run(simtime) weights = plastic_projection.get('weight', 'list') pre_spikes = neo_convertor.convert_spikes(pre_pop.get_data('spikes')) post_spikes = neo_convertor.convert_spikes(post_pop.get_data('spikes')) # End simulation on SpiNNaker sim.end() return (pre_spikes, post_spikes, weights)
def get_spike_source_spikes_numpy(self): spikes = self._input_spikes_recorded_list[0] return neo_convertor.convert_spikes(spikes)
def get_output_pop_spikes_numpy(self): spikes = self._recorded_spikes_list[0] return neo_convertor.convert_spikes(spikes)
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(p.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-") synapse_type = p.StaticSynapse(weight=weight_to_spike, delay=delay) for i in range(0, nPopulations): projections.append(p.Projection(populations[i], populations[(i + 1) % nPopulations], p.OneToOneConnector(), synapse_type=synapse_type, 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("----------------------------------------------------") # from pprint import pprint as pp # 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(), synapse_type=synapse_type)) for i in range(0, nPopulations): populations[i].record("v") populations[i].record("gsyn_exc") populations[i].record("spikes") p.run(1500) '''' weights = projections[0].getWeights() delays = projections[0].getDelays() ''' neo = populations[0].get_data(["v", "spikes", "gsyn_exc"]) v = neo_convertor.convert_data(neo, name="v") gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, gsyn, spikes)
n_cores = 1 neo = do_run(n_neurons, n_cores, 0.1875) spiketrains = neo.segments[0].spiketrains for spiketrain in spiketrains: self.assertEquals(0, len(spiketrain)) def test_three_cores(self): n_neurons = 40 n_cores = 3 neo = do_run(n_neurons, n_cores, 0.1875) spiketrains = neo.segments[0].spiketrains for spiketrain in spiketrains: self.assertEquals(0, len(spiketrain)) if __name__ == '__main__': n_neurons = 40 n_cores = 3 neo = do_run(n_neurons, n_cores, 0.1875) spikes = neo_convertor.convert_spikes(neo) v = neo_convertor.convert_data(neo, "v") gsyn = neo_convertor.convert_data(neo, "gsyn_exc") print(spikes) plot_utils.plot_spikes(spikes) plot_utils.heat_plot(v) plot_utils.heat_plot(gsyn) times = set(spikes[:, 1]) print(n_neurons * len(times), len(spikes))
gsyn_inh_0_0 = neo_convertor.convert_data(neos[0], "gsyn_inh", 0) gsyn_inh_1_0 = neo_convertor.convert_data(neos[1], "gsyn_inh", 0) gsyn_inh_1_1 = neo_convertor.convert_data(neos[1], "gsyn_inh", 1) self.assertEquals(nNeurons * runtimes[0], len(gsyn_inh_0_0)) self.assertEquals(nNeurons * runtimes[0], len(gsyn_inh_1_0)) self.assertEquals(nNeurons * runtimes[1], len(gsyn_inh_1_1)) if __name__ == '__main__': synfire_run.do_run(nNeurons, spike_times=spike_times, reset=reset, run_times=runtimes, neurons_per_core=neurons_per_core, get_all=True) neos = synfire_run.get_output_pop_all_list() spikes = [1, 1] spikes[0] = neo_convertor.convert_spikes(neos[1], 0) spikes[1] = neo_convertor.convert_spikes(neos[1], 1) v_1_0 = neo_convertor.convert_data(neos[1], "v", 0) v_1_1 = neo_convertor.convert_data(neos[1], "v", 1) gsyn_exc_1_0 = neo_convertor.convert_data(neos[1], "gsyn_exc", 0) gsyn_exc_1_1 = neo_convertor.convert_data(neos[1], "gsyn_exc", 1) print(len(spikes[0])) print(len(spikes[1])) plot_utils.plot_spikes(spikes) plot_utils.heat_plot(v_1_0, title="v1") plot_utils.heat_plot(gsyn_exc_1_0, title="gysn1") plot_utils.heat_plot(v_1_1, title="v2") plot_utils.heat_plot(gsyn_exc_1_1, title="gysn2")
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core(p.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(p.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_exc") populations[0].record("spikes") populations[2].record("v") populations[2].record("gsyn_exc") populations[2].record("spikes") p.run(500) neo = populations[0].get_data(["v", "spikes", "gsyn_exc"]) cond_v = neo_convertor.convert_data(neo, name="v") cond_gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") cond_spikes = neo_convertor.convert_spikes(neo) neo = populations[2].get_data(["v", "spikes", "gsyn_exc"]) curr_v = neo_convertor.convert_data(neo, name="v") curr_gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") curr_spikes = neo_convertor.convert_spikes(neo) p.end() return (cond_v, cond_gsyn, cond_spikes, curr_v, curr_gsyn, curr_spikes)
def do_run(): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) nNeurons = 100 # number of neurons in each population 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 = 3 delays = list() connections = list() for i in range(0, nNeurons): delays.append(float(delay)) singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) 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), p.StaticSynapse(weight=weight_to_spike, delay=delay))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=1))) populations[0].record(['spikes']) p.external_devices.activate_live_output_for(populations[0]) populations[0].add_placement_constraint(0, 0, 2) populations[1].add_placement_constraint(0, 0, 3) run_time = 1000 print("Running for {} ms".format(run_time)) p.run(run_time) spikes = neo_convertor.convert_spikes(populations[0].get_data('spikes')) p.end() return spikes
ie_projection = sim.Projection( in_pop, ex_pop, sim.FixedProbabilityConnector(0.02), receptor_type='inhibitory', synapse_type=stdp_model) return ex_pop, ie_projection # Build static network static_ex_pop, _ = build_network(None) # Run for 1s sim.run(1000) # Get static spikes static_spikes = static_ex_pop.get_data('spikes') static_spikes_numpy = neo_convertor.convert_spikes(static_spikes) # Build inhibitory plasticity model stdp_model = sim.STDPMechanism( timing_dependence=sim.extra_models.Vogels2011Rule(alpha=0.12, tau=20.0, A_plus=0.05), weight_dependence=sim.AdditiveWeightDependence(w_min=0.0, w_max=1.0)) # Build plastic network plastic_ex_pop, plastic_ie_projection = build_network(stdp_model) # Run simulation sim.run(10000) # Get plastic spikes and save to disk plastic_spikes = plastic_ex_pop.get_data('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(p.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_exc") populations[0].record("spikes") run_time = (max_delay * nNeurons) print("Running for {} ms".format(run_time)) p.run(run_time) neo = populations[0].get_data(["v", "spikes", "gsyn_exc"]) v = neo_convertor.convert_data(neo, name="v") gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, gsyn, spikes)
def do_run(): # 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 } ################################## # 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(n_neurons, Frontend.IF_curr_exp(**cell_params_lif), label='pop_forward') pop_backward = Frontend.Population(n_neurons, Frontend.IF_curr_exp(**cell_params_lif), label='pop_backward') # Create injection populations injector_forward = Frontend.Population( n_neurons, Frontend.external_devices.SpikeInjector(), additional_parameters=cell_params_spike_injector_with_key, label='spike_injector_forward') injector_backward = Frontend.Population( n_neurons, Frontend.external_devices.SpikeInjector(), additional_parameters=cell_params_spike_injector, label='spike_injector_backward') # Create a connection from the injector into the populations Frontend.Projection(injector_forward, pop_forward, Frontend.OneToOneConnector(), Frontend.StaticSynapse(weight=weight_to_spike)) Frontend.Projection(injector_backward, pop_backward, Frontend.OneToOneConnector(), Frontend.StaticSynapse(weight=weight_to_spike)) # Synfire chain connection where each neuron is connected to 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, n_neurons - 1): loop_forward.append((i, (i + 1) % n_neurons, weight_to_spike, 3)) loop_backward.append(((i + 1) % n_neurons, i, weight_to_spike, 3)) Frontend.Projection( pop_forward, pop_forward, Frontend.FromListConnector(loop_forward), Frontend.StaticSynapse(weight=weight_to_spike, delay=3)) Frontend.Projection( pop_backward, pop_backward, Frontend.FromListConnector(loop_backward), Frontend.StaticSynapse(weight=weight_to_spike, delay=3)) # record spikes from the synfire chains so that we can read off valid # results in a safe way afterwards, and verify the behaviour pop_forward.record(['spikes']) pop_backward.record(['spikes']) # Activate the sending of live spikes Frontend.external_devices.activate_live_output_for(pop_forward) Frontend.external_devices.activate_live_output_for(pop_backward) # Set up the live connection for sending spikes live_spikes_connection_send = \ Frontend.external_devices.SpynnakerLiveSpikesConnection( receive_labels=None, local_port=None, send_labels=["spike_injector_forward", "spike_injector_backward"]) Frontend.external_devices.add_database_socket_address( live_spikes_connection_send.local_ip_address, live_spikes_connection_send.local_port, None) # Set up callbacks to occur at initialisation live_spikes_connection_send.add_init_callback("spike_injector_forward", init_pop) live_spikes_connection_send.add_init_callback("spike_injector_backward", init_pop) # Set up callbacks to occur at the start of simulation live_spikes_connection_send.add_start_resume_callback( "spike_injector_forward", send_input_forward) live_spikes_connection_send.add_start_resume_callback( "spike_injector_backward", send_input_backward) # if not using the c visualiser, then a new spynnaker live spikes # connection is created to define that there is a python function which # receives the spikes. live_spikes_connection_receive = \ Frontend.external_devices.SpynnakerLiveSpikesConnection( receive_labels=["pop_forward", "pop_backward"], local_port=None, send_labels=None) Frontend.external_devices.add_database_socket_address( live_spikes_connection_receive.local_ip_address, live_spikes_connection_receive.local_port, 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) Frontend.run(run_time) # Retrieve spikes from the synfire chain population spikes_forward = neo_convertor.convert_spikes( pop_forward.get_data('spikes')) spikes_backward = neo_convertor.convert_spikes( pop_backward.get_data('spikes')) # Clear data structures on spiNNaker to leave the machine in a clean state # for future executions Frontend.end() return (spikes_forward, spikes_backward)
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core(p.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(p.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(p.Izhikevich, 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.Izhikevich, 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_exc") populations[0].record("spikes") # record stuff for curr populations[1].record("v") populations[1].record("gsyn_exc") populations[1].record("spikes") # record stuff for izk populations[2].record("v") populations[2].record("gsyn_exc") populations[2].record("spikes") p.run(500) # get cond neo = populations[0].get_data(["v", "spikes", "gsyn_exc"]) cond_v = neo_convertor.convert_data(neo, name="v") cond_gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") cond_spikes = neo_convertor.convert_spikes(neo) # get curr neo = populations[1].get_data(["v", "spikes", "gsyn_exc"]) curr_v = neo_convertor.convert_data(neo, name="v") curr_gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") curr_spikes = neo_convertor.convert_spikes(neo) # get izk neo = populations[1].get_data(["v", "spikes", "gsyn_exc"]) izk_v = neo_convertor.convert_data(neo, name="v") izk_gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") izk_spikes = neo_convertor.convert_spikes(neo) 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): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core(p.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_exc") populations[0].record("spikes") p.run(1000) '''' weights = projections[0].getWeights() delays = projections[0].getDelays() ''' neo = populations[0].get_data(["v", "spikes", "gsyn_exc"]) v = neo_convertor.convert_data(neo, name="v") gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, gsyn, spikes)
def test_run(self): v, spikes = do_run(plot=False) # any checks go here spikes_test = neo_convertor.convert_spikes(spikes) self.assertEquals(3, len(spikes_test))
def do_run(): # p.setup(timestep=1.0, min_delay = 1.0, max_delay = 32.0) 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) # p.set_number_of_neurons_per_core("DelayExtension", 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 # d_value = 3.1 delay = 3 # delay = numpy.random.RandomState() delays = list() connections = list() for i in range(0, nNeurons): # d_value = int(delay.uniform(low=1, high=max_delay)) # if i == 0: # d_value = 16.0 # if i == 1: # d_value = 17.0 # if i == 2: # d_value = 33.0 delays.append(float(delay)) singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) 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')) # populations[0].set_mapping_constraint({"x": 1, "y": 0}) projections.append( p.Projection(populations[0], populations[0], p.FromListConnector(connections), p.StaticSynapse(weight=weight_to_spike, delay=delay))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=1))) p.external_devices.activate_live_output_for(populations[0]) populations[0].set_constraint(ChipAndCoreConstraint(0, 0, 4)) populations[1].set_constraint(ChipAndCoreConstraint(0, 0, 5)) run_time = 100 print("Running for {} ms".format(run_time)) populations[0].record(['spikes']) p.run(run_time) # v = None # gsyn = None spikes = None spikes = neo_convertor.convert_spikes(populations[0].get_data(['spikes'])) # print(projections[0].getWeights()) # print(projections[0].getDelays()) # print(delays) p.end() return spikes