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 = 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)
    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)
    p.Projection(input,
                 relay_on,
                 p.OneToOneConnector(weights=1),
                 synapse_dynamics=s_d_LGN,
                 target='excitatory')

    p.run(1000)
    p.end()
示例#2
0
# +-------------------------------------------------------------------+
# | Initial network setup                                             |
# +-------------------------------------------------------------------+

# Putting this populations on chip 0 1 makes it easier to copy the provenance
# data somewhere else
# target_pop.set_constraint(PlacerChipAndCoreConstraint(0, 1))
# Connections
# Plastic Connections between pre_pop and post_pop

stdp_model = sim.STDPMechanism(
    timing_dependence=sim.SpikePairRule(tau_plus=tau_plus,
                                        tau_minus=tau_minus),
    weight_dependence=sim.AdditiveWeightDependence(
        w_min=0,
        w_max=g_max,
        # A_plus=0.02, A_minus=0.02
        A_plus=a_plus,
        A_minus=a_minus))

if args.case == CASE_CORR_AND_REW:
    structure_model_w_stdp = sim.StructuralMechanism(
        stdp_model=stdp_model,
        weight=g_max,
        s_max=s_max,
        grid=grid,
        f_rew=f_rew,
        lateral_inhibition=args.lateral_inhibition,
        random_partner=args.random_partner,
        p_elim_dep=p_elim_dep,
        p_elim_pot=p_elim_pot,
        sigma_form_forward=sigma_form_forward,
    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),
            weight_dependence=p.AdditiveWeightDependence(w_min=0.0,
                                                         w_max=1.0,
                                                         A_plus=0.005,
                                                         A_minus=0.005),
        )

        # Plastic Connection between pre_pop and post_pop
        stdp_model2 = p.STDPMechanism(
            timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7),
            weight_dependence=p.AdditiveWeightDependence(w_min=0.0,
                                                         w_max=1.0,
                                                         A_plus=0.005,
                                                         A_minus=0.005),
        )

        # Plastic Connection between pre_pop and post_pop
        stdp_model3 = p.STDPMechanism(
            timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7),
            weight_dependence=p.MultiplicativeWeightDependence(w_min=0.0,
                                                               w_max=1.0,
                                                               A_plus=0.005,
                                                               A_minus=0.005),
        )

        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)))
        pop = p.Projection(populations[1], populations[0],
                           p.FromListConnector(injectionConnection))
        projections.append(pop)
        synapse_dynamics = p.SynapseDynamics(slow=stdp_model1)
        pop = p.Projection(populations[2],
                           populations[0],
                           p.FromListConnector(injectionConnection),
                           synapse_dynamics=synapse_dynamics)
        projections.append(pop)
        # This is expected to raise a SynapticConfigurationException
        synapse_dynamics = p.SynapseDynamics(slow=stdp_model2)
        pop = p.Projection(populations[3],
                           populations[0],
                           p.FromListConnector(injectionConnection),
                           synapse_dynamics=synapse_dynamics)
        projections.append(pop)
        synapse_dynamics = p.SynapseDynamics(slow=stdp_model3)
        pop = p.Projection(populations[4],
                           populations[0],
                           p.FromListConnector(injectionConnection),
                           synapse_dynamics=synapse_dynamics)
        projections.append(pop)
