Exemple #1
0
def structural_eliminate_to_empty():
    p.setup(1.0)
    stim = p.Population(9, p.SpikeSourceArray(range(10)), label="stim")

    # These populations should experience elimination
    pop = p.Population(9, p.IF_curr_exp(), label="pop")

    # Make a full list

    # Elimination with random selection (0 probability formation)
    proj = p.Projection(
        stim, pop, p.AllToAllConnector(),
        p.StructuralMechanismStatic(
            partner_selection=p.RandomSelection(),
            formation=p.DistanceDependentFormation([3, 3], 0.0),
            elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0),
            f_rew=1000,
            initial_weight=4.0,
            initial_delay=3.0,
            s_max=9,
            seed=0,
            weight=0.0,
            delay=1.0))

    pop.record("rewiring")

    p.run(1000)

    # Get the final connections
    conns = list(proj.get(["weight", "delay"], "list"))

    rewiring = pop.get_data("rewiring")
    formation_events = rewiring.segments[0].events[0]
    elimination_events = rewiring.segments[0].events[1]

    num_forms = len(formation_events.times)
    num_elims = len(elimination_events.times)

    first_elim = elimination_events.labels[0]

    p.end()

    # These should have no connections since all should be eliminated
    assert (len(conns) == 0)
    assert (num_elims == 81)
    assert (num_forms == 0)
    assert (first_elim == "7_5_elimination")
Exemple #2
0
def structural_formation_to_full():
    p.setup(1.0)
    stim = p.Population(4, p.SpikeSourceArray(range(10)), label="stim")

    # These populations should experience formation
    pop = p.Population(4, p.IF_curr_exp(), label="pop")

    # Formation with random selection (0 probability elimination), setting
    # with_replacement=False means an all-to-all connection will be the result
    proj = p.Projection(
        stim, pop, p.FromListConnector([]),
        p.StructuralMechanismStatic(
            partner_selection=p.LastNeuronSelection(),
            formation=p.DistanceDependentFormation([2, 2], 1.0),
            elimination=p.RandomByWeightElimination(4.0, 0, 0),
            f_rew=1000,
            initial_weight=4.0,
            initial_delay=3.0,
            s_max=4,
            seed=0,
            weight=0.0,
            delay=1.0,
            with_replacement=False))

    pop.record("rewiring")

    p.run(1000)

    # Get the final connections
    conns = proj.get(["weight", "delay"], "list")

    rewiring = pop.get_data("rewiring")

    formation_events = rewiring.segments[0].events[0]
    elimination_events = rewiring.segments[0].events[1]

    num_forms = len(formation_events.times)
    num_elims = len(elimination_events.times)

    first_f = formation_events.labels[0]

    p.end()

    return conns, num_forms, num_elims, first_f
def mission_impossible_2():
    sim.setup(0.1, time_scale_factor=1)

    # Can't do structural on multiple synapse cores
    source = sim.Population(1, sim.SpikeSourcePoisson(rate=10))
    pop = sim.Population(128,
                         sim.IF_curr_exp(),
                         additional_parameters={
                             "splitter":
                             SplitterAbstractPopulationVertexNeuronsSynapses(2)
                         })

    sim.Projection(
        source, pop, sim.FromListConnector([]),
        sim.StructuralMechanismStatic(sim.RandomSelection(),
                                      sim.DistanceDependentFormation(),
                                      sim.RandomByWeightElimination(0.5)))

    with pytest.raises(SynapticConfigurationException):
        sim.run(100)
Exemple #4
0
                                        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 /
    2.,  # Use same weight as initial weight for static connections
    prob_elim_depressed=p_elim_dep,
    prob_elim_potentiated=p_elim_pot)

