LIFRef#
- class brainpy.state.LIFRef(in_size, R=Quantity(1., "ohm"), tau=Quantity(5., "ms"), tau_ref=Quantity(5., "ms"), V_th=Quantity(1., "mV"), V_reset=Quantity(0., "mV"), V_rest=Quantity(0., "mV"), V_initializer=Constant(value=0. mV), spk_fun=ReluGrad(alpha=0.3, width=1.0), spk_reset='soft', name=None)#
Leaky Integrate-and-Fire neuron model with refractory period.
This class implements a Leaky Integrate-and-Fire neuron model that includes a refractory period after spiking, during which the neuron cannot fire regardless of input. This better captures the behavior of biological neurons that exhibit a recovery period after action potential generation.
The model is characterized by the following equations:
When not in refractory period:
\[ \tau \frac{dV}{dt} = -(V - V_{rest}) + R \cdot I(t) \]During refractory period:
\[ V = V_{reset} \]Spike condition: If \(V \geq V_{th}\): emit spike, set \(V = V_{reset}\), and enter refractory period for \(\tau_{ref}\)
- Parameters:
in_size (
Size) – Size of the input to the neuron.R (
ArrayLike, default1. * u.ohm) – Membrane resistance.tau (
ArrayLike, default5. * u.ms) – Membrane time constant.tau_ref (
ArrayLike, default5. * u.ms) – Refractory period duration.V_th (
ArrayLike, default1. * u.mV) – Firing threshold voltage.V_reset (
ArrayLike, default0. * u.mV) – Reset voltage after spike.V_rest (
ArrayLike, default0. * u.mV) – Resting membrane potential.V_initializer (
Callable) – Initializer for the membrane potential state.spk_fun (
Callable, defaultsurrogate.ReluGrad()) – Surrogate gradient function for the non-differentiable spike generation.spk_reset (
str, default'soft') – Reset mechanism after spike generation: - ‘soft’: subtract threshold V = V - V_th - ‘hard’: strict reset using stop_gradientname (
str, optional) – Name of the neuron layer.
- V#
Membrane potential.
- Type:
HiddenState
- last_spike_time#
Time of the last spike, used to implement refractory period.
- Type:
ShortTermState
Notes
The refractory period is implemented by tracking the time of the last spike and preventing membrane potential updates if the elapsed time is less than tau_ref.
During the refractory period, the membrane potential remains at the reset value regardless of input current strength.
Refractory periods prevent high-frequency repetitive firing and are critical for realistic neural dynamics [3].
The time-dependent dynamics are integrated using an exponential Euler method.
The simulation environment time variable ‘t’ is used to track the refractory state.
For a comprehensive treatment of LIF models with refractory periods, see [1] and [2].
References
Examples
>>> import brainpy >>> import brainstate >>> import saiunit as u >>> # Create a LIFRef neuron layer with 10 neurons >>> lifref = brainpy.state.LIFRef(10, tau=10*u.ms, tau_ref=5*u.ms, ... V_th=0.8*u.mV) >>> # Initialize the state >>> lifref.init_state(batch_size=1) >>> # Apply an input current and update the neuron state >>> spikes = lifref.update(x=1.5*u.mA)
- get_spike(V=None)[source]#
Generate spikes based on neuron state variables.
This abstract method must be implemented by subclasses to define the spike generation mechanism. The method should use the surrogate gradient function
self.spk_funto enable gradient-based learning.- Parameters:
*args – Positional arguments (typically state variables like membrane potential)
**kwargs – Keyword arguments
- Returns:
Binary spike tensor where 1 indicates a spike and 0 indicates no spike.
- Return type:
ArrayLike- Raises:
NotImplementedError – If the subclass does not implement this method.