def step_math(self, dt, J, spiked, voltage, ref, adaptation): """Compute rates for input current (incl. bias)""" n = adaptation k = np.expm1(-dt / self.tau_n) inc = -k dec = k + 1 n *= dec # decay adaptation LIF.step_math(self, dt, J - n, spiked, voltage, ref) n += inc * (self.inc_n * spiked) # increment adaptation
def test_operators(): sig = Signal(np.array([0.0]), name="sig") assert fnmatch(repr(TimeUpdate(sig, sig)), "<TimeUpdate at 0x*>") assert fnmatch(repr(TimeUpdate(sig, sig, tag="tag")), "<TimeUpdate 'tag' at 0x*>") assert fnmatch(repr(Reset(sig)), "<Reset at 0x*>") assert fnmatch(repr(Reset(sig, tag="tag")), "<Reset 'tag' at 0x*>") assert fnmatch(repr(Copy(sig, sig)), "<Copy at 0x*>") assert fnmatch(repr(Copy(sig, sig, tag="tag")), "<Copy 'tag' at 0x*>") assert fnmatch(repr(ElementwiseInc(sig, sig, sig)), "<ElementwiseInc at 0x*>") assert fnmatch(repr(ElementwiseInc(sig, sig, sig, tag="tag")), "<ElementwiseInc 'tag' at 0x*>") assert fnmatch(repr(DotInc(sig, sig, sig)), "<DotInc at 0x*>") assert fnmatch(repr(DotInc(sig, sig, sig, tag="tag")), "<DotInc 'tag' at 0x*>") assert fnmatch(repr(SimPyFunc(sig, lambda x: 0.0, True, sig)), "<SimPyFunc at 0x*>") assert fnmatch( repr(SimPyFunc(sig, lambda x: 0.0, True, sig, tag="tag")), "<SimPyFunc 'tag' at 0x*>", ) assert fnmatch(repr(SimPES(sig, sig, sig, 0.1)), "<SimPES at 0x*>") assert fnmatch(repr(SimPES(sig, sig, sig, 0.1, tag="tag")), "<SimPES 'tag' at 0x*>") assert fnmatch(repr(SimBCM(sig, sig, sig, sig, 0.1)), "<SimBCM at 0x*>") assert fnmatch(repr(SimBCM(sig, sig, sig, sig, 0.1, tag="tag")), "<SimBCM 'tag' at 0x*>") assert fnmatch(repr(SimOja(sig, sig, sig, sig, 0.1, 1.0)), "<SimOja at 0x*>") assert fnmatch(repr(SimOja(sig, sig, sig, sig, 0.1, 1.0, tag="tag")), "<SimOja 'tag' at 0x*>") assert fnmatch(repr(SimVoja(sig, sig, sig, sig, 1.0, sig, 1.0)), "<SimVoja at 0x*>") assert fnmatch( repr(SimVoja(sig, sig, sig, sig, 0.1, sig, 1.0, tag="tag")), "<SimVoja 'tag' at 0x*>", ) assert fnmatch(repr(SimRLS(sig, sig, sig, sig)), "<SimRLS at 0x*>") assert fnmatch( repr(SimRLS(sig, sig, sig, sig, tag="tag")), "<SimRLS 'tag' at 0x*>", ) assert fnmatch(repr(SimNeurons(LIF(), sig, {"sig": sig})), "<SimNeurons at 0x*>") assert fnmatch( repr(SimNeurons(LIF(), sig, {"sig": sig}, tag="tag")), "<SimNeurons 'tag' at 0x*>", ) assert fnmatch(repr(SimProcess(WhiteNoise(), sig, sig, sig)), "<SimProcess at 0x*>") assert fnmatch( repr(SimProcess(WhiteNoise(), sig, sig, sig, tag="tag")), "<SimProcess 'tag' at 0x*>", )
def test_neuron_types(): check_init_args(Direct, ["initial_state"]) check_repr(Direct()) assert repr(Direct()) == "Direct()" check_init_args(RectifiedLinear, ["amplitude", "initial_state"]) check_repr(RectifiedLinear()) check_repr(RectifiedLinear(amplitude=2)) assert repr(RectifiedLinear()) == "RectifiedLinear()" check_init_args(SpikingRectifiedLinear, ["amplitude", "initial_state"]) check_repr(SpikingRectifiedLinear()) check_repr(SpikingRectifiedLinear(amplitude=2)) check_repr( SpikingRectifiedLinear(initial_state={"voltage": Choice([1.0])})) assert repr(SpikingRectifiedLinear()) == "SpikingRectifiedLinear()" check_init_args(Sigmoid, ["tau_ref", "initial_state"]) check_repr(Sigmoid()) check_repr(Sigmoid(tau_ref=0.1)) assert repr(Sigmoid()), "Sigmoid()" assert repr(Sigmoid(tau_ref=0.001)) == "Sigmoid(tau_ref=0.001)" check_init_args(LIFRate, ["tau_rc", "tau_ref", "amplitude", "initial_state"]) 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)) assert repr(LIFRate()) == "LIFRate()" assert repr(LIFRate(tau_rc=0.01, tau_ref=0)) == "LIFRate(tau_rc=0.01, tau_ref=0)" check_init_args( LIF, ["tau_rc", "tau_ref", "min_voltage", "amplitude", "initial_state"]) 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_repr(LIF(initial_state={"refractory_time": Choice([0.1])})) assert repr(LIF()) == "LIF()" assert repr(LIF(tau_rc=0.01, tau_ref=0)) == "LIF(tau_rc=0.01, tau_ref=0)" check_init_args( AdaptiveLIFRate, ["tau_n", "inc_n", "tau_rc", "tau_ref", "amplitude", "initial_state"], ) 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_repr(AdaptiveLIFRate(initial_state={"adaptation": Choice([0.1])})) assert repr(AdaptiveLIFRate()) == "AdaptiveLIFRate()" assert (repr(AdaptiveLIFRate( tau_rc=0.01, tau_n=0.5, inc_n=0.02)) == "AdaptiveLIFRate(tau_n=0.5, inc_n=0.02, tau_rc=0.01)") check_init_args( AdaptiveLIF, [ "tau_n", "inc_n", "tau_rc", "tau_ref", "min_voltage", "amplitude", "initial_state", ], ) 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_repr(AdaptiveLIF(initial_state={"adaptation": Choice([0.1])})) assert repr(AdaptiveLIF()) == "AdaptiveLIF()" assert (repr(AdaptiveLIF( tau_rc=0.01, tau_n=0.5, inc_n=0.02)) == "AdaptiveLIF(tau_n=0.5, inc_n=0.02, tau_rc=0.01)") check_init_args( Izhikevich, [ "tau_recovery", "coupling", "reset_voltage", "reset_recovery", "initial_state", ], ) 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)) check_repr(Izhikevich(initial_state={"recovery": Choice([0.1])})) assert repr(Izhikevich()) == "Izhikevich()" assert (repr( Izhikevich(tau_recovery=0.01, coupling=0.5, reset_voltage=-60, reset_recovery=6)) == "Izhikevich(tau_recovery=0.01, coupling=0.5, reset_voltage=-60, " "reset_recovery=6)") check_init_args(Tanh, ["tau_ref", "initial_state"]) check_repr(Tanh()) check_repr(Tanh(tau_ref=0.1))