def do_run(self): sim.setup(1.0) pop = sim.Population(1, sim.IF_curr_exp(i_offset=5.0), label="pop") pop.record("spikes") pop_2 = sim.Population(1, sim.IF_curr_exp(), label="pop_2") proj = sim.Projection( pop, pop_2, sim.AllToAllConnector(), sim.STDPMechanism( timing_dependence=sim.SpikePairRule(), weight_dependence=sim.AdditiveWeightDependence(), weight=sim.RandomDistribution("uniform", low=0.3, high=0.7))) proj_2 = sim.Projection( pop, pop_2, sim.OneToOneConnector(), sim.STDPMechanism( timing_dependence=sim.SpikePairRule(), weight_dependence=sim.AdditiveWeightDependence(), weight=sim.RandomDistribution("uniform", low=0.3, high=0.7))) sim.run(100) weights_1_1 = proj.get("weight", "list") weights_1_2 = proj_2.get("weight", "list") spikes_1 = pop.get_data("spikes").segments[0].spiketrains sim.reset() sim.run(100) weights_2_1 = proj.get("weight", "list") weights_2_2 = proj_2.get("weight", "list") spikes_2 = pop.get_data("spikes").segments[1].spiketrains sim.end() assert(numpy.array_equal(weights_1_1, weights_2_1)) assert(numpy.array_equal(weights_1_2, weights_2_2)) assert(numpy.array_equal(spikes_1, spikes_2))
def do_run(self): sim.setup(timestep=1.0) input_pop = sim.Population( 1, sim.SpikeSourceArray(range(0, run_time, 100)), label="input") test_pop = sim.Population( 1, MyModelCurrExp(my_neuron_parameter=-70.0, i_offset=0.0), label="my_model_pop") test_pop.record(['spikes', 'v']) stdp = sim.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_weight_parameter=0.5)) sim.Projection( input_pop, test_pop, sim.OneToOneConnector(), receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=2.0)) stdp_connection = sim.Projection( input_pop, test_pop, sim.OneToOneConnector(), synapse_type=stdp) sim.run(run_time) weights = stdp_connection.get('weight', 'list') neo = test_pop.get_data('all') sim.end() for _, _, weight in weights: self.assertEqual(weight, 0.5) self.check_results(neo, [201, 402, 603, 804])
def post_spike_same_time(): """ Check that the offsets between send times of different spike source arrays don't change the outcome of STDP """ # STDP parameters a_plus = 0.01 a_minus = 0.01 tau_plus = 20 tau_minus = 20 plastic_delay = 1 initial_weight = 4.0 max_weight = 5.0 min_weight = 0 pre_spikes = range(0, 10, 2) p.setup(1) pre_1 = p.Population(1, p.SpikeSourceArray(pre_spikes), label="pre_1") pre_2 = p.Population(1, p.SpikeSourceArray(pre_spikes), label="pre_2") post_1 = p.Population(1, p.IF_curr_exp(), label="post_1") post_2 = p.Population(1, p.IF_curr_exp(), label="post_2") post_1.record("spikes") stdp = p.STDPMechanism( timing_dependence=p.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=p.AdditiveWeightDependence(w_min=min_weight, w_max=max_weight), weight=initial_weight, delay=plastic_delay) conn = p.OneToOneConnector() proj_1 = p.Projection(pre_1, post_1, conn, stdp) proj_2 = p.Projection(pre_2, post_2, conn, stdp) p.run(12) # Get the weights weights_1 = list(proj_1.get('weight', 'list', with_address=False)) weights_2 = list(proj_2.get('weight', 'list', with_address=False)) # Get the spikes post_spikes = numpy.array( # pylint: disable=no-member post_1.get_data('spikes').segments[0].spiketrains[0].magnitude) p.end() new_weight_exact = calculate_spike_pair_additive_stdp_weight( pre_spikes, post_spikes, initial_weight, plastic_delay, max_weight, a_plus, a_minus, tau_plus, tau_minus) print(weights_1) print(weights_2) print(new_weight_exact) assert (len(weights_1) == 1) assert (len(weights_2) == 1) assert (weights_1[0] == weights_2[0]) assert (numpy.allclose(weights_1, new_weight_exact, rtol=0.001))
def _build_stdp_model(self): """ Build STDP Model based on the parameters defined in parameters.py Weights for the layer to train are initialized randomly by Gaussian Distribution. As timing rule for the spike based learning is used the Spike Pair Rule with an additive weight dependence. Returns ------- STDPMechanism object """ if self.rc.train_layer: layer = self.rc.train_layer try: timing_rule = s.SpikePairRule( tau_plus=eval("TAU_PLUS_LAYER_{}".format(layer)), tau_minus=eval("TAU_MINUS_LAYER_{}".format(layer)), A_plus=eval("A_PLUS_LAYER_{}".format(layer)), A_minus=eval("A_MINUS_LAYER_{}".format(layer))) except: raise NotImplementedError( "Timing rule for Layer {} not found in parameters.py". format(layer)) try: # MultiplicativeWeightDependence # AdditiveWeightDependence weight_rule = s.AdditiveWeightDependence( w_max=eval("W_MAX_STDP_LAYER_{}".format(layer)), w_min=eval("W_MIN_STDP_LAYER_{}".format(layer))) except: raise NotImplementedError( "weight rule for Layer {} not found in parameters.py". format(layer)) neurons = self.model.layers[layer].kernels kernel_shape = self.model.layers[layer].shape try: w_shape = (neurons, kernel_shape[0] * kernel_shape[1] ) # (4,64) self.w_init = np.random.normal( loc=eval("INIT_WEIGHT_MEAN_LAYER_{}".format(layer)), scale=eval("SIGMA_LAYER_{}".format(layer)), size=w_shape) except: raise NotImplementedError( "random. parameters for Layer {} not found in parameters.py" .format(layer)) return s.STDPMechanism(timing_dependence=timing_rule, weight_dependence=weight_rule, delay=DELAY_SYNAPSE_CONNECTION) else: return None
def do_run(): # this test ensures there is too much dtcm used up, thus crashes during # initisation p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) input_pop = p.Population(1024, p.SpikeSourcePoisson, {'rate': 10}, "input") relay_on = p.Population(1024, p.IF_curr_exp, {}, "input") t_rule_LGN = p.SpikePairRule(tau_plus=17, tau_minus=34, A_plus=0.01, A_minus=0.0085) w_rule_LGN = p.AdditiveWeightDependence(w_min=0.0, w_max=0.3) stdp_model_LGN = p.STDPMechanism(timing_dependence=t_rule_LGN, weight_dependence=w_rule_LGN, weight=1) # TODO weights=1 p.Projection(input_pop, relay_on, p.OneToOneConnector(), synapse_type=stdp_model_LGN, receptor_type="excitatory") p.run(1000) p.end()
def neuromodulation(self): """ Simple test for neuromodulated STDP. Two pre-synaptic spikes are added, at times 1500 and 2400ms. Post-synaptic neuron is stimulated at 1502 and fires at time 1503ms. Dendritic delay is 1ms so post-synaptic time is at 1504ms when processed in STDP. Dopamine neuron spikes at 1600+1ms (Also added dendritic delay). Calculating weight change in this scenario, according to equations in the Izhikevich 2007 paper*, gives us the weight change of 10.0552710... *https://www.ncbi.nlm.nih.gov/pubmed/17220510 Simulation from SpiNNaker gives us the weight change of 10.0087890625. Some inaccuracy occurs due to precision loss in s5.11 fixed point format used in STDP traces and exp LUTs. Also, due to long timing constants, exp LUTs are discretized further by TAU_C_SHIFT and TAU_D_SHIFT to be able to fit them into memory, adding another level of inaccuracy. Finally, some more accuracy may be lost due to weight scaling. """ timestep = 1.0 duration = 3000 # Main parameters from Izhikevich 2007 STDP paper t_pre = [1500, 2400] # Pre-synaptic neuron times t_post = [1502] # Post-synaptic neuron stimuli time t_dopamine = [1600] # Dopaminergic neuron spike times tau_c = 1000 # Eligibility trace decay time constant. tau_d = 200 # Dopamine trace decay time constant. DA_concentration = 0.1 # Dopamine trace step increase size # Initial weight rewarded_syn_weight = 0.0 cell_params = { 'cm': 0.3, 'i_offset': 0.0, 'tau_m': 10.0, 'tau_refrac': 4.0, 'tau_syn_E': 1.0, 'tau_syn_I': 1.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -55.4 } sim.setup(timestep=timestep) pre_pop = sim.Population(1, sim.SpikeSourceArray, {'spike_times': t_pre}) # Create a population of dopaminergic neurons for reward reward_pop = sim.Population(1, sim.SpikeSourceArray, {'spike_times': t_dopamine}, label='reward') # Stimulus for post synaptic population post_stim = sim.Population(1, sim.SpikeSourceArray, {'spike_times': t_post}) # Create post-synaptic pop which will be modulated by DA concentration post_pop = sim.Population(1, sim.IF_curr_exp, cell_params, label='post1') post_pop.record("spikes") # Stimulate post-synaptic neuron sim.Projection(post_stim, post_pop, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=6), receptor_type='excitatory') # Create STDP dynamics synapse_dynamics = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=10, tau_minus=12, A_plus=1, A_minus=1), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=20), weight=rewarded_syn_weight) # Create a plastic connection between pre and post neurons plastic_projection = sim.Projection(pre_pop, post_pop, sim.AllToAllConnector(), synapse_type=synapse_dynamics, receptor_type='excitatory', label='Pre-post projection') # Create dopaminergic connection sim.Projection(reward_pop, post_pop, sim.AllToAllConnector(), synapse_type=sim.extra_models.Neuromodulation( weight=DA_concentration, tau_c=tau_c, tau_d=tau_d, w_max=20.0), receptor_type='reward', label='reward synapses') sim.run(duration) # End simulation on SpiNNaker weights = plastic_projection.get('weight', 'list') spikes = post_pop.get_data("spikes").segments[0].spiketrains[0] sim.end() print(spikes) pot = 1 * math.exp(-((1504 - 1500) / 10)) decay = math.exp(-((1601 - 1504) / 1000)) el = pot * decay const = 1.0 / (-((1.0 / 1000.0) + (1.0 / 200.0))) decay_d = math.exp(-((2400 - 1601) / 200)) decay_e = math.exp(-((2400 - 1601) / 1000)) weight_exact = (((el * DA_concentration) * const) * ((decay_d * decay_e) - 1)) print(f"Weight calculated: {weight_exact}") print(f"Weight from SpiNNaker: {weights[0][2]}") self.assertTrue(numpy.allclose(weights[0][2], weight_exact, atol=0.02))
sim.setup(timestep=1.0) # consisting of two single-neuron populations pre_pop = sim.Population(1, sim.IF_curr_exp(), label="Pre") post_pop = sim.Population(1, sim.IF_curr_exp(), label="Post") # connected with an STDP synapse using a spike pair rule # and additive weight dependency, and initial weights of 0. timing_rule = sim.SpikePairRule(tau_plus=20.0, tau_minus=20.0, A_plus=0.5, A_minus=0.5) weight_rule = sim.AdditiveWeightDependence(w_max=5.0, w_min=0.0) stdp_model = sim.STDPMechanism(timing_dependence=timing_rule, weight_dependence=weight_rule, weight=0.0, delay=5.0) stdp_projection = sim.Projection(pre_pop, post_pop, sim.OneToOneConnector(), synapse_type=stdp_model) # Stimulate each of the neurons with a spike source array with times of your # choice, with the times for stimulating the first neuron being slightly # before the times stimulating the second neuron (e.g.2ms or more), # ensuring the times are far enough apart not to cause depression # (compare the spacing in time with the tau_plus and tau_minus settings); # note that a weight of 5.0 should be enough to force an IF_curr_exp neuron to # fire with the default parameters. # Add a few extra times at the end of the run for stimulating the first neuron. spike = 0
def run_multiple_stdp_mechs_on_same_neuron(self): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) nNeurons = 200 # 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 = 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, A_plus=0.005, A_minus=0.005), weight_dependence=p.AdditiveWeightDependence(w_min=0.0, w_max=1.0), ) # Plastic Connection between pre_pop and post_pop stdp_model2 = p.STDPMechanism( timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7, A_plus=0.005, A_minus=0.005), weight_dependence=p.AdditiveWeightDependence(w_min=0.0, w_max=1.0), ) # Plastic Connection between pre_pop and post_pop stdp_model3 = p.STDPMechanism( timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7, A_plus=0.005, A_minus=0.005), weight_dependence=p.MultiplicativeWeightDependence(w_min=0.0, w_max=1.0), ) injectionConnection = [(0, 0, weight_to_spike, 1)] spikeArray1 = {'spike_times': [[0]]} spikeArray2 = {'spike_times': [[25]]} spikeArray3 = {'spike_times': [[50]]} spikeArray4 = {'spike_times': [[75]]} spikeArray5 = {'spike_times': [[100]]} spikeArray6 = {'spike_times': [[125]]} spikeArray7 = {'spike_times': [[150]]} spikeArray8 = {'spike_times': [[175]]} populations.append( p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), label='pop_1')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray1), label='inputSpikes_1')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray2), label='inputSpikes_2')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray3), label='inputSpikes_3')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray4), label='inputSpikes_4')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray5), label='inputSpikes_5')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray6), label='inputSpikes_6')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray7), label='inputSpikes_7')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray8), label='inputSpikes_8')) projections.append( p.Projection(populations[0], populations[0], p.FromListConnector(connections), p.StaticSynapse(weight=weight_to_spike, delay=delay))) pop = p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=1)) projections.append(pop) pop = p.Projection(populations[2], populations[0], p.FromListConnector(injectionConnection), synapse_type=stdp_model1) projections.append(pop) # This is expected to raise a SynapticConfigurationException pop = p.Projection(populations[3], populations[0], p.FromListConnector(injectionConnection), synapse_type=stdp_model2) projections.append(pop) pop = p.Projection(populations[4], populations[0], p.FromListConnector(injectionConnection), synapse_type=stdp_model3) projections.append(pop)
def record_weights_using_callback(): ###################################### # Setup ###################################### sim.setup(timestep=simulationParameters["timeStep"]) ###################################### # Neuron pop ###################################### # Input neurons ILayer = sim.Population(popNeurons["ILayer"], sim.SpikeSourceArray(spike_times=ILSpike), label="ILayer") # LIF neurons LIFLayer = sim.Population(popNeurons["LIFLayer"], sim.IF_curr_exp(**neuronParameters["LIFL"]), label="LIFLayer") LIFLayer.set(v=initNeuronParameters["LIFL"]["vInit"]) ###################################### # Synapses ###################################### # ILayer-LIFLayer -> statics sim.Projection(ILayer, LIFLayer, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse( weight=synParameters["IL-LIFL"]["initWeight"], delay=synParameters["IL-LIFL"]["delay"])) # LIFLayer-ILayer -> STDP timing_rule = sim.SpikePairRule( tau_plus=synParameters["LIFL-LIFL"]["tau_plus"], tau_minus=synParameters["LIFL-LIFL"]["tau_minus"], A_plus=synParameters["LIFL-LIFL"]["A_plus"], A_minus=synParameters["LIFL-LIFL"]["A_minus"]) weight_rule = sim.AdditiveWeightDependence( w_max=synParameters["LIFL-LIFL"]["w_max"], w_min=synParameters["LIFL-LIFL"]["w_min"]) stdp_model = sim.STDPMechanism( timing_dependence=timing_rule, weight_dependence=weight_rule, weight=synParameters["LIFL-LIFL"]["initWeight"], delay=synParameters["LIFL-LIFL"]["delay"]) LIFLayer_LIFLayer_conn = sim.Projection( LIFLayer, LIFLayer, sim.AllToAllConnector(allow_self_connections=False), synapse_type=stdp_model) ###################################### # Record parameters ###################################### LIFLayer.record(["spikes", "v"]) weightRecorderLIF_LIF = weight_recorder( sampling_interval=simulationParameters["timeStep"], projection=LIFLayer_LIFLayer_conn) ###################################### # Run simulation ###################################### sim.run(simulationParameters["simTime"], callbacks=[weightRecorderLIF_LIF]) ###################################### # Recall data ###################################### populationData = LIFLayer.get_data(variables=["spikes", "v"]) LIFLSpikes = populationData.segments[0].spiketrains vLIFL = populationData.segments[0].filter(name='v')[0] w_LIFL_LIFL = weightRecorderLIF_LIF.get_weights() ###################################### # End simulation ###################################### sim.end() ###################################### # Return parameters ###################################### return ILSpike, LIFLSpikes, vLIFL, w_LIFL_LIFL
def potentiation_and_depression(self): p.setup(1) runtime = 100 initial_run = 1000 # to negate any initial conditions # STDP parameters a_plus = 0.1 a_minus = 0.0375 tau_plus = 20 tau_minus = 64 plastic_delay = 1 initial_weight = 0.05 max_weight = 0.1 min_weight = 0 pre_spikes = [10, 50] extra_spikes = [30] for i in range(len(pre_spikes)): pre_spikes[i] += initial_run for i in range(len(extra_spikes)): extra_spikes[i] += initial_run # Spike source to send spike via plastic synapse pre_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': pre_spikes}, label="pre") # Spike source to send spike via static synapse to make # post-plastic-synapse neuron fire extra_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': extra_spikes}, label="extra") # Post-plastic-synapse population post_pop = p.Population(1, p.IF_cond_exp(), label="post") # Create projections p.Projection(pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") p.Projection(extra_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=0.1, delay=1), receptor_type="excitatory") syn_plas = p.STDPMechanism( timing_dependence=p.extra_models.SpikeNearestPairRule( tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=p.AdditiveWeightDependence(w_min=min_weight, w_max=max_weight), weight=initial_weight, delay=plastic_delay) plastic_synapse = p.Projection(pre_pop, post_pop, p.OneToOneConnector(), synapse_type=syn_plas, receptor_type='excitatory') # Record the spikes post_pop.record("spikes") # Run p.run(initial_run + runtime) # Get the weights weights = plastic_synapse.get('weight', 'list', with_address=False) # Get the spikes post_spikes = numpy.array( # pylint: disable=no-member post_pop.get_data('spikes').segments[0].spiketrains[0].magnitude) # End the simulation as all information gathered p.end() # Get the spikes and time differences that will be considered by # the simulation (as the last pre-spike will be considered differently) pre_spikes = numpy.array(pre_spikes) last_pre_spike = pre_spikes[-1] considered_post_spikes = post_spikes[post_spikes < last_pre_spike] considered_post_spikes += plastic_delay potentiation_times = list() depression_times = list() for time in pre_spikes: post_times = considered_post_spikes[considered_post_spikes > time] if len(post_times) > 0: last_time = post_times[0] potentiation_times.append(time - last_time) post_times = considered_post_spikes[considered_post_spikes < time] if len(post_times) > 0: last_time = post_times[-1] depression_times.append(last_time - time) potentiation_times = numpy.array(potentiation_times) depression_times = numpy.array(depression_times) # Work out the weight according to the rules potentiations = max_weight * a_plus * numpy.exp( (potentiation_times / tau_plus)) depressions = max_weight * a_minus * numpy.exp( (depression_times / tau_minus)) new_weight_exact = \ initial_weight + numpy.sum(potentiations) - numpy.sum(depressions) # print("Pre neuron spikes at: {}".format(pre_spikes)) # print("Post-neuron spikes at: {}".format(post_spikes)) target_spikes = [1013, 1032, 1051, 1056] self.assertListEqual(list(post_spikes), target_spikes) # print("New weight exact: {}".format(new_weight_exact)) # print("New weight SpiNNaker: {}".format(weights)) self.assertTrue(numpy.allclose(weights, new_weight_exact, rtol=0.001))
def run_script(): p.setup(1.0) p.set_number_of_neurons_per_core(p.IF_curr_exp, 3) inp = p.Population(10, p.SpikeSourceArray(spike_times=[1.0]), label="SpikeSourceArray") out = p.Population(10, p.IF_curr_exp(), label="IF_curr_exp") out.record("spikes") param_projections = [ (1.0, 1.0), (RandomDistribution("uniform", low=1.0, high=10.0), 2.0), (3.0, 17.0), (4.0, RandomDistribution("normal", mu=22.0, sigma=10.0)), (5.0, RandomDistribution("normal_clipped", mu=22.0, sigma=10.0, low=5.0, high=32.0)), (6.0, RandomDistribution("normal_clipped_to_boundary", mu=14.0, sigma=5.0, low=6.0, high=16.0)), (7.0, RandomDistribution("exponential", beta=2.0)), ] connectors = [ p.OneToOneConnector, p.AllToAllConnector, functools.partial(p.AllToAllConnector, allow_self_connections=False), functools.partial(p.FixedProbabilityConnector, 0.5), functools.partial(p.FixedTotalNumberConnector, 50, with_replacement=True), functools.partial(p.FixedTotalNumberConnector, 20, with_replacement=False) ] projs = list() for weight, delay in param_projections: for connector in connectors: conn = connector() projs.append( (weight, delay, conn, False, p.Projection(inp, out, conn, p.StaticSynapse(weight=weight, delay=delay)))) projs.append((weight, delay, conn, True, p.Projection( inp, out, conn, p.STDPMechanism(p.SpikePairRule(), p.AdditiveWeightDependence(), weight=weight, delay=delay)))) p.run(10) for weight, delay, connector, is_stdp, proj in projs: weights = proj.get("weight", "list", with_address=False) delays = proj.get("delay", "list", with_address=False) if not is_stdp: check_params(weight, weights) check_params(delay, delays) p.end()
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') plastic_spikes_numpy = neo_convertor.convert_spikes(plastic_spikes) numpy.save("plastic_spikes.npy", plastic_spikes_numpy) plastic_weights = plastic_ie_projection.get('weight', 'array') # Weights(format="array")
sim.Projection(pre_stim, pre_pop, ee_connector, synapse_type=synapse_type, receptor_type='excitatory') sim.Projection(post_stim, post_pop, ee_connector, synapse_type=synapse_type, receptor_type='excitatory') # Plastic Connections between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=20.0, tau_minus=50.0, A_plus=0.02, A_minus=0.02), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=1)) sim.Projection(pre_pop, post_pop, sim.OneToOneConnector(), synapse_type=stdp_model) # Record spikes pre_pop.record("spikes") post_pop.record("spikes") # Run simulation sim.run(sim_time)
def do_run(): # 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} delta_t = 10 time_between_pairs = 150 num_pre_pairs = 10 num_pairs = 100 num_post_pairs = 10 pop_size = 1 pairing_start_time = (num_pre_pairs * time_between_pairs) + delta_t pairing_end_time = pairing_start_time + (num_pairs * time_between_pairs) sim_time = pairing_end_time + (num_post_pairs * time_between_pairs) # +-------------------------------------------------------------------+ # | Creation of neuron populations | # +-------------------------------------------------------------------+ # Neuron populations pre_pop = sim.Population(pop_size, model, cell_params) post_pop = sim.Population(pop_size, model, cell_params) # Stimulating populations pre_stim = sim.Population(pop_size, sim.SpikeSourceArray, {'spike_times': [[i for i in range(0, sim_time, time_between_pairs)], ]}) post_stim = sim.Population(pop_size, sim.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 = sim.OneToOneConnector() synapse_type = sim.StaticSynapse(weight=2) sim.Projection(pre_stim, pre_pop, ee_connector, synapse_type=synapse_type, receptor_type='excitatory') sim.Projection(post_stim, post_pop, ee_connector, synapse_type=synapse_type, receptor_type='excitatory') # Plastic Connections between pre_pop and post_pop stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=20.0, tau_minus=50.0, A_plus=0.02, A_minus=0.02), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=1)) sim.Projection(pre_pop, post_pop, sim.OneToOneConnector(), synapse_type=stdp_model) # Record spikes pre_pop.record("spikes") post_pop.record("spikes") # Run simulation sim.run(sim_time) neo = pre_pop.get_data("spikes") pre_spikes = neo_convertor.convert_spikes(neo) neo = post_pop.get_data("spikes") post_spikes = neo_convertor.convert_spikes(neo) # End simulation on SpiNNaker sim.end() return (pre_spikes, post_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)
p.SpikeSourceArray(**spikeArray), label='excit_pop_ss_array')) # 0 populations.append(p.Population(nInhibNeurons, p.IF_curr_exp(**cell_params_lif), label='inhib_pop')) # 1 populations.append(p.Population(nExcitNeurons, p.IF_curr_exp(**cell_params_lif), label='excit_pop')) # 2 populations.append(p.Population(nTeachNeurons, p.SpikeSourceArray(**teachingSpikeArray), label='teaching_ss_array')) # 3 stdp_model = p.STDPMechanism( timing_dependence=p.extra_models.RecurrentRule( accumulator_depression=-6, accumulator_potentiation=3, mean_pre_window=10.0, mean_post_window=10.0, dual_fsm=True, A_plus=0.2, A_minus=0.2), weight_dependence=p.MultiplicativeWeightDependence(w_min=0.0, w_max=16.0), weight=baseline_excit_weight, delay=1) rng = NumpyRNG(seed=1) ext_delay_distr = RandomDistribution('normal', (1.5, 0.75), rng=rng) inh_delay_distr = RandomDistribution('normal', (0.75, 0.375), rng=rng) delay_distr_recurrent = RandomDistribution('uniform', [2.0, 8.0], rng=rng) weight_distr_ffwd = RandomDistribution('uniform', [0.5, 1.25], rng=rng) weight_distr_recurrent = RandomDistribution('uniform', [0.1, 0.2], rng=rng) projections.append( p.Projection(populations[stimulus], populations[excit], p.AllToAllConnector(), synapse_type=stdp_model))
my_model_my_threshold_pop = p.Population( 1, My_Model_Curr_Exp_My_Threshold(**myModelCurrExpMyThresholdParams), label="my_model_my_threshold_pop") p.Projection(input_pop, my_model_my_threshold_pop, p.OneToOneConnector(), receptor_type='excitatory', synapse_type=p.StaticSynapse(weight=weight)) my_model_stdp_pop = p.Population(1, My_Model_Curr_Exp(**myModelCurrExpParams), 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)) p.Projection(input_pop, my_model_stdp_pop, p.OneToOneConnector(), receptor_type='excitatory', synapse_type=p.StaticSynapse(weight=weight)) stdp_connection = p.Projection(input_pop, my_model_stdp_pop, p.OneToOneConnector(), synapse_type=stdp) my_model_pop.record(['v']) my_model_my_synapse_type_pop.record(['v']) my_model_my_additional_input_pop.record(['v'])
def test_potentiation_and_depression(self): p.setup(1) runtime = 100 initial_run = 1000 # to negate any initial conditions # STDP parameters a_plus = 0.01 a_minus = 0.01 tau_plus = 20 tau_minus = 20 plastic_delay = 3 initial_weight = 2.5 max_weight = 5 min_weight = 0 spike_times = [10, 50] spike_times2 = [30] for i in range(len(spike_times)): spike_times[i] += initial_run for i in range(len(spike_times2)): spike_times2[i] += initial_run # Spike source to send spike via plastic synapse pop_src1 = p.Population(1, p.SpikeSourceArray, {'spike_times': spike_times}, label="src1") # Spike source to send spike via static synapse to make # post-plastic-synapse neuron fire pop_src2 = p.Population(1, p.SpikeSourceArray, {'spike_times': spike_times2}, label="src2") # Post-plastic-synapse population pop_exc = p.Population(1, p.IF_curr_exp(), label="test") # Create projections p.Projection(pop_src1, pop_exc, p.OneToOneConnector(), p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory") p.Projection(pop_src2, pop_exc, p.OneToOneConnector(), p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory") syn_plas = p.STDPMechanism( timing_dependence=p.SpikePairRule(), weight_dependence=p.AdditiveWeightDependence(w_min=min_weight, w_max=max_weight), weight=initial_weight, delay=plastic_delay) plastic_synapse = p.Projection(pop_src1, pop_exc, p.OneToOneConnector(), synapse_type=syn_plas) pop_src1.record('all') pop_exc.record("all") p.run(initial_run + runtime) weights = [] weights.append( plastic_synapse.get('weight', 'list', with_address=False)[0]) # pre_spikes = pop_src1.get_data('spikes') # v = pop_exc.get_data('v') spikes = pop_exc.get_data('spikes') potentiation_time_1 = (spikes.segments[0].spiketrains[0].magnitude[0] + plastic_delay) - spike_times[0] potentiation_time_2 = (spikes.segments[0].spiketrains[0].magnitude[1] + plastic_delay) - spike_times[0] depression_time_1 = spike_times[1] - ( spikes.segments[0].spiketrains[0].magnitude[0] + plastic_delay) depression_time_2 = spike_times[1] - ( spikes.segments[0].spiketrains[0].magnitude[1] + plastic_delay) potentiation_1 = max_weight * a_plus * \ math.exp(-potentiation_time_1/tau_plus) potentiation_2 = max_weight * a_plus * \ math.exp(-potentiation_time_2/tau_plus) depression_1 = max_weight * a_minus * \ math.exp(-depression_time_1/tau_minus) depression_2 = max_weight * a_minus * \ math.exp(-depression_time_2/tau_minus) new_weight_exact = (initial_weight + potentiation_1 + potentiation_2 - depression_1 - depression_2) print("Pre neuron spikes at: {}".format(spike_times)) print("Post-neuron spikes at: {}".format( spikes.segments[0].spiketrains[0].magnitude)) print("Potentiation time differences: {}, {},\ \nDepression time difference: {}, {}".format( potentiation_time_1, potentiation_time_2, depression_time_1, depression_time_2)) print("Ammounts to potentiate: {}, {},\ \nAmount to depress: {}, {},".format(potentiation_1, potentiation_2, depression_1, depression_2)) print("New weight exact: {}".format(new_weight_exact)) print("New weight SpiNNaker: {}".format(weights[0])) self.assertTrue( numpy.allclose(weights[0], new_weight_exact, atol=0.001)) p.end()
receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=2)) # **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.extra_models.PfisterSpikeTriplet( tau_plus=16.8, tau_minus=33.7, tau_x=101, tau_y=114, A_plus=param_scale * 0.0, A_minus=param_scale * 7.1e-3), weight_dependence=sim.extra_models.WeightDependenceAdditiveTriplet( w_min=0.0, w_max=1.0, A3_plus=param_scale * 6.5e-3, A3_minus=param_scale * 0.0), weight=start_w, delay=1) projections[-1].append( sim.Projection(pre_pop, post_pop, sim.OneToOneConnector(), synapse_type=stdp_model)) print("Simulating for %us" % (sim_time / 1000))
def potentiation_and_depression(self): p.setup(1) runtime = 100 initial_run = 1000 # to negate any initial conditions # STDP parameters a_plus = 0.01 a_minus = 0.01 tau_plus = 20 tau_minus = 20 plastic_delay = 3 initial_weight = 2.5 max_weight = 5 min_weight = 0 pre_spikes = [10, 50] extra_spikes = [30] for i in range(len(pre_spikes)): pre_spikes[i] += initial_run for i in range(len(extra_spikes)): extra_spikes[i] += initial_run # Spike source to send spike via plastic synapse pre_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': pre_spikes}, label="pre") # Spike source to send spike via static synapse to make # post-plastic-synapse neuron fire extra_pop = p.Population(1, p.SpikeSourceArray, {'spike_times': extra_spikes}, label="extra") # Post-plastic-synapse population post_pop = p.Population(1, p.IF_curr_exp(), label="post") # Create projections p.Projection( pre_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory") p.Projection( extra_pop, post_pop, p.OneToOneConnector(), p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory") syn_plas = p.STDPMechanism( timing_dependence=p.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=p.AdditiveWeightDependence(w_min=min_weight, w_max=max_weight), weight=initial_weight, delay=plastic_delay) plastic_synapse = p.Projection(pre_pop, post_pop, p.OneToOneConnector(), synapse_type=syn_plas, receptor_type='excitatory') # Record the spikes post_pop.record("spikes") # Run p.run(initial_run + runtime) # Get the weights weights = plastic_synapse.get('weight', 'list', with_address=False) # Get the spikes post_spikes = numpy.array( post_pop.get_data('spikes').segments[0].spiketrains[0].magnitude) # End the simulation as all information gathered p.end() new_weight_exact = calculate_spike_pair_additive_stdp_weight( pre_spikes, post_spikes, initial_weight, plastic_delay, max_weight, a_plus, a_minus, tau_plus, tau_minus) print("Pre neuron spikes at: {}".format(pre_spikes)) print("Post-neuron spikes at: {}".format(post_spikes)) target_spikes = [1014, 1032, 1053] self.assertListEqual(list(post_spikes), target_spikes) print("New weight exact: {}".format(new_weight_exact)) print("New weight SpiNNaker: {}".format(weights)) self.assertTrue(numpy.allclose(weights, new_weight_exact, rtol=0.001))
'input_type': input_type, 'random_partner': args.random_partner, 'lesion': args.lesion, 'argparser': vars(args), 'fixed_signal_value': args.fixed_signal_value } # +-------------------------------------------------------------------+ # | Initial network setup | # +-------------------------------------------------------------------+ # Connections stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=g_max), weight=g_max) partner_selection_last_neuron = sim.LastNeuronSelection() formation_distance = sim.DistanceDependentFormation( grid=grid, # spatial org of neurons sigma_form_forward= sigma_form_forward, # spread of feadforward receptive field sigma_form_lateral=sigma_form_lateral, # spread of lateral receptive field p_form_forward=p_form_forward, # feedforward formation probability p_form_lateral=p_form_lateral # lateral formation probability ) elimination_weight = sim.RandomByWeightElimination( threshold=g_max /
start_weight = RandomDistribution('uniform', (av_weight - ten_perc, av_weight + ten_perc)) stdp_weights = RandomDistribution('uniform', (av_weight - ten_perc, av_weight + ten_perc)) stdp_delays = RandomDistribution('uniform', (1, 51.)) time_dep = sim.extra_models.SpikeNearestPairRule( tau_plus=tau_plus, tau_minus=tau_minus, #time_dep =sim.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=a_plus, A_minus=a_minus) weight_dep = sim.AdditiveWeightDependence(w_min=w_min, w_max=w_max) stdp = sim.STDPMechanism(time_dep, weight_dep, weight=stdp_weights, delay=stdp_delays) print("************ ------------ using stdp ------------ ***********") print("tau_plus = %f\ttau_minus = %f" % (tau_plus, tau_minus)) print("w_min = %f\tw_max = %f\ta_plus = %f\ta_minus = %f" % (w_min, w_max, a_plus, a_minus)) #aiming for around 50 post connections (one for each delay) #num_post_conn = 50.#10.#1000. #p_connect = num_post_conn/AC_pop_size #1.# 0.005 # 0.05 #num_incoming_connections = (num_post_conn * AN_pop_size)/AC_pop_size#AN_pop_size# p_connect = 0.35 fixed_type = sim.StaticSynapse(weight=w2s_target / 4., delay=stdp_delays) # ic2ac_proj = sim.Projection(