if args.case == CASE_CORR_AND_REW:
    structure_model_w_stdp = sim.StructuralMechanismSTDP(
        # Partner selection, formation and elimination rules from above
        partner_selection_last_neuron,
        formation_distance,
        elimination_weight,
        # Use this weight when creating a new synapse
        initial_weight=g_max,
        # Use this weight for synapses at start of simulation
        weight=g_max,
        # Use this delay when creating a new synapse
        initial_delay=args.delay,
def structural_shared():
    p.setup(1.0)
    pre_spikes = numpy.array(range(0, 10, 2))
    A_plus = 0.01
    A_minus = 0.01
    tau_plus = 20.0
    tau_minus = 20.0
    w_min = 0.0
    w_max = 5.0
    w_init = 5.0
    delay_init = 2.0
    stim = p.Population(1, p.SpikeSourceArray(pre_spikes), label="stim")
    pop = p.Population(1, p.IF_curr_exp(), label="pop")
    pop_2 = p.Population(1, p.IF_curr_exp(), label="pop_2")
    pop_3 = p.Population(1, p.IF_curr_exp(), label="pop_3")
    pop_4 = p.Population(1, p.IF_curr_exp(), label="pop_4")
    pop.record("spikes")
    pop_2.record("spikes")
    struct_pl_static = p.StructuralMechanismStatic(
        partner_selection=p.LastNeuronSelection(),
        formation=p.DistanceDependentFormation([1, 1], 1.0),
        elimination=p.RandomByWeightElimination(2.0, 0, 0),
        f_rew=1000, initial_weight=w_init, initial_delay=delay_init,
        s_max=1, seed=0, weight=0.0, delay=1.0)
    struct_pl_stdp = p.StructuralMechanismSTDP(
            partner_selection=p.LastNeuronSelection(),
            formation=p.DistanceDependentFormation([1, 1], 0.0),
            elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0),
            timing_dependence=p.SpikePairRule(
                tau_plus, tau_minus, A_plus, A_minus),
            weight_dependence=p.AdditiveWeightDependence(w_min, w_max),
            f_rew=1000, initial_weight=2.0, initial_delay=5.0,
            s_max=1, seed=0, weight=0.0, delay=1.0)
    proj = p.Projection(
        stim, pop, p.FromListConnector([]), struct_pl_static)
    proj_2 = p.Projection(
        stim, pop_2, p.FromListConnector([]), struct_pl_static)
    proj_3 = p.Projection(
        stim, pop_3, p.FromListConnector([(0, 0)]), struct_pl_stdp)
    proj_4 = p.Projection(
        stim, pop_4, p.FromListConnector([(0, 0)]), struct_pl_stdp)
    p.Projection(pop_3, pop_4, p.AllToAllConnector(),
                 p.StaticSynapse(weight=1, delay=3))
    p.run(10)

    conns = list(proj.get(["weight", "delay"], "list"))
    conns_2 = list(proj_2.get(["weight", "delay"], "list"))
    conns_3 = list(proj_3.get(["weight", "delay"], "list"))
    conns_4 = list(proj_4.get(["weight", "delay"], "list"))

    p.end()

    print(conns)
    print(conns_2)
    print(conns_3)
    print(conns_4)

    assert(len(conns) == 1)
    assert(tuple(conns[0]) == (0, 0, w_init, delay_init))
    assert(len(conns_2) == 1)
    assert(tuple(conns_2[0]) == (0, 0, w_init, delay_init))
    assert(len(conns_3) == 0)
    assert(len(conns_4) == 0)
