def test_get_weights(self): # Population parameters cell_params = { 'cm': 0.2, # nF 'i_offset': 0.2, 'tau_m': 20.0, 'tau_refrac': 5.0, 'tau_syn_E': 5.0, 'tau_syn_I': 10.0, 'v_reset': -60.0, 'v_rest': -60.0, 'v_thresh': -50.0 } # Reduce number of neurons to simulate on each core sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 10) # Build inhibitory plasticity model stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=20.0, tau_minus=12.7, nearest=True), weight_dependence=sim.AdditiveWeightDependence(w_min=0.0, w_max=1.0, A_plus=0.05), mad=True) # Build plastic network plastic_ex_pop, plastic_ie_projection =\ self.build_network(sim.SynapseDynamics(slow=stdp_model), cell_params) # Run simulation sim.run(1000) # Get plastic spikes and save to disk plastic_spikes = plastic_ex_pop.getSpikes(compatible_output=True) #numpy.save("plastic_spikes.npy", plastic_spikes) plastic_weights = plastic_ie_projection.getWeights(format="array") # mean_weight = numpy.average(plastic_weights) # End simulation on SpiNNaker sim.end()
# Connections between spike sources and neuron populations ee_connector = sim.OneToOneConnector(weights=2) sim.Projection(pre_stim, pre_pop, ee_connector, target='excitatory') sim.Projection(post_stim, post_pop, ee_connector, target='excitatory') # **HACK** param_scale = 0.5 # Plastic Connection between pre_pop and post_pop # Sjostrom visual cortex min-triplet params stdp_model = sim.STDPMechanism( timing_dependence=sim.PfisterSpikeTripletRule(tau_plus=16.8, tau_minus=33.7, tau_x=101, tau_y=114), weight_dependence=sim.AdditiveWeightDependence( w_min=0.0, w_max=1.0, A_plus=param_scale * 0.0, A_minus=param_scale * 7.1e-3, A3_plus=param_scale * 6.5e-3, A3_minus=param_scale * 0.0)) projections[-1].append( sim.Projection( pre_pop, post_pop, sim.OneToOneConnector(weights=start_w), synapse_dynamics=sim.SynapseDynamics(slow=stdp_model))) print("Simulating for %us" % (sim_time / 1000))
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 })
"threshold_value": -10.0, "my_threshold_parameter": 0.4 }, label="my_model_my_threshold_pop") p.Projection(input_pop, my_model_my_threshold_pop, p.OneToOneConnector(weights=weight)) my_model_stdp_pop = p.Population(1, MyModelCurrExp, { "my_parameter": -70.0, "i_offset": i_offset, }, label="my_model_pop") stdp = p.STDPMechanism(timing_dependence=MyTimingDependence( my_potentiation_parameter=2.0, my_depression_parameter=0.1), weight_dependence=MyWeightDependence(w_min=0.0, w_max=10.0, my_parameter=0.5), mad=True) p.Projection(input_pop, my_model_stdp_pop, p.OneToOneConnector(weights=weight)) stdp_connection = p.Projection(input_pop, my_model_stdp_pop, p.OneToOneConnector(weights=0), synapse_dynamics=p.SynapseDynamics(slow=stdp)) my_model_pop.record_v() my_model_my_synapse_type_pop.record_v() my_model_my_additional_input_pop.record_v() my_model_my_threshold_pop.record_v() p.run(run_time)
import spynnaker.pyNN as p p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) nNeurons = 100 #p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons) input = p.Population(1024, p.SpikeSourcePoisson, {'rate': 10}, "input") relay_on = p.Population(1024, p.IF_curr_exp, {}, "input") weight_to_spike = 2.0 delay = 17 t_rule_LGN = p.SpikePairRule (tau_plus=17, tau_minus=34) w_rule_LGN = p.AdditiveWeightDependence (w_min=0.0, w_max=0.3, A_plus=0.01, A_minus=0.0085) stdp_model_LGN = p.STDPMechanism (timing_dependence = t_rule_LGN, weight_dependence = w_rule_LGN) s_d_LGN = p.SynapseDynamics(slow = stdp_model_LGN) in_to_relay_on = p.Projection(input, relay_on, p.OneToOneConnector(weights=1),synapse_dynamics = s_d_LGN, target='excitatory') p.run(1000) p.end()
# Stimulating populations pre_stim = p.Population(pop_size, p.SpikeSourceArray, {'spike_times': [[i for i in range(0, sim_time, time_between_pairs)],]}) post_stim = p.Population(pop_size, p.SpikeSourceArray, {'spike_times': [[i for i in range(pairing_start_time, pairing_end_time, time_between_pairs)],]}) # +-------------------------------------------------------------------+ # | Creation of connections | # +-------------------------------------------------------------------+ # Connection type between noise poisson generator and excitatory populations ee_connector = p.OneToOneConnector(weights=2) p.Projection(pre_stim, pre_pop, ee_connector, target='excitatory') p.Projection(post_stim, post_pop, ee_connector, target='excitatory') # Plastic Connections between pre_pop and post_pop stdp_model = p.STDPMechanism( timing_dependence = p.SpikePairRule(tau_plus = 20.0, tau_minus = 50.0), weight_dependence = p.AdditiveWeightDependence(w_min = 0, w_max = 1, A_plus=0.02, A_minus = 0.02) ) p.Projection(pre_pop, post_pop, p.OneToOneConnector(), synapse_dynamics = p.SynapseDynamics(slow= stdp_model) ) # Record spikes pre_pop.record() post_pop.record() # Run simulation p.run(sim_time) # Dump data #pre_pop.printSpikes("results/stdp_pre.spikes")
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]}) # 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
projections = list() weight_to_spike = 2.0 delay = 1 connections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) # Plastic Connection between pre_pop and post_pop stdp_model1 = p.STDPMechanism(timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7, nearest=True), weight_dependence=p.AdditiveWeightDependence( w_min=0.0, w_max=1.0, A_plus=0.005, A_minus=0.005), mad=True) # Plastic Connection between pre_pop and post_pop stdp_model2 = p.STDPMechanism( timing_dependence=p.PfisterSpikeTripletRule(tau_plus=16.7, tau_minus=33.7, tau_x=44, tau_y=44), weight_dependence=p.AdditiveWeightDependence(w_min=0.0, w_max=1.0, A_plus=0.005, A_minus=0.005),
#raster plot of the firing time of the neurons TrianSpikeON = BuildTrainingSpike(order,1) FourDirectionTime = BuildTrainingSpike(order,1) 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') #------------------------------------------------# # 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_stim = sim.Population(1, sim.SpikeSourceArray, {'spike_times': [ post_times, ]}) # Connections between spike sources and neuron populations ee_connector = sim.OneToOneConnector(weights=2) sim.Projection(pre_stim, pre_pop, ee_connector, target='excitatory') sim.Projection(post_stim, post_pop, ee_connector, target='excitatory') # Plastic Connection between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=16.7, tau_minus=33.7, nearest=True), weight_dependence=sim.AdditiveWeightDependence(w_min=0.0, w_max=1.0, A_plus=0.005, A_minus=0.005), mad=mad) projections.append( sim.Projection(pre_pop, post_pop, sim.OneToOneConnector(weights=start_w), synapse_dynamics=sim.SynapseDynamics(slow=stdp_model))) print("Simulating for %us" % (sim_time / 1000)) # Run simulation sim.run(sim_time)
# Up if y > 0: add_connection(x, y, x, y - 1, cost_image, conn_list, delay_func, weight_func) # Down if y < (cost_image.shape[1] - 1): add_connection(x, y, x, y + 1, cost_image, conn_list, delay_func, weight_func) if plastic: stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=50.0, tau_minus=50.0), weight_dependence=sim.AdditiveWeightDependence( w_min=0.0, w_max=instant_spike_weight, A_plus=0.000001, A_minus=1.0), dendritic_delay_fraction=1.0) synapse_dynamics = sim.SynapseDynamics(slow=stdp_model) else: synapse_dynamics = None # Create connector proj = sim.Projection(neurons, neurons, sim.FromListConnector(conn_list), synapse_dynamics=synapse_dynamics, target="excitatory") # Stimulate stim neuron