LIF#
- class brainpy.state.LIF(in_size, R=Quantity(1., "ohm"), tau=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 (LIF) neuron model.
This class implements the Leaky Integrate-and-Fire neuron model, which extends the basic Integrate-and-Fire model by adding a leak term. The leak causes the membrane potential to decay towards a resting value in the absence of input, making the model more biologically plausible.
The model is characterized by the following differential equation:
\[ \tau \frac{dV}{dt} = -(V - V_{rest}) + R \cdot I(t) \]Spike condition: If \(V \geq V_{th}\): emit spike and reset \(V = V_{reset}\)
- 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.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
See also
Notes
The leak term causes the membrane potential to decay exponentially towards V_rest with time constant tau when no input is present.
The time-dependent dynamics are integrated using an exponential Euler method.
Spike generation is non-differentiable, so surrogate gradients are used for backpropagation during training.
References
Examples
>>> import brainpy >>> import brainstate >>> import saiunit as u >>> # Create a LIF neuron layer with 10 neurons >>> lif = brainpy.state.LIF(10, tau=10*u.ms, V_th=0.8*u.mV) >>> # Initialize the state >>> lif.init_state(batch_size=1) >>> # Apply an input current and update the neuron state >>> spikes = lif.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.