def test_allow_self_connections(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 synapse_type = first_population._vertex.get_synapse_id('excitatory') connection = pyNN.AllToAllConnector(weight, delay, allow_self_connections=False) synaptic_list = connection.generate_synapse_list( first_population, first_population, 1, 1.0, synapse_type) pp(synaptic_list.get_rows())
def test_generate_synapse_list(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 synapse_type = first_population._vertex.get_synapse_id('excitatory') connection = pyNN.AllToAllConnector(weight, delay) synaptic_list = connection.generate_synapse_list( first_population, first_population, 1, 1.0, synapse_type) self.assertEqual(synaptic_list.get_max_weight(), weight) self.assertEqual(synaptic_list.get_min_weight(), weight) # pp(synaptic_list.get_rows()) self.assertEqual(synaptic_list.get_n_rows(), number_of_neurons) self.assertEqual(synaptic_list.get_max_delay(), delay) self.assertEqual(synaptic_list.get_min_delay(), delay)
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_synapse_list_generation_for_different_sized_populations(self): number_of_neurons = 10 first_population = pyNN.Population(number_of_neurons, pyNN.IF_curr_exp, cell_params_lif, label="One pop") second_population = pyNN.Population(number_of_neurons + 5, pyNN.IF_curr_exp, cell_params_lif, label="Second pop") weight = 2 delay = 1 connection = pyNN.AllToAllConnector(weight, delay) synaptic_list = connection.generate_synapse_list( first_population, second_population, 1, 1.0, 0) self.assertEqual(synaptic_list.get_max_weight(), weight) self.assertEqual(synaptic_list.get_min_weight(), weight) self.assertEqual(synaptic_list.get_n_rows(), number_of_neurons) self.assertEqual(synaptic_list.get_max_delay(), delay) self.assertEqual(synaptic_list.get_min_delay(), delay)
projections = list() weight_to_spike = 2 #delay = 3.1 injection_delay = 2 delay = 10 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.AllToAllConnector(weights=weight_to_spike, delays=delay))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector([(0, 0, 4, injection_delay)]))) populations[0].record_v() populations[0].record() p.run(90) v = None gsyn = None spikes = None v = populations[0].get_v(compatible_output=True) spikes = populations[0].getSpikes(compatible_output=True)
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 })
raster_plot() #Let us only use the ON events TrianSpikeON = BuildTrainingSpike(order,1) #print TrianSpikeON spikeArrayOn = {'spike_times': TrianSpikeON} ON_pop = sim.Population(prepop_size, sim.SpikeSourceArray, spikeArrayOn, label='inputSpikes_On') post_pop= sim.Population(postpop_size,sim.IF_curr_exp, cell_params_lif, label='post_1') connectionsOn = sim.Projection(ON_pop, post_pop, sim.FromListConnector( convert_weights_to_list(weights_import, delay))) #inhibitory between the neurons connection_I = sim.Projection(post_pop, post_pop, sim.AllToAllConnector( weights = 15,delays=1,allow_self_connections=False), target='inhibitory') post_pop.record() sim.run(simtime) # == Get the Simulated Data ================================================= post_spikes = post_pop.getSpikes(compatible_output=True) sim.end() def GetFiringPattern(spike,low,high): spikeT = np.transpose(spike) time_stamp = spikeT[1] target_index = ((time_stamp-low)>=0) & ((time_stamp-high)<0) firingTable = np.unique(spikeT[0][target_index]) firingRate = len(np.unique(spikeT[0][target_index])) return firingRate,firingTable
output_population=readout_neurons, clk_rate=1000, ros_output_rate=10) #====================================================== #=== #=== Define Neural Projections #=== #====================================================== # Build your network, run the simulation and optionally record the spikes and voltages. pynn.Projection(input_interface, reservoir, pynn.AllToAllConnector(weights=3, delays=1)) pynn.Projection(reservoir, readout_neurons, pynn.AllToAllConnector(weights=3, delays=1)) readout_neurons.record() readout_neurons.record_v() pynn.run(simulation_time) spikes = readout_neurons.getSpikes()
sim.Projection(IAddPre[i], pre_pop, ee_connector, target='excitatory') for i in range(len(IAddPost)): sim.Projection(IAddPost[i], post_pop, ee_connector, target='excitatory') # Plastic Connections between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence = sim.SpikePairRule(tau_plus = 20., tau_minus = 50.0, nearest=True), weight_dependence = sim.AdditiveWeightDependence(w_min = 0, w_max = 0.9, A_plus=0.02, A_minus = 0.02) ) """ plastic_projection = \ sim.Projection(pre_pop, post_pop, sim.FixedProbabilityConnector(p_connect=0.10, delays=1, weights=2), synapse_dynamics = sim.SynapseDynamics(slow= stdp_model)) """ plastic_projection = \ sim.Projection(pre_pop, post_pop, sim.AllToAllConnector(delays=1, weights=2), synapse_dynamics = sim.SynapseDynamics(slow= stdp_model)) """ plastic_projection = \ sim.Projection(pre_pop, post_pop, sim.FixedProbabilityConnector(p_connect=0.10, delays=17, weights=2)) """ # +-------------------------------------------------------------------+ # | Simulation and results | # +-------------------------------------------------------------------+ # Record neurons' potentials pre_pop.record_v() post_pop.record_v()
populations[population_index].set_mapping_constraint({'x':0, 'y':0}) population_index += 1 populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='in_cur_esp2')) populations[population_index].set_mapping_constraint({'x':7, 'y':7}) population_index += 1 #upwards path for processor in range(2, 16): populations.append(p.Population(nNeurons, p.SpikeSourceArray, spikeArray, label='inputSpikes_2:{}'.format(processor))) populations[population_index].set_mapping_constraint({'x':0, 'y':0}) projections.append(p.Projection(populations[population_index], populations[0], p.AllToAllConnector())) population_index += 1 for processor in range(2, 16): populations.append(p.Population(nNeurons, p.SpikeSourceArray, spikeArray, label='inputSpikes_2:{}'.format(processor))) populations[population_index].set_mapping_constraint({'x':1, 'y':1}) projections.append(p.Projection(populations[population_index], populations[0], p.AllToAllConnector())) population_index += 1 for processor in range(2, 16): populations.append(p.Population(nNeurons, p.SpikeSourceArray, spikeArray, label='inputSpikes_2:{}'.format(processor))) populations[population_index].set_mapping_constraint({'x':2, 'y':2}) projections.append(p.Projection(populations[population_index], populations[0], p.AllToAllConnector())) population_index += 1
spikeArrayOn, label='inputSpikes_On') post_pop = sim.Population(postpop_size, sim.IF_curr_exp, cell_params_lif, label='post_1') connectionsOn = sim.Projection( ON_pop, post_pop, sim.FromListConnector(convert_weights_to_list(weights_import, delay))) #inhibitory between the neurons connection_I = sim.Projection(post_pop, post_pop, sim.AllToAllConnector( weights=15, delays=1, allow_self_connections=False), target='inhibitory') ON_pop.record() post_pop.record() sim.run(simtime) # == Get the Simulated Data ================================================= pre_spikes = ON_pop.getSpikes(compatible_output=True) post_spikes = post_pop.getSpikes(compatible_output=True) sim.end() def GetFiringPattern(spike, low, high): spikeT = np.transpose(spike)
'v_thresh' : -50.0 } cell_params_pos = { 'rate' : 10.0 } rng = NumpyRNG( seed = 1 ) weight_distn = RandomDistribution( 'normal', parameters = [ 0.35, 0.035 ], rng=rng, boundaries=[0.0, 3.0 ], constrain='redraw' ) delay_distn = RandomDistribution( 'normal', parameters = [ 7.0, 2.0 ], rng=rng, boundaries=[1.0, 16.0], constrain='redraw' ) sink = p.Population( nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1') source = p.Population( 2000, p.SpikeSourcePoisson, cell_params_pos, label='inputSpikes_1') p.Projection( source, sink, p.AllToAllConnector( weights = weight_distn, delays = delay_distn )) sink.record_v() sink.record_gsyn() sink.record() run_time = 1000 print "Running for {} ms".format(run_time) p.run(run_time) v = None gsyn = None spikes = None v = sink.get_v(compatible_output=True) gsyn = sink.get_gsyn(compatible_output=True)
cell_params_lif, label='post_1') #------------------------------------------------# # STDP and Neuron Network Specification# #------------------------------------------------# stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=15.0, tau_minus=25.0 ,nearest=True), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=0.5, A_plus=0.012, A_minus=0.01)) weight_ini = np.random.normal(0.108, 0.003,prepop_size*postpop_size).tolist() delay_ini = np.random.normal(2, 0.3,prepop_size*postpop_size).tolist() connectionsOn = sim.Projection(ON_pop, post_pop, sim.AllToAllConnector( weights = weight_ini,delays=2), synapse_dynamics=sim.SynapseDynamics( slow=stdp_model)) #inhibitory between the neurons connection_I = sim.Projection(post_pop, post_pop, sim.AllToAllConnector(weights = 0.08,delays=1), target='inhibitory') post_pop.record() #post_pop.record_v() sim.run(simtime) v = None post_spikes = None synapses =None
ON_pop = sim.Population(prepop_size, sim.SpikeSourceArray, spikeArrayOn, label='inputSpikes_On') post_pop = sim.Population(postpop_size, sim.IF_curr_exp, cell_params_lif, label='post_1') connectionsOn = sim.Projection( ON_pop, post_pop, sim.FromListConnector(convert_weights_to_list(weights_import, delay))) #inhibitory between the neurons connection_I = sim.Projection(post_pop, post_pop, sim.AllToAllConnector(weights=0.08, delays=1), target='inhibitory') post_pop.record() sim.run(simtime) # == Get the Simulated Data ================================================= post_spikes = post_pop.getSpikes(compatible_output=True) sim.end() def GetFiringPattern(spike, low, high): spikeT = np.transpose(spike) time_stamp = spikeT[1] target_index = ((time_stamp - low) >= 0) & ((time_stamp - high) < 0) firingTable = np.unique(spikeT[0][target_index]) firingRate = len(np.unique(spikeT[0][target_index]))
# Neuron populations population = sim.Population(1, model, cell_params) # Plastic Connection between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence=cer.TimingDependenceCerebellum(tau=tau, peak_time=peak_time), weight_dependence=sim.AdditiveWeightDependence(w_min=0.0, w_max=1.0, A_plus=0.1, A_minus=0.5)) # Connections between spike sources and neuron populations ####### SET HERE THE PARALLEL FIBER-PURKINJE CELL LEARNING RULE ee_connector = sim.AllToAllConnector(weights=0.5) projection_pf = sim.Projection( pre_stim, population, ee_connector, synapse_dynamics=sim.SynapseDynamics(slow=stdp_model), target='excitatory') # SET HERE THE TEACHING SIGNAL PROJECTION ee_connector = sim.OneToOneConnector() proj_teaching = sim.Projection(teaching_stim, population, ee_connector, target='supervision') print("Simulating for %us" % (sim_time / 1000))
output_population=readout_neurons, clk_rate=1000, ros_output_rate=10) #====================================================== #=== #=== Define Neural Projections #=== #====================================================== # Build your network, run the simulation and optionally record the spikes and voltages. rconn = 0.1 ext_conn = FixedProbabilityConnector(rconn, weights=0.1) pynn.Projection(input_interface, reservoir, pynn.AllToAllConnector(weights=0.5, delays=1)) pynn.Projection(reservoir, readout_neurons, pynn.AllToAllConnector(weights=0.5, delays=1)) readout_neurons.record() readout_neurons.record_v() # run the network and measure the time it takes timer.start() pynn.run(simulation_time) simCPUTime = timer.diff() spikes = readout_neurons.getSpikes()
'i_offset': 0.0, 'tau_m': 10.0, 'tau_refrac': 2.0, 'tau_syn_E': 2.5, 'tau_syn_I': 2.5, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -55.4 } spike_list = {'spike_times': [float(x) for x in range(599)]} #p.setup(timestep=1.0, min_delay = 1.0, max_delay = 32.0) p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) nNeurons = 256 # number of neurons in each population populations = list() projections = list() populations.append( p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input')) populations.append( p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1')) projections.append( p.Projection(populations[0], populations[1], p.AllToAllConnector())) populations[0].record() p.run(1000) spikes = populations[0].getSpikes(compatible_output=True) print spikes p.end()
delay = 1 spikeArray = {'spike_times': [[0, 10, 20, 30]]} populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='pop_0')) #populations.append(p.Population(nNeurons, p.IF_curr_exp, input_cell_params, 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')) #projections.append(p.Projection(populations[0], populations[1], p.OneToOneConnector(weights=weight_to_spike, delays=delay))) projections.append( p.Projection( populations[0], populations[1], p.AllToAllConnector(weights=weight_to_spike, delays=injection_delay))) projections.append( p.Projection(populations[1], populations[2], p.OneToOneConnector(weights=weight_to_spike, delays=delay))) #projections.append(p.Projection(populations[1], populations[0], p.FromListConnector([(0, 0, weight_to_spike, injection_delay)]))) populations[1].record_v() populations[1].record() p.run(100) v = None gsyn = None spikes = None v = populations[1].get_v(compatible_output=True)
print "++++++++++++++++" print "Added population %s" % (i) print "o-o-o-o-o-o-o-o-" for i in range(0, nPopulations ): projections.append(p.Projection(populations[i], populations[(i + 1) % nPopulations], p.OneToOneConnector(weight_to_spike,delay), label= "Projection from pop {} to pop {}".format(i,(i + 1) % nPopulations))) print "++++++++++++++++++++++++++++++++++++++++++++++++++++" print "Added projection from population %s to population %s" % (i, (i + 1) % nPopulations) print "----------------------------------------------------" injectionConnection = [(0, 0, weight_to_spike, delay)] 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(weight_to_spike,delay))) for i in range(0,nPopulations): populations[i].record_v() populations[i].record_gsyn() populations[i].record() p.run(1500) v = None gsyn = None spikes = None '''' weights = projections[0].getWeights() delays = projections[0].getDelays()