IF#

class brainpy.state.IF(in_size, R=Quantity(1., "ohm"), tau=Quantity(5., "ms"), V_th=Quantity(1., "mV"), V_initializer=Constant(value=0. mV), spk_fun=ReluGrad(alpha=0.3, width=1.0), spk_reset='soft', name=None)#

Integrate-and-Fire (IF) neuron model.

This class implements the classic Integrate-and-Fire neuron model, one of the simplest spiking neuron models. It accumulates input current until the membrane potential reaches a threshold, at which point it fires a spike and resets the potential.

The model is characterized by the following differential equation:

\[ \tau \frac{dV}{dt} = -V + R \cdot I(t) \]

Spike condition: If \(V \geq V_{th}\): emit spike and reset \(V = V - V_{th}\) (soft reset) or \(V = 0\) (hard reset)

Parameters:
  • in_size (Size) – Size of the input to the neuron.

  • R (ArrayLike, default 1. * u.ohm) – Membrane resistance.

  • tau (ArrayLike, default 5. * u.ms) – Membrane time constant.

  • V_th (ArrayLike, default 1. * u.mV) – Firing threshold voltage (should be positive).

  • V_initializer (Callable) – Initializer for the membrane potential state.

  • spk_fun (Callable, default surrogate.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_gradient

  • name (str, optional) – Name of the neuron layer.

V#

Membrane potential.

Type:

HiddenState

See also

LIF

Leaky integrate-and-fire with resting potential.

QuaIF

Quadratic integrate-and-fire with nonlinear dynamics.

Notes

  • Unlike the LIF model, the IF model has no leak towards a resting potential.

  • The membrane potential decays exponentially with time constant tau in the absence of input.

  • The time-dependent dynamics are integrated using an exponential Euler method.

  • The IF model is perfect integrator in the sense that it accumulates input indefinitely until reaching threshold, without any leak current.

  • The integrate-and-fire model was first introduced by Lapicque [1] [2].

  • For a comprehensive review of integrate-and-fire models, see [3].

References

Examples

>>> import brainpy
>>> import brainstate
>>> import saiunit as u
>>> # Create an IF neuron layer with 10 neurons
>>> if_neuron = brainpy.state.IF(10, tau=8*u.ms, V_th=1.2*u.mV)
>>> # Initialize the state
>>> if_neuron.init_state(batch_size=1)
>>> # Apply an input current and update the neuron state
>>> spikes = if_neuron.update(x=2.0*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_fun to 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.

init_state(batch_size=None, **kwargs)[source]#

State initialization function.

reset_state(batch_size=None, **kwargs)[source]#

State resetting function.