def structural_with_stdp():
    p.setup(1.0)
    pre_spikes = numpy.array(range(0, 10, 2))
    pre_spikes_last_neuron = pre_spikes[pre_spikes > 0]
    A_plus = 0.01
    A_minus = 0.01
    tau_plus = 20.0
    tau_minus = 20.0
    w_min = 0.0
    w_max = 5.0
    w_init_1 = 5.0
    delay_1 = 2.0
    w_init_2 = 4.0
    delay_2 = 1.0
    stim = p.Population(1, p.SpikeSourceArray(pre_spikes), label="stim")
    pop = p.Population(1, p.IF_curr_exp(), label="pop")
    pop_2 = p.Population(1, p.IF_curr_exp(), label="pop_2")
    pop_3 = p.Population(1, p.IF_curr_exp(), label="pop_3")
    pop_4 = p.Population(1, p.IF_curr_exp(), label="pop_4")
    pop.record("spikes")
    pop_2.record("spikes")
    proj = p.Projection(
        stim, pop, p.FromListConnector([]), p.StructuralMechanismSTDP(
            partner_selection=p.LastNeuronSelection(),
            formation=p.DistanceDependentFormation([1, 1], 1.0),
            elimination=p.RandomByWeightElimination(2.0, 0, 0),
            timing_dependence=p.SpikePairRule(
                tau_plus, tau_minus, A_plus, A_minus),
            weight_dependence=p.AdditiveWeightDependence(w_min, w_max),
            f_rew=1000, initial_weight=w_init_1, initial_delay=delay_1,
            s_max=1, seed=0, weight=0.0, delay=1.0))
    proj_2 = p.Projection(
        stim, pop_2, p.FromListConnector([]), p.StructuralMechanismSTDP(
            partner_selection=p.RandomSelection(),
            formation=p.DistanceDependentFormation([1, 1], 1.0),
            elimination=p.RandomByWeightElimination(4.0, 0, 0),
            timing_dependence=p.SpikePairRule(
                tau_plus, tau_minus, A_plus, A_minus),
            weight_dependence=p.AdditiveWeightDependence(w_min, w_max),
            f_rew=1000, initial_weight=w_init_2, initial_delay=delay_2,
            s_max=1, seed=0, weight=0.0, delay=1.0))
    proj_3 = p.Projection(
        stim, pop_3, p.FromListConnector([(0, 0)]),
        p.StructuralMechanismSTDP(
            partner_selection=p.LastNeuronSelection(),
            formation=p.DistanceDependentFormation([1, 1], 0.0),
            elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0),
            timing_dependence=p.SpikePairRule(
                tau_plus, tau_minus, A_plus, A_minus),
            weight_dependence=p.AdditiveWeightDependence(w_min, w_max),
            f_rew=1000, initial_weight=2.0, initial_delay=5.0,
            s_max=1, seed=0, weight=0.0, delay=1.0))
    proj_4 = p.Projection(
        stim, pop_4, p.FromListConnector([(0, 0)]),
        p.StructuralMechanismSTDP(
            partner_selection=p.RandomSelection(),
            formation=p.DistanceDependentFormation([1, 1], 0.0),
            elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0),
            timing_dependence=p.SpikePairRule(
                tau_plus, tau_minus, A_plus, A_minus),
            weight_dependence=p.AdditiveWeightDependence(w_min, w_max),
            f_rew=1000, initial_weight=4.0, initial_delay=3.0,
            s_max=1, seed=0, weight=0.0, delay=1.0))
    p.run(10)

    conns = list(proj.get(["weight", "delay"], "list"))
    conns_2 = list(proj_2.get(["weight", "delay"], "list"))
    conns_3 = list(proj_3.get(["weight", "delay"], "list"))
    conns_4 = list(proj_4.get(["weight", "delay"], "list"))

    spikes_1 = [s.magnitude
                for s in pop.get_data("spikes").segments[0].spiketrains]
    spikes_2 = [s.magnitude
                for s in pop_2.get_data("spikes").segments[0].spiketrains]

    p.end()

    print(conns)
    print(conns_2)
    print(conns_3)
    print(conns_4)

    w_final_1 = calculate_spike_pair_additive_stdp_weight(
        pre_spikes_last_neuron, spikes_1[0], w_init_1, delay_1, w_max,
        A_plus, A_minus, tau_plus, tau_minus)
    w_final_2 = calculate_spike_pair_additive_stdp_weight(
        pre_spikes, spikes_2[0], w_init_2, delay_2, w_max, A_plus, A_minus,
        tau_plus, tau_minus)
    print(w_final_1, spikes_1[0])
    print(w_final_2, spikes_2[0])

    assert(len(conns) == 1)
    assert(conns[0][3] == delay_1)
    assert(conns[0][2] >= w_final_1 - 0.01 and
           conns[0][2] <= w_final_1 + 0.01)
    assert(len(conns_2) == 1)
    assert(conns_2[0][3] == delay_2)
    assert(conns_2[0][2] >= w_final_2 - 0.01 and
           conns_2[0][2] <= w_final_2 + 0.01)
    assert(len(conns_3) == 0)
    assert(len(conns_4) == 0)
