예제 #1
0
def test_probeable():
    def check_neuron_type(neuron_type, expected):
        assert neuron_type.probeable == expected
        ens = nengo.Ensemble(10, 1, neuron_type=neuron_type)
        assert ens.neurons.probeable == expected + ("input", )

    with nengo.Network():
        check_neuron_type(Direct(), ("output", ))
        check_neuron_type(RectifiedLinear(), ("output", ))
        check_neuron_type(SpikingRectifiedLinear(), ("output", "voltage"))
        check_neuron_type(Sigmoid(), ("output", ))
        check_neuron_type(Tanh(), ("output", ))
        check_neuron_type(LIFRate(), ("output", ))
        check_neuron_type(LIF(), ("output", "voltage", "refractory_time"))
        check_neuron_type(AdaptiveLIFRate(), ("output", "adaptation"))
        check_neuron_type(
            AdaptiveLIF(),
            ("output", "voltage", "refractory_time", "adaptation"))
        check_neuron_type(Izhikevich(), ("output", "voltage", "recovery"))
        check_neuron_type(RegularSpiking(LIFRate()),
                          ("output", "rate_out", "voltage"))
        check_neuron_type(StochasticSpiking(AdaptiveLIFRate()),
                          ("output", "rate_out", "adaptation"))
        check_neuron_type(PoissonSpiking(LIFRate()), ("output", "rate_out"))
예제 #2
0
def test_argreprs():
    """Test repr() for each neuron type."""
    def check_init_args(cls, args):
        assert getfullargspec(cls.__init__).args[1:] == args

    def check_repr(obj):
        assert eval(repr(obj)) == obj

    check_init_args(Direct, [])
    check_repr(Direct())

    check_init_args(RectifiedLinear, ["amplitude"])
    check_repr(RectifiedLinear())
    check_repr(RectifiedLinear(amplitude=2))

    check_init_args(SpikingRectifiedLinear, ["amplitude"])
    check_repr(SpikingRectifiedLinear())
    check_repr(SpikingRectifiedLinear(amplitude=2))

    check_init_args(Sigmoid, ["tau_ref"])
    check_repr(Sigmoid())
    check_repr(Sigmoid(tau_ref=0.1))

    check_init_args(LIFRate, ["tau_rc", "tau_ref", "amplitude"])
    check_repr(LIFRate())
    check_repr(LIFRate(tau_rc=0.1))
    check_repr(LIFRate(tau_ref=0.1))
    check_repr(LIFRate(amplitude=2))
    check_repr(LIFRate(tau_rc=0.05, tau_ref=0.02))
    check_repr(LIFRate(tau_rc=0.05, amplitude=2))
    check_repr(LIFRate(tau_ref=0.02, amplitude=2))
    check_repr(LIFRate(tau_rc=0.05, tau_ref=0.02, amplitude=2))

    check_init_args(LIF, ["tau_rc", "tau_ref", "min_voltage", "amplitude"])
    check_repr(LIF())
    check_repr(LIF(tau_rc=0.1))
    check_repr(LIF(tau_ref=0.1))
    check_repr(LIF(amplitude=2))
    check_repr(LIF(min_voltage=-0.5))
    check_repr(LIF(tau_rc=0.05, tau_ref=0.02))
    check_repr(LIF(tau_rc=0.05, amplitude=2))
    check_repr(LIF(tau_ref=0.02, amplitude=2))
    check_repr(LIF(tau_rc=0.05, tau_ref=0.02, amplitude=2))
    check_repr(LIF(tau_rc=0.05, tau_ref=0.02, min_voltage=-0.5, amplitude=2))

    check_init_args(AdaptiveLIFRate,
                    ["tau_n", "inc_n", "tau_rc", "tau_ref", "amplitude"])
    check_repr(AdaptiveLIFRate())
    check_repr(AdaptiveLIFRate(tau_n=0.1))
    check_repr(AdaptiveLIFRate(inc_n=0.5))
    check_repr(AdaptiveLIFRate(tau_rc=0.1))
    check_repr(AdaptiveLIFRate(tau_ref=0.1))
    check_repr(AdaptiveLIFRate(amplitude=2))
    check_repr(
        AdaptiveLIFRate(tau_n=0.1,
                        inc_n=0.5,
                        tau_rc=0.05,
                        tau_ref=0.02,
                        amplitude=2))

    check_init_args(
        AdaptiveLIF,
        ["tau_n", "inc_n", "tau_rc", "tau_ref", "min_voltage", "amplitude"])
    check_repr(AdaptiveLIF())
    check_repr(AdaptiveLIF(tau_n=0.1))
    check_repr(AdaptiveLIF(inc_n=0.5))
    check_repr(AdaptiveLIF(tau_rc=0.1))
    check_repr(AdaptiveLIF(tau_ref=0.1))
    check_repr(AdaptiveLIF(min_voltage=-0.5))
    check_repr(
        AdaptiveLIF(
            tau_n=0.1,
            inc_n=0.5,
            tau_rc=0.05,
            tau_ref=0.02,
            min_voltage=-0.5,
            amplitude=2,
        ))

    check_init_args(
        Izhikevich,
        ["tau_recovery", "coupling", "reset_voltage", "reset_recovery"])
    check_repr(Izhikevich())
    check_repr(Izhikevich(tau_recovery=0.1))
    check_repr(Izhikevich(coupling=0.3))
    check_repr(Izhikevich(reset_voltage=-1))
    check_repr(Izhikevich(reset_recovery=5))
    check_repr(
        Izhikevich(tau_recovery=0.1,
                   coupling=0.3,
                   reset_voltage=-1,
                   reset_recovery=5))
예제 #3
0
    for max_rate, intercept in [(300.0, 1.1), (300.0, 1.0), (100.0, 0.9), (100, 1.0)]:
        with nengo.Network() as net:
            nengo.Ensemble(
                1,
                1,
                neuron_type=Sigmoid(),
                max_rates=[max_rate],
                intercepts=[intercept],
            )
        with pytest.raises(BuildError, match="lead to neurons with negative"):
            with Simulator(net):
                pass


@pytest.mark.slow
@pytest.mark.parametrize("base_type", [LIFRate(), RectifiedLinear(), Tanh()])
def test_spiking_types(base_type, seed, plt, allclose):
    spiking_types = {
        RegularSpiking: dict(atol=0.05, rmse_target=0.011),
        PoissonSpiking: dict(atol=0.13, rmse_target=0.024),
        StochasticSpiking: dict(atol=0.10, rmse_target=0.019),
    }

    n_neurons = 1000

    with nengo.Network(seed=seed) as net:
        u = nengo.Node(lambda t: np.sin(2 * np.pi * t))
        a = nengo.Ensemble(n_neurons, 1)
        nengo.Connection(u, a)
        u_p = nengo.Probe(u, synapse=0.005)
        a_p = nengo.Probe(a, synapse=0.005)