Gif#

class brainpy.state.Gif(in_size, R=Quantity(20., "ohm"), tau=Quantity(20., "ms"), V_rest=Quantity(-70., "mV"), V_reset=Quantity(-70., "mV"), V_th_inf=Quantity(-50., "mV"), V_th_reset=Quantity(-60., "mV"), V_th_initializer=Constant(value=-50. mV), a=Quantity(0., "kHz"), b=Quantity(0.01, "kHz"), k1=Quantity(0.2, "kHz"), k2=Quantity(0.02, "kHz"), R1=0.0, R2=1.0, A1=Quantity(0., "mA"), A2=Quantity(0., "mA"), V_initializer=Constant(value=-70. mV), I1_initializer=Constant(value=0. mA), I2_initializer=Constant(value=0. mA), spk_fun=ReluGrad(alpha=0.3, width=1.0), spk_reset='soft', name=None)#

Generalized Integrate-and-Fire (Gif) neuron model.

This model extends the basic integrate-and-fire neuron by adding internal currents and a dynamic threshold. The model can reproduce diverse firing patterns observed in biological neurons.

The model is characterized by the following equations:

\[ \frac{dI_1}{dt} = -k_1 I_1 \]

\[ \frac{dI_2}{dt} = -k_2 I_2 \]

\[ \tau \frac{dV}{dt} = -(V - V_{rest}) + R(I_1 + I_2 + I(t)) \]

\[ \frac{dV_{th}}{dt} = a(V - V_{rest}) - b(V_{th} - V_{th\infty}) \]

When \(V \geq V_{th}\): - \(I_1 \leftarrow R_1 I_1 + A_1\) - \(I_2 \leftarrow R_2 I_2 + A_2\) - \(V \leftarrow V_{reset}\) - \(V_{th} \leftarrow \max(V_{th_{reset}}, V_{th})\)

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

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

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

  • V_rest (ArrayLike, default -70. * u.mV) – Resting potential.

  • V_reset (ArrayLike, default -70. * u.mV) – Reset potential after spike.

  • V_th_inf (ArrayLike, default -50. * u.mV) – Target value of threshold potential updating.

  • V_th_reset (ArrayLike, default -60. * u.mV) – Free parameter, should be larger than V_reset.

  • V_th_initializer (Callable) – Initializer for the threshold potential.

  • a (ArrayLike, default 0. / u.ms) – Coefficient describes dependence of V_th on membrane potential.

  • b (ArrayLike, default 0.01 / u.ms) – Coefficient describes V_th update.

  • k1 (ArrayLike, default 0.2 / u.ms) – Constant of I1.

  • k2 (ArrayLike, default 0.02 / u.ms) – Constant of I2.

  • R1 (ArrayLike, default 0.) – Free parameter describing dependence of I1 reset value on I1 before spiking.

  • R2 (ArrayLike, default 1.) – Free parameter describing dependence of I2 reset value on I2 before spiking.

  • A1 (ArrayLike, default 0. * u.mA) – Free parameter.

  • A2 (ArrayLike, default 0. * u.mA) – Free parameter.

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

  • I1_initializer (Callable) – Initializer for internal current I1.

  • I2_initializer (Callable) – Initializer for internal current I2.

  • spk_fun (Callable, default surrogate.ReluGrad()) – Surrogate gradient function.

  • spk_reset (str, default 'soft') – Reset mechanism after spike generation.

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

V#

Membrane potential.

Type:

HiddenState

I1#

Internal current 1.

Type:

HiddenState

I2#

Internal current 2.

Type:

HiddenState

V_th#

Spiking threshold potential.

Type:

HiddenState

See also

GifRef

Gif with absolute refractory period.

ALIF

Simpler adaptive LIF model.

AdExIF

Adaptive exponential IF (alternative complex model).

Notes

  • The Gif model uses internal currents (I1, I2) for complex dynamics [1].

  • Dynamic threshold V_th adapts based on membrane potential and its own dynamics.

  • Can reproduce diverse firing patterns: regular spiking, bursting, adaptation.

  • Parameters a and b control threshold adaptation.

  • Parameters k1, k2, R1, R2, A1, A2 control internal current dynamics.

  • More flexible than simpler IF models for matching biological data [2].

References

Examples

>>> import brainpy
>>> import brainstate
>>> import saiunit as u
>>> # Create a Gif neuron layer with dynamic threshold
>>> gif = brainpy.state.Gif(10, tau=20*u.ms, k1=0.2/u.ms,
...                         k2=0.02/u.ms, a=0.005/u.ms, b=0.01/u.ms)
>>> # Initialize the state
>>> gif.init_state(batch_size=1)
>>> # Apply input and observe diverse firing patterns
>>> spikes = gif.update(x=1.5*u.mA)
get_spike(V=None, V_th=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.