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"))
def __init__(self, tau_ref=0.0025, amplitude=1.0, initial_state=None): super().__init__( base_type=Tanh(tau_ref=tau_ref), amplitude=amplitude, initial_state=initial_state, )
def test_tanh_invalid(): tanh = Tanh(tau_ref=0.5) with pytest.raises(ValidationError, match="Max rates must be below"): tanh.gain_bias(max_rates=np.array([100]), intercepts=np.array([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)
def test_tanh_invalid(): """Ensures validation error is thrown when given a large max rate.""" tanh = Tanh(tau_ref=0.5) with pytest.raises(ValidationError, match="Max rates must be below"): tanh.gain_bias(max_rates=np.array([100]), intercepts=np.array([0]))