def getSynapseType(lat_conn_strength_params, use_stdp, tau_plus=20.0, tau_minus=20.0, A_plus=0.01, A_minus=0.012, w_min=0, w_max=1.0, static_weight=0.02): """ For getting the required synapse type, fixed or STDP Arguments: lat_conn_strength_params, parameters for the uniform distribution. The connections evolve during training anyway. use_stdp, flag the other Arguments are defaults. Return: the synapse_type to use """ stdp_weight_distn = pynn.random.RandomDistribution( 'uniform', lat_conn_strength_params) stdp = pynn.STDPMechanism( weight=stdp_weight_distn, timing_dependence=pynn.SpikePairRule(tau_plus=tau_plus, tau_minus=tau_minus, A_plus=A_plus, A_minus=A_minus), weight_dependence=pynn.AdditiveWeightDependence(w_min=w_min, w_max=w_max)) synapse_to_use = stdp if use_stdp else pynn.StaticSynapse( weight=static_weight) return synapse_to_use
def test_stdp_set_tau_minus(self): """cf https://github.com/NeuralEnsemble/PyNN/issues/423""" intended_tau_minus = 18.9 stdp_model = sim.STDPMechanism( timing_dependence=sim.SpikePairRule(tau_plus=16.7, tau_minus=intended_tau_minus, A_plus=0.005, A_minus=0.005), weight_dependence=sim.AdditiveWeightDependence(w_min=0.0, w_max=1.0), weight=0.5, delay=1.0, dendritic_delay_fraction=1.0) prj = sim.Projection(self.p1, self.p2, self.all2all, synapse_type=stdp_model) actual_tau_minus = nest.GetStatus([prj.post[0]], "tau_minus")[0] self.assertEqual(intended_tau_minus, actual_tau_minus)
def connect_layers(firstLayer, secondLayer): # === Parameters for STDP mechanism === # === Timing dependence === # Time constant of the positive part of the STDP curve, in milliseconds. tau_plus = 20.0 # Time constant of the negative part of the STDP curve, in milliseconds. tau_minus = 20.0 # Amplitude of the positive part of the STDP curve. A_plus = 0.006 # Amplitude of the negative part of the STDP curve. A_minus = 0.0055 # === Weight dependence === # Minimum synaptic weight w_min = 0.0 # Maximum synaptic weight w_max = 0.1 # Default weight w_default = 0.0 # === Delay === delay = 0.1 # Synapses to use later for testing global synapses # The amplitude of the weight change is independent of the current weight. # If the new weight would be less than w_min it is set to w_min. If it would be greater than w_max it is set to w_max. stdp_synapse = 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=w_min, w_max=w_max), dendritic_delay_fraction=1.0, weight=w_default, delay=delay) # Save synapses onto a global variable synapses = sim.Projection(inputLayer, outputLayer, sim.AllToAllConnector(), synapse_type=stdp_synapse)
def recognizer_weights_from(feature_np_array): """ Builds a network from the firing rates of the given feature_np_array for the input neurons and learns the weights to recognize the image through STDP. """ in_p = create_spike_source_layer_from(feature_np_array).population out_p = sim.Population(1, sim.IF_curr_exp(i_offset=5)) synapse = sim.STDPMechanism( weight=-0.2, timing_dependence=sim.SpikePairRule(tau_plus=20.0, tau_minus=20.0, A_plus=0.01, A_minus=0.005), weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=0.4)) proj = sim.Projection(in_p, out_p, sim.AllToAllConnector(), synapse) sim.run(500) return proj.get('weight', 'array')
temp_popv.set('rate', teaching_rate) TeachingPoission.append(pop) #print ImagePoission[10].get('start') ee_connector = p.OneToOneConnector(weights=3.0) for i in range(num_train * num_epo * 1): p.Projection(ImagePoission[i], pop_input, ee_connector, target='excitatory') pop_output = p.Population(num_output, p.IF_curr_exp, cell_params_lif) weight_max = 1.3 stdp_model = p.STDPMechanism( timing_dependence=p.SpikePairRule(tau_plus=10., tau_minus=10.0), weight_dependence=p.MultiplicativeWeightDependence(w_min=0.0, w_max=weight_max, A_plus=0.01, A_minus=0.01) #AdditiveWeightDependence ) ''' weight_distr = p.RandomDistribution(distribution='normal',parameters=[1,0.1]) ''' if run_i == 0: stdp_weight = 0.0 directory = 'weight%d' % par_start if not os.path.exists(directory): os.makedirs(directory) else: stdp_weight = np.load('%s/weight_%d.npy' % (directory, (run_i - 1))) proj_stdp = p.Projection( #pop_input, pop_output, p.AllToAllConnector(weights = weight_distr),
zip(c2_training_spikes, c2_validation_spikes): # ============= Training ============= # print('Construct training network') sim.setup(threads=args.threads, min_delay=.1) # Create the C2 layer and connect it to the single output neuron training_spiketrains = [[s for s in st] for st in training_pair[1]] C2_populations, compound_C2_population =\ create_C2_populations(training_spiketrains) out_p = sim.Population(1, sim.IF_curr_exp(tau_refrac=.1)) stdp_weight = 7 / s2_prototype_cells stdp = sim.STDPMechanism( weight=stdp_weight, timing_dependence=sim.SpikePairRule(tau_plus=20.0, tau_minus=26.0, A_plus=stdp_weight / 5, A_minus=stdp_weight / 4.48), weight_dependence=sim.AdditiveWeightDependence(w_min=0.0, w_max=15.8 * stdp_weight)) learn_proj = sim.Projection(compound_C2_population, out_p, sim.AllToAllConnector(), stdp) epoch = training_pair[0] print('Simulating for epoch', epoch) # Record the spikes for visualization purposes and to count the number of # fired spikes # compound_C2_population.record('spikes') out_p.record(['spikes', 'v'])
args = parser.parse_args() pynn.setup(timestep=0.1, min_delay=2.0) if not args.debug: # define target cell target_cell = pynn.create(pynn.IF_cond_exp, {'i_offset':0.11, 'tau_refrac':3.0, 'v_thresh':-51.0}) # define inhibitory and excitatory populations inhib_rates, excit_rates = getRatesForInhibExcit(args.inhib_rates_lower, args.excit_rates_lower, args.num_inhib, args.num_excit) inhib_source = pynn.Population(args.num_inhib, pynn.SpikeSourcePoisson(rate=inhib_rates), label="inhib_input") excit_source = pynn.Population(args.num_excit, pynn.SpikeSourcePoisson(rate=excit_rates), label="excit_input") # define stdp rules, parameters could be messed around with here. stdp = pynn.STDPMechanism(weight=0.02, # this is the initial value of the weight timing_dependence=pynn.SpikePairRule(tau_plus=20.0, tau_minus=20.0, A_plus=0.01, A_minus=0.012), weight_dependence=pynn.AdditiveWeightDependence(w_min=0, w_max=0.04)) synapse_to_use = stdp if args.stdp else pynn.StaticSynapse(weight=0.02) # connect inhibitory and excitatory sources to target. Could connect inhib to excit? inhib_conn = pynn.Projection(inhib_source, target_cell, connector=pynn.AllToAllConnector(), synapse_type=synapse_to_use, receptor_type='inhibitory') excit_conn = pynn.Projection(excit_source, target_cell, connector=pynn.AllToAllConnector(), synapse_type=synapse_to_use, receptor_type='excitatory') # tell the sim what to record target_cell.record(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) if args.record_target_spikes else target_cell.record(['v', 'gsyn_exc', 'gsyn_inh']) inhib_source.record('spikes') excit_source.record('spikes') # record the weights inhib_weight_recorder = WeightRecorder(sampling_interval=1.0, projection=inhib_conn) excit_weight_recorder = WeightRecorder(sampling_interval=1.0, projection=excit_conn)