示例#4
0
def do_run():
    # SpiNNaker setup
    p.setup(timestep=1.0, min_delay=1.0, max_delay=10.0)

    # +-------------------------------------------------------------------+
    # | General Parameters                                                |
    # +-------------------------------------------------------------------+

    # Population parameters
    model = p.IF_curr_exp
    # model = sim.IF_cond_exp
    """
    cell_params = {'i_offset' : .1,    'tau_refrac' : 3.0, 'v_rest' : -65.0,
                   'v_thresh' : -51.0,  'tau_syn_E'  : 2.0,
                   'tau_syn_I': 5.0,    'v_reset'    : -70.0}
    """
    cell_params = {
        'cm': 0.25,  # nF
        '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 = p.Population(pop_size, model, cell_params)
    post_pop = p.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(
            p.Population(
                pop_size, p.SpikeSourcePoisson, {
                    'rate': in_rate,
                    'start': start_test_pre_pairing + ISI * (i),
                    'duration': dur_stim
                }))

    # Pairing protocol : pre_pop and post_pop are stimulated with a 10 ms
    # difference
    for i in range(n_stim_pairing):
        IAddPre.append(
            p.Population(
                pop_size, p.SpikeSourcePoisson, {
                    'rate': in_rate,
                    'start': start_pairing + ISI * (i),
                    'duration': dur_stim
                }))
        IAddPost.append(
            p.Population(
                pop_size, p.SpikeSourcePoisson, {
                    'rate': in_rate,
                    'start': start_pairing + ISI * (i) + 10.,
                    'duration': dur_stim
                }))

    # 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(
            p.Population(pop_size, p.SpikeSourcePoisson, {
                'rate': in_rate,
                'start': start,
                'duration': dur_stim
            }))

    # Noise inputs
    INoisePre = p.Population(pop_size,
                             p.SpikeSourcePoisson, {
                                 'rate': e_rate,
                                 'start': 0,
                                 'duration': simtime
                             },
                             label="expoisson")
    params = {'rate': e_rate, 'start': 0, 'duration': simtime}
    INoisePost = p.Population(pop_size,
                              p.SpikeSourcePoisson,
                              params,
                              label="expoisson")

    # +-------------------------------------------------------------------+
    # | Creation of connections                                           |
    # +-------------------------------------------------------------------+

    # Connection parameters
    JEE = 3.

    # Connection type between noise poisson generator and
    # excitatory populations
    ee_connector = p.OneToOneConnector(weights=JEE * 0.05)

    # Noise projections
    p.Projection(INoisePre, pre_pop, ee_connector, target='excitatory')
    p.Projection(INoisePost, post_pop, ee_connector, target='excitatory')

    # Additional Inputs projections
    for i in range(len(IAddPre)):
        p.Projection(IAddPre[i], pre_pop, ee_connector, target='excitatory')
    for i in range(len(IAddPost)):
        p.Projection(IAddPost[i], post_pop, ee_connector, target='excitatory')

    # Plastic Connections between pre_pop and post_pop
    timing_dependence = p.SpikePairRule(tau_plus=20., tau_minus=50.0)
    weight_dependence = p.AdditiveWeightDependence(w_min=0,
                                                   w_max=0.9,
                                                   A_plus=0.02,
                                                   A_minus=0.02)
    stdp_model = p.STDPMechanism(timing_dependence=timing_dependence,
                                 weight_dependence=weight_dependence)

    plastic_projection = \
        p.Projection(pre_pop, post_pop,
                     p.FixedProbabilityConnector(p_connect=0.5),
                     synapse_dynamics=p.SynapseDynamics(slow=stdp_model)
                     )

    # +-------------------------------------------------------------------+
    # | Simulation and results                                            |
    # +-------------------------------------------------------------------+

    # Record neurons' potentials
    pre_pop.record_v()
    post_pop.record_v()

    # Record spikes
    pre_pop.record()
    post_pop.record()

    # Run simulation
    p.run(simtime)

    weights = plastic_projection.getWeights()

    pre_spikes = pre_pop.getSpikes(compatible_output=True)
    post_spikes = post_pop.getSpikes(compatible_output=True)

    p.end()

    return (weights, pre_spikes, post_spikes)
#dummy_stim = sim.Population(1,sim.SpikeSourceArray,{'spike_times': [sim_time]},label="dummy")

nn_pc = 10 # number of purkinje cells (and inferior olive cells)
teaching_stim = sim.Population(nn_pc, sim.SpikeSourceArray,
    {'spike_times': [[teaching_time+j*ts for j in range(i)] for i in range(nn_pc)]},label="Inferior Olives")

# Neuron populations
population = sim.Population(nn_pc, model, cell_params, label="Purkinjes")
population.record("spikes")
population2 = sim.Population(nn_pc, sim.IF_curr_exp, cell_params, label="fake purk")
population2.record("spikes")

# Plastic Connection between pre_pop and post_pop
stdp_model = sim.STDPMechanism(
    timing_dependence = TimingDependenceCerebellum(tau=tau, peak_time=peak_time),
    weight_dependence = sim.AdditiveWeightDependence(w_min=1.0, w_max=15.0, A_plus=0.5, A_minus=0.01)
)

#stdp_model = sim.STDPMechanism(
#    timing_dependence = sim.SpikePairRule(tau_plus=tau, tau_minus=tau),
#    weight_dependence = sim.AdditiveWeightDependence(w_min=1.0, w_max=15.0, A_plus=0.1, A_minus=0.1)
#)


# Connections between spike sources and neuron populations
    ####### SET HERE THE PARALLEL FIBER-PURKINJE CELL LEARNING RULE
ee_connector = sim.AllToAllConnector(weights=1.0)
projection_pf = sim.Projection(pre_stim, population, ee_connector,
                                         synapse_dynamics=sim.SynapseDynamics(slow=stdp_model),
                                         target='excitatory')
示例#6
0
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(weights=2)

    sim.Projection(pre_stim, pre_pop, ee_connector, target='excitatory')
    sim.Projection(post_stim, 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.0, tau_minus=50.0),
      weight_dependence=sim.AdditiveWeightDependence(w_min=0, w_max=1,
                                                     A_plus=0.02,
                                                     A_minus=0.02))

    sim.Projection(pre_pop, post_pop, sim.OneToOneConnector(),
                   synapse_dynamics=sim.SynapseDynamics(slow=stdp_model))

    # Record spikes
    pre_pop.record()
    post_pop.record()

    # Run simulation
    sim.run(sim_time)

    pre_spikes = pre_pop.getSpikes(compatible_output=True)
    post_spikes = post_pop.getSpikes(compatible_output=True)

    # End simulation on SpiNNaker
    sim.end()

    return (pre_spikes, post_spikes)