def structural_without_stdp():
    p.setup(1.0)
    stim = p.Population(1, p.SpikeSourceArray(range(10)), label="stim")

    # These populations should experience formation
    pop = p.Population(1, p.IF_curr_exp(), label="pop")
    pop_2 = p.Population(1, p.IF_curr_exp(), label="pop_2")

    # These populations should experience elimination
    pop_3 = p.Population(1, p.IF_curr_exp(), label="pop_3")
    pop_4 = p.Population(1, p.IF_curr_exp(), label="pop_4")

    # Formation with last-neuron selection (0 probability elimination)
    proj = p.Projection(
        stim, pop, p.FromListConnector([]), p.StructuralMechanismStatic(
            partner_selection=p.LastNeuronSelection(),
            formation=p.DistanceDependentFormation([1, 1], 1.0),
            elimination=p.RandomByWeightElimination(2.0, 0, 0),
            f_rew=1000, initial_weight=2.0, initial_delay=5.0,
            s_max=1, seed=0, weight=0.0, delay=1.0))

    # Formation with random selection (0 probability elimination)
    proj_2 = p.Projection(
        stim, pop_2, p.FromListConnector([]), p.StructuralMechanismStatic(
            partner_selection=p.RandomSelection(),
            formation=p.DistanceDependentFormation([1, 1], 1.0),
            elimination=p.RandomByWeightElimination(4.0, 0, 0),
            f_rew=1000, initial_weight=4.0, initial_delay=3.0,
            s_max=1, seed=0, weight=0.0, delay=1.0))

    # Elimination with last neuron selection (0 probability formation)
    proj_3 = p.Projection(
        stim, pop_3, p.FromListConnector([(0, 0)]),
        p.StructuralMechanismStatic(
            partner_selection=p.LastNeuronSelection(),
            formation=p.DistanceDependentFormation([1, 1], 0.0),
            elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0),
            f_rew=1000, initial_weight=2.0, initial_delay=5.0,
            s_max=1, seed=0, weight=0.0, delay=1.0))

    # Elimination with random selection (0 probability formation)
    proj_4 = p.Projection(
        stim, pop_4, p.FromListConnector([(0, 0)]),
        p.StructuralMechanismStatic(
            partner_selection=p.RandomSelection(),
            formation=p.DistanceDependentFormation([1, 1], 0.0),
            elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0),
            f_rew=1000, initial_weight=4.0, initial_delay=3.0,
            s_max=1, seed=0, weight=0.0, delay=1.0))
    p.run(10)

    # Get the final connections
    conns = list(proj.get(["weight", "delay"], "list"))
    conns_2 = list(proj_2.get(["weight", "delay"], "list"))
    conns_3 = list(proj_3.get(["weight", "delay"], "list"))
    conns_4 = list(proj_4.get(["weight", "delay"], "list"))

    p.end()

    print(conns)
    print(conns_2)
    print(conns_3)
    print(conns_4)

    # These should be formed with specified parameters
    assert(len(conns) == 1)
    assert(tuple(conns[0]) == (0, 0, 2.0, 5.0))
    assert(len(conns_2) == 1)
    assert(tuple(conns_2[0]) == (0, 0, 4.0, 3.0))

    # These should have no connections since eliminated
    assert(len(conns_3) == 0)
    assert(len(conns_4) == 0)