コード例 #1
0
def test_get_max_synapses():
    unittest_setup()
    spynnaker8.setup()
    d = SynapseDynamicsSTDP(timing_dependence=TimingDependenceSpikePair(),
                            weight_dependence=WeightDependenceAdditive(),
                            pad_to_length=258)
    assert d.get_max_synapses(256) <= 256
コード例 #2
0
    def __init__(self,
                 stdp_model=CommonSP.default_parameters['stdp_model'],
                 f_rew=CommonSP.default_parameters['f_rew'],
                 weight=CommonSP.default_parameters['weight'],
                 delay=CommonSP.default_parameters['delay'],
                 s_max=CommonSP.default_parameters['s_max'],
                 sigma_form_forward=CommonSP.
                 default_parameters['sigma_form_forward'],
                 sigma_form_lateral=CommonSP.
                 default_parameters['sigma_form_lateral'],
                 p_form_forward=CommonSP.default_parameters['p_form_forward'],
                 p_form_lateral=CommonSP.default_parameters['p_form_lateral'],
                 p_elim_dep=CommonSP.default_parameters['p_elim_dep'],
                 p_elim_pot=CommonSP.default_parameters['p_elim_pot'],
                 grid=CommonSP.default_parameters['grid'],
                 lateral_inhibition=CommonSP.
                 default_parameters['lateral_inhibition'],
                 random_partner=CommonSP.default_parameters['random_partner'],
                 seed=None):
        if (stdp_model is not None
                and not isinstance(stdp_model, SynapseDynamicsSTDP)):
            raise TypeError("Using wrong StructuralMechanism. "
                            "You should be using StructuralMechanismStatic. ")

        SynapseDynamicsSTDP.__init__(self,
                                     stdp_model.timing_dependence,
                                     stdp_model.weight_dependence,
                                     None,
                                     stdp_model.dendritic_delay_fraction,
                                     pad_to_length=s_max)
        AbstractSynapseDynamicsStructural.__init__(self)

        self._common_sp = CommonSP(stdp_model=self,
                                   f_rew=f_rew,
                                   weight=weight,
                                   delay=delay,
                                   s_max=s_max,
                                   sigma_form_forward=sigma_form_forward,
                                   sigma_form_lateral=sigma_form_lateral,
                                   p_form_forward=p_form_forward,
                                   p_form_lateral=p_form_lateral,
                                   p_elim_dep=p_elim_dep,
                                   p_elim_pot=p_elim_pot,
                                   grid=grid,
                                   lateral_inhibition=lateral_inhibition,
                                   random_partner=random_partner,
                                   seed=seed)
コード例 #3
0
import pytest


@pytest.mark.parametrize(
    "dynamics,size,exception,max_size",
    [
        # Normal static rows can be up to 255 words, 1 word per synapse
        (SynapseDynamicsStatic(), 512, SynapseRowTooBigException, 255),

        # Normal static row of 20 is allowed - 20 words = 80 bytes
        (SynapseDynamicsStatic(), 20, None, 80),

        # STDP row with spike pair rule is 1 words per synapse but extra
        # header takes some of the space, so only 252 synapses allowed
        (SynapseDynamicsSTDP(
            TimingDependenceSpikePair(),
            WeightDependenceAdditive()), 512, SynapseRowTooBigException, 252),

        # STDP row with spike pair rule of 20 is allowed - 20 words = 80 bytes
        (SynapseDynamicsSTDP(TimingDependenceSpikePair(),
                             WeightDependenceAdditive()), 20, None, 80)
    ])
def test_get_max_row_bytes(dynamics, size, exception, max_size):
    io = SynapseIORowBased()
    population_table = MasterPopTableAsBinarySearch()
    synapse_information = SynapseInformation(None, dynamics, 0)
    in_edge = ProjectionApplicationEdge(None, None, synapse_information)
    if exception is not None:
        with pytest.raises(exception) as exc_info:
            io._get_max_row_bytes(size, dynamics, population_table, in_edge,
                                  size)
