コード例 #1
0
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
コード例 #2
0
ファイル: test_nest.py プロジェクト: stjordanis/PyNN
 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)
コード例 #3
0
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)
コード例 #4
0
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')
    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'])

    # Let the simulation run to "fill" the layer pipeline with spikes
    sim.run(40)
コード例 #6
0
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)