示例#7
0
def run_sim(num_pre, num_post, spike_times, run_time, weight=5.6, delay=40., gom=False,
            conn_type='one2one', use_stdp=False, mad=False, prob=0.5):
    model = p.IF_curr_exp
    p.setup( timestep = 1.0, min_delay = 1.0, max_delay = 144.0 )
    # if num_pre <= 10:
    #     p.set_number_of_neurons_per_core(model, 4)
    #     p.set_number_of_neurons_per_core(p.SpikeSourceArray, 5)
    # elif 10 < num_pre <= 50:
    #     p.set_number_of_neurons_per_core(model, 20)
    #     p.set_number_of_neurons_per_core(p.SpikeSourceArray, 21)
    # elif 50 < num_pre <= 100:
    #     p.set_number_of_neurons_per_core(model, 50)
    #     p.set_number_of_neurons_per_core(p.SpikeSourceArray, 51)
    # else:
    if use_stdp:
        p.set_number_of_neurons_per_core(model, 150)

    p.set_number_of_neurons_per_core(p.SpikeSourceArray, 2000)


    cell_params_lif = {  'cm'        : 1.0, # nF
                         'i_offset'  : 0.00,
                         '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'  : -60.0
                      }

    cell_params_pos = {
        'spike_times': spike_times,
    }
    w2s = weight
    dly = delay
    rng = NumpyRNG( seed = 1 )
    if use_stdp:
        td = p.SpikePairRule(tau_minus=1., tau_plus=1.)
        wd = p.AdditiveWeightDependence(w_min=0, w_max=20., A_plus=0.0, A_minus=0.0)
        stdp = p.STDPMechanism(timing_dependence=td, weight_dependence=wd)
        syn_dyn = p.SynapseDynamics(slow=stdp)
    else:
        syn_dyn = None

    sink = p.Population( num_post, model, cell_params_lif, label='sink')
    # sink1 = p.Population( nNeuronsPost, model, cell_params_lif, label='sink1')

    source0 = p.Population( num_pre, p.SpikeSourceArray, cell_params_pos,
                            label='source_0')

    # source1 = p.Population( nNeurons, p.SpikeSourceArray, cell_params_pos,
    #                         label='source_1')


    if conn_type == 'one2one':
        conn = p.OneToOneConnector(weights=w2s, delays=dly, generate_on_machine=gom)
    elif conn_type == 'all2all':
        conn = p.AllToAllConnector(weights=w2s, delays=dly, generate_on_machine=gom)
    elif conn_type == 'fixed_prob':
        conn = p.FixedProbabilityConnector(prob, weights=w2s, delays=dly,
                                           generate_on_machine=gom)
    else:
        raise Exception("Not a valid connector for test")

    proj = p.Projection( source0, sink, conn, target='excitatory',
                         synapse_dynamics=syn_dyn,
                         label=' source 0 to sink - EXC - delayed')


    # sink.record_v()
    # sink.record_gsyn()
    sink.record()


    print("Running for {} ms".format(run_time))
    t0 = time.time()
    p.run(run_time)
    time_to_run = time.time() - t0
    v = None
    gsyn = None
    spikes = None

    # v = np.array(sink.get_v(compatible_output=True))
    # gsyn = sink.get_gsyn(compatible_output=True)
    spikes = sink.getSpikes(compatible_output=True)
    w = proj.getWeights(format='array')
    p.end()

    return v, gsyn, spikes, w, time_to_run
for inpop, outpop in zip(PuC_layer_pop, DCN_layer_pop):
    sim.Projection(inpop,
                   outpop,
                   sim.FromListConnector(connlist_PuC_DCN),
                   target="inhibitory",
                   label="proj_" + inpop.label + "_" + outpop.label)
    pass

## Plastic synapses (GrC to PuC)
tau = 60.  #450. # 60.
peak_time = 100.  #100.
# Create cerebellar learning rule
stdp_model = sim.STDPMechanism(
    timing_dependence=TimingDependenceCerebellum(tau=tau, peak_time=peak_time),
    weight_dependence=sim.AdditiveWeightDependence(w_min=0.0,
                                                   w_max=W_MAX,
                                                   A_plus=0.01,
                                                   A_minus=0.01))
#weight_dependence = sim.AdditiveWeightDependence(w_min=0.0, w_max=W_MAX, A_plus=0.0015, A_minus=0.0020)
weigth_first = []
proj_GrC_PuC = []
for outpop in PuC_layer_pop:
    proj_GrC_PuC.append(
        sim.Projection(
            GrC_layer_pop[0],
            outpop,
            sim.FixedProbabilityConnector(1.0, weights=weight_dist_GrC_PuC),
            synapse_dynamics=sim.SynapseDynamics(slow=stdp_model),
            target="excitatory",
            label="proj_" + GrC_layer_pop[0].label + "_" + outpop.label))
    weigth_first.append(proj_GrC_PuC[-1].getWeights())