コード例 #4
0
    def test_set_synapse_dynamics(self):
        MockSimulator.setup()
        default_config_paths = os.path.join(
            os.path.dirname(abstract_spinnaker_common.__file__),
            AbstractSpiNNakerCommon.CONFIG_FILE_NAME)
        config = conf_loader.load_config(
            AbstractSpiNNakerCommon.CONFIG_FILE_NAME, default_config_paths)
        synaptic_manager = SynapticManager(
            n_synapse_types=2, ring_buffer_sigma=5.0,
            spikes_per_second=100.0, config=config)

        static = SynapseDynamicsStatic()
        stdp = SynapseDynamicsSTDP(
            timing_dependence=TimingDependenceSpikePair(),
            weight_dependence=WeightDependenceAdditive())
        alt_stdp = SynapseDynamicsSTDP(
            timing_dependence=TimingDependenceSpikePair(),
            weight_dependence=WeightDependenceMultiplicative())
        static_struct = SynapseDynamicsStructuralStatic(
            partner_selection=LastNeuronSelection(),
            formation=DistanceDependentFormation(),
            elimination=RandomByWeightElimination(0.5))
        alt_static_struct = SynapseDynamicsStructuralStatic(
            partner_selection=RandomSelection(),
            formation=DistanceDependentFormation(),
            elimination=RandomByWeightElimination(0.5))
        stdp_struct = SynapseDynamicsStructuralSTDP(
            partner_selection=LastNeuronSelection(),
            formation=DistanceDependentFormation(),
            elimination=RandomByWeightElimination(0.5),
            timing_dependence=TimingDependenceSpikePair(),
            weight_dependence=WeightDependenceAdditive())
        alt_stdp_struct = SynapseDynamicsStructuralSTDP(
            partner_selection=RandomSelection(),
            formation=DistanceDependentFormation(),
            elimination=RandomByWeightElimination(0.5),
            timing_dependence=TimingDependenceSpikePair(),
            weight_dependence=WeightDependenceAdditive())
        alt_stdp_struct_2 = SynapseDynamicsStructuralSTDP(
            partner_selection=LastNeuronSelection(),
            formation=DistanceDependentFormation(),
            elimination=RandomByWeightElimination(0.5),
            timing_dependence=TimingDependenceSpikePair(),
            weight_dependence=WeightDependenceMultiplicative())

        # This should be fine as it is the first call
        synaptic_manager.synapse_dynamics = static

        # This should be fine as STDP overrides static
        synaptic_manager.synapse_dynamics = stdp

        # This should fail because STDP dependences are difference
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp

        # This should work because STDP dependences are the same
        synaptic_manager.synapse_dynamics = stdp

        # This should work because static always works, but the type should
        # still be STDP
        synaptic_manager.synapse_dynamics = static
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsSTDP)

        # This should work but should merge with the STDP rule
        synaptic_manager.synapse_dynamics = static_struct
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralSTDP)

        # These should work as static / the STDP is the same but neither should
        # change anything
        synaptic_manager.synapse_dynamics = static
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralSTDP)
        synaptic_manager.synapse_dynamics = stdp
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralSTDP)
        synaptic_manager.synapse_dynamics = static_struct
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralSTDP)

        # These should fail as things are different
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_static_struct
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp

        # This should pass as same structural STDP
        synaptic_manager.synapse_dynamics = stdp_struct
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralSTDP)

        # These should fail as both different
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp_struct
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp_struct_2

        # Try starting again to get a couple more combinations
        synaptic_manager = SynapticManager(
            n_synapse_types=2, ring_buffer_sigma=5.0,
            spikes_per_second=100.0, config=config)

        # STDP followed by structural STDP should result in Structural STDP
        synaptic_manager.synapse_dynamics = stdp
        synaptic_manager.synapse_dynamics = stdp_struct
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralSTDP)

        # ... and should fail here because of differences
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_static_struct
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp_struct
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp_struct_2

        # One more time!
        synaptic_manager = SynapticManager(
            n_synapse_types=2, ring_buffer_sigma=5.0,
            spikes_per_second=100.0, config=config)

        # Static followed by static structural should result in static
        # structural
        synaptic_manager.synapse_dynamics = static
        synaptic_manager.synapse_dynamics = static_struct
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralStatic)

        # ... and should fail here because of differences
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_static_struct
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp_struct

        # This should be fine
        synaptic_manager.synapse_dynamics = static

        # This should be OK, but should merge with STDP (opposite of above)
        synaptic_manager.synapse_dynamics = stdp
        self.assertIsInstance(
            synaptic_manager.synapse_dynamics, SynapseDynamicsStructuralSTDP)

        # ... and now these should fail
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_static_struct
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp_struct
        with self.assertRaises(SynapticConfigurationException):
            synaptic_manager.synapse_dynamics = alt_stdp_struct_2

        # OK, just one more, honest
        synaptic_manager = SynapticManager(
            n_synapse_types=2, ring_buffer_sigma=5.0,
            spikes_per_second=100.0, config=config)
        synaptic_manager.synapse_dynamics = static_struct
        synaptic_manager.synapse_dynamics = stdp_struct
コード例 #5
0
def test_set_synapse_dynamics():
    unittest_setup()
    p.setup(1.0)
    post_app_model = IFCurrExpBase()
    post_app_vertex = post_app_model.create_vertex(
        n_neurons=10,
        label="post",
        constraints=None,
        spikes_per_second=None,
        ring_buffer_sigma=None,
        incoming_spike_buffer_size=None,
        n_steps_per_timestep=1,
        drop_late_spikes=True,
        splitter=None)

    static = SynapseDynamicsStatic()
    stdp = SynapseDynamicsSTDP(timing_dependence=TimingDependenceSpikePair(),
                               weight_dependence=WeightDependenceAdditive())
    alt_stdp = SynapseDynamicsSTDP(
        timing_dependence=TimingDependenceSpikePair(),
        weight_dependence=WeightDependenceMultiplicative())
    static_struct = SynapseDynamicsStructuralStatic(
        partner_selection=LastNeuronSelection(),
        formation=DistanceDependentFormation(),
        elimination=RandomByWeightElimination(0.5))
    alt_static_struct = SynapseDynamicsStructuralStatic(
        partner_selection=RandomSelection(),
        formation=DistanceDependentFormation(),
        elimination=RandomByWeightElimination(0.5))
    stdp_struct = SynapseDynamicsStructuralSTDP(
        partner_selection=LastNeuronSelection(),
        formation=DistanceDependentFormation(),
        elimination=RandomByWeightElimination(0.5),
        timing_dependence=TimingDependenceSpikePair(),
        weight_dependence=WeightDependenceAdditive())
    alt_stdp_struct = SynapseDynamicsStructuralSTDP(
        partner_selection=RandomSelection(),
        formation=DistanceDependentFormation(),
        elimination=RandomByWeightElimination(0.5),
        timing_dependence=TimingDependenceSpikePair(),
        weight_dependence=WeightDependenceAdditive())
    alt_stdp_struct_2 = SynapseDynamicsStructuralSTDP(
        partner_selection=LastNeuronSelection(),
        formation=DistanceDependentFormation(),
        elimination=RandomByWeightElimination(0.5),
        timing_dependence=TimingDependenceSpikePair(),
        weight_dependence=WeightDependenceMultiplicative())
    neuromodulation = SynapseDynamicsNeuromodulation()
    alt_neuromodulation = SynapseDynamicsNeuromodulation(tau_c=1)

    # This should be fine as it is the first call
    post_app_vertex.synapse_dynamics = static

    # This should fail as can't add neuromodulation first
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = neuromodulation

    # This should be fine as STDP overrides static
    post_app_vertex.synapse_dynamics = stdp

    # This should fail because STDP dependences are difference
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp

    # This should pass because neuromodulation is OK after STDP
    post_app_vertex.synapse_dynamics = neuromodulation
    assert isinstance(post_app_vertex.synapse_dynamics, SynapseDynamicsSTDP)

    # This should work because STDP dependences are the same
    post_app_vertex.synapse_dynamics = stdp

    # This should fail as neuromodulation type is different
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_neuromodulation

    # This should be fine as same neuromodulation
    post_app_vertex.synapse_dynamics = neuromodulation
    assert isinstance(post_app_vertex.synapse_dynamics, SynapseDynamicsSTDP)

    # This should work because static always works, but the type should
    # still be STDP
    post_app_vertex.synapse_dynamics = static
    assert isinstance(post_app_vertex.synapse_dynamics, SynapseDynamicsSTDP)

    # This should work but should merge with the STDP rule
    post_app_vertex.synapse_dynamics = static_struct
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralSTDP)

    # These should work as static / the STDP is the same but neither should
    # change anything
    post_app_vertex.synapse_dynamics = static
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralSTDP)
    post_app_vertex.synapse_dynamics = stdp
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralSTDP)
    post_app_vertex.synapse_dynamics = static_struct
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralSTDP)

    # These should fail as things are different
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_static_struct
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp

    # This should pass as same structural STDP
    post_app_vertex.synapse_dynamics = stdp_struct
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralSTDP)

    # These should fail as both different
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp_struct
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp_struct_2

    # Try starting again to get a couple more combinations
    post_app_vertex = post_app_model.create_vertex(
        n_neurons=10,
        label="post",
        constraints=None,
        spikes_per_second=None,
        ring_buffer_sigma=None,
        incoming_spike_buffer_size=None,
        n_steps_per_timestep=1,
        drop_late_spikes=True,
        splitter=None)

    # STDP followed by structural STDP should result in Structural STDP
    post_app_vertex.synapse_dynamics = stdp
    post_app_vertex.synapse_dynamics = stdp_struct
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralSTDP)

    # ... and should fail here because of differences
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_static_struct
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp_struct
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp_struct_2

    # One more time!
    post_app_vertex = post_app_model.create_vertex(
        n_neurons=10,
        label="post",
        constraints=None,
        spikes_per_second=None,
        ring_buffer_sigma=None,
        incoming_spike_buffer_size=None,
        n_steps_per_timestep=1,
        drop_late_spikes=True,
        splitter=None)

    # Static followed by static structural should result in static
    # structural
    post_app_vertex.synapse_dynamics = static
    post_app_vertex.synapse_dynamics = static_struct
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralStatic)

    # ... and should fail here because of differences
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_static_struct
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp_struct

    # This should be fine
    post_app_vertex.synapse_dynamics = static

    # This should be OK, but should merge with STDP (opposite of above)
    post_app_vertex.synapse_dynamics = stdp
    assert isinstance(post_app_vertex.synapse_dynamics,
                      SynapseDynamicsStructuralSTDP)

    # ... and now these should fail
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_static_struct
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp_struct
    with pytest.raises(SynapticConfigurationException):
        post_app_vertex.synapse_dynamics = alt_stdp_struct_2

    # OK, just one more, honest
    post_app_vertex = post_app_model.create_vertex(
        n_neurons=10,
        label="post",
        constraints=None,
        spikes_per_second=None,
        ring_buffer_sigma=None,
        incoming_spike_buffer_size=None,
        n_steps_per_timestep=1,
        drop_late_spikes=True,
        splitter=None)
    post_app_vertex.synapse_dynamics = static_struct
    post_app_vertex.synapse_dynamics = stdp_struct