norse.torch.functional.lif module

A very popular neuron model that combines a norse.torch.functional.leaky_integrator with spike thresholds to produce events (spikes).

The model describes the change in a neuron membrane voltage (\(v\)) and inflow current (\(i\)). See the leaky_integrator module for more information.

\[\begin{split}\begin{align*} \dot{v} &= 1/\tau_{\text{mem}} (v_{\text{leak}} - v + i) \\ \dot{i} &= 1/\tau_{\text{syn}} i \end{align*}\end{split}\]

The F in LIF stands for the thresholded “firing” events that occur if the neuron voltage increases over a certain point or threshold (\(v_{\text{th}}\)).

\[z = \Theta(v - v_{\text{th}})\]

In regular artificial neural networks, this is referred to as the activation function. The behaviour can be controlled by setting the method field in the neuron parameters, but will default to the superspike synthetic gradient approach that uses the heaviside step function:

\[\begin{split}H[n]=\begin{cases} 0, & n <= 0 \\ 1, & n \gt 0 \end{cases}\end{split}\]
class norse.torch.functional.lif.LIFFeedForwardState(v: torch.Tensor, i: torch.Tensor)[source]

Bases: tuple

State of a feed forward LIF neuron

Parameters

Create new instance of LIFFeedForwardState(v, i)

i: torch.Tensor

Alias for field number 1

v: torch.Tensor

Alias for field number 0

class norse.torch.functional.lif.LIFParameters(tau_syn_inv: torch.Tensor = tensor(200.), tau_mem_inv: torch.Tensor = tensor(100.), v_leak: torch.Tensor = tensor(0.), v_th: torch.Tensor = tensor(1.), v_reset: torch.Tensor = tensor(0.), method: str = 'super', alpha: float = tensor(100.))[source]

Bases: tuple

Parametrization of a LIF neuron

Parameters
  • tau_syn_inv (torch.Tensor) – inverse synaptic time constant (\(1/\tau_\text{syn}\)) in 1/ms

  • tau_mem_inv (torch.Tensor) – inverse membrane time constant (\(1/\tau_\text{mem}\)) in 1/ms

  • v_leak (torch.Tensor) – leak potential in mV

  • v_th (torch.Tensor) – threshold potential in mV

  • v_reset (torch.Tensor) – reset potential in mV

  • method (str) – method to determine the spike threshold (relevant for surrogate gradients)

  • alpha (float) – hyper parameter to use in surrogate gradient computation

Create new instance of LIFParameters(tau_syn_inv, tau_mem_inv, v_leak, v_th, v_reset, method, alpha)

alpha: float

Alias for field number 6

method: str

Alias for field number 5

tau_mem_inv: torch.Tensor

Alias for field number 1

tau_syn_inv: torch.Tensor

Alias for field number 0

v_leak: torch.Tensor

Alias for field number 2

v_reset: torch.Tensor

Alias for field number 4

v_th: torch.Tensor

Alias for field number 3

class norse.torch.functional.lif.LIFParametersJIT(tau_syn_inv: torch.Tensor, tau_mem_inv: torch.Tensor, v_leak: torch.Tensor, v_th: torch.Tensor, v_reset: torch.Tensor, method: str, alpha: torch.Tensor)[source]

Bases: tuple

Parametrization of a LIF neuron

Parameters
  • tau_syn_inv (torch.Tensor) – inverse synaptic time constant (\(1/\tau_\text{syn}\)) in 1/ms

  • tau_mem_inv (torch.Tensor) – inverse membrane time constant (\(1/\tau_\text{mem}\)) in 1/ms

  • v_leak (torch.Tensor) – leak potential in mV

  • v_th (torch.Tensor) – threshold potential in mV

  • v_reset (torch.Tensor) – reset potential in mV

  • method (str) – method to determine the spike threshold (relevant for surrogate gradients)

  • alpha (torch.Tensor) – hyper parameter to use in surrogate gradient computation

Create new instance of LIFParametersJIT(tau_syn_inv, tau_mem_inv, v_leak, v_th, v_reset, method, alpha)

alpha: torch.Tensor

Alias for field number 6

method: str

Alias for field number 5

tau_mem_inv: torch.Tensor

Alias for field number 1

tau_syn_inv: torch.Tensor

Alias for field number 0

v_leak: torch.Tensor

Alias for field number 2

v_reset: torch.Tensor

Alias for field number 4

v_th: torch.Tensor

Alias for field number 3

class norse.torch.functional.lif.LIFState(z: torch.Tensor, v: torch.Tensor, i: torch.Tensor)[source]

Bases: tuple

State of a LIF neuron

Parameters

Create new instance of LIFState(z, v, i)

i: torch.Tensor

Alias for field number 2

v: torch.Tensor

Alias for field number 1

z: torch.Tensor

Alias for field number 0

norse.torch.functional.lif.lif_current_encoder(input_current, voltage, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Computes a single euler-integration step of a leaky integrator. More specifically it implements one integration step of the following ODE

\[\begin{split}\begin{align*} \dot{v} &= 1/\tau_{\text{mem}} (v_{\text{leak}} - v + i) \\ \dot{i} &= -1/\tau_{\text{syn}} i \end{align*}\end{split}\]
Parameters
  • input (torch.Tensor) – the input current at the current time step

  • voltage (torch.Tensor) – current state of the LIF neuron

  • p (LIFParameters) – parameters of a leaky integrate and fire neuron

  • dt (float) – Integration timestep to use

Return type

Tuple[Tensor, Tensor]

norse.torch.functional.lif.lif_feed_forward_integral(input_tensor, state, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Computes multiple euler-integration steps of a LIF neuron-model. More specifically it integrates the following ODE

\[\begin{split}\begin{align*} \dot{v} &= 1/\tau_{\text{mem}} (v_{\text{leak}} - v + i) \\ \dot{i} &= -1/\tau_{\text{syn}} i \end{align*}\end{split}\]

together with the jump condition

\[z = \Theta(v - v_{\text{th}})\]

and transition equations

\[\begin{split}\begin{align*} v &= (1-z) v + z v_{\text{reset}} \\ i &= i + i_{\text{in}} \end{align*}\end{split}\]
Parameters
  • input_tensor (torch.Tensor) – the input spikes with the outer dimension assumed to be timesteps

  • s (LIFState) – current state of the LIF neuron

  • p (LIFParameters) – parameters of a leaky integrate and fire neuron

  • dt (float) – Integration timestep to use

Return type

Tuple[Tensor, LIFState]

norse.torch.functional.lif.lif_feed_forward_step(input_tensor, state, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Computes a single euler-integration step for a lif neuron-model. It takes as input the input current as generated by an arbitrary torch module or function. More specifically it implements one integration step of the following ODE

\[\begin{split}\begin{align*} \dot{v} &= 1/\tau_{\text{mem}} (v_{\text{leak}} - v + i) \\ \dot{i} &= -1/\tau_{\text{syn}} i \end{align*}\end{split}\]

together with the jump condition

\[z = \Theta(v - v_{\text{th}})\]

and transition equations

\[\begin{split}\begin{align*} v &= (1-z) v + z v_{\text{reset}} \\ i &= i + i_{\text{in}} \end{align*}\end{split}\]

where \(i_{\text{in}}\) is meant to be the result of applying an arbitrary pytorch module (such as a convolution) to input spikes.

Parameters
  • input_tensor (torch.Tensor) – the input spikes at the current time step

  • state (LIFFeedForwardState) – current state of the LIF neuron

  • p (LIFParameters) – parameters of a leaky integrate and fire neuron

  • dt (float) – Integration timestep to use

Return type

Tuple[Tensor, LIFFeedForwardState]

norse.torch.functional.lif.lif_feed_forward_step_sparse(input_tensor, state, p, dt=0.001)[source]
Return type

Tuple[Tensor, LIFFeedForwardState]

norse.torch.functional.lif.lif_step(input_tensor, state, input_weights, recurrent_weights, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Computes a single euler-integration step of a LIF neuron-model. More specifically it implements one integration step of the following ODE

\[\begin{split}\begin{align*} \dot{v} &= 1/\tau_{\text{mem}} (v_{\text{leak}} - v + i) \\ \dot{i} &= -1/\tau_{\text{syn}} i \end{align*}\end{split}\]

together with the jump condition

\[z = \Theta(v - v_{\text{th}})\]

and transition equations

\[\begin{split}\begin{align*} v &= (1-z) v + z v_{\text{reset}} \\ i &= i + w_{\text{input}} z_{\text{in}} \\ i &= i + w_{\text{rec}} z_{\text{rec}} \end{align*}\end{split}\]

where \(z_{\text{rec}}\) and \(z_{\text{in}}\) are the recurrent and input spikes respectively.

Parameters
  • input_tensor (torch.Tensor) – the input spikes at the current time step

  • s (LIFState) – current state of the LIF neuron

  • input_weights (torch.Tensor) – synaptic weights for incoming spikes

  • recurrent_weights (torch.Tensor) – synaptic weights for recurrent spikes

  • p (LIFParameters) – parameters of a leaky integrate and fire neuron

  • dt (float) – Integration timestep to use

Return type

Tuple[Tensor, LIFState]

norse.torch.functional.lif.lif_step_integral(input_tensor, state, input_weights, recurrent_weights, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]

Computes multiple euler-integration steps of a LIF neuron-model. More specifically it integrates the following ODE

\[\begin{split}\begin{align*} \dot{v} &= 1/\tau_{\text{mem}} (v_{\text{leak}} - v + i) \\ \dot{i} &= -1/\tau_{\text{syn}} i \end{align*}\end{split}\]

together with the jump condition

\[z = \Theta(v - v_{\text{th}})\]

and transition equations

\[\begin{split}\begin{align*} v &= (1-z) v + z v_{\text{reset}} \\ i &= i + w_{\text{input}} z_{\text{in}} \\ i &= i + w_{\text{rec}} z_{\text{rec}} \end{align*}\end{split}\]

where \(z_{\text{rec}}\) and \(z_{\text{in}}\) are the recurrent and input spikes respectively.

Parameters
  • input_tensor (torch.Tensor) – the input spikes, assuming the outer (first) dimension is time

  • s (LIFState) – current state of the LIF neuron

  • input_weights (torch.Tensor) – synaptic weights for incoming spikes

  • recurrent_weights (torch.Tensor) – synaptic weights for recurrent spikes

  • p (LIFParameters) – parameters of a leaky integrate and fire neuron

  • dt (float) – Integration timestep to use

Return type

Tuple[Tensor, LIFState]

Returns

A tuple of (spike output from all timesteps, neuron state from the final timestep)

norse.torch.functional.lif.lif_step_sparse(input_tensor, state, input_weights, recurrent_weights, p=LIFParameters(tau_syn_inv=tensor(200.), tau_mem_inv=tensor(100.), v_leak=tensor(0.), v_th=tensor(1.), v_reset=tensor(0.), method='super', alpha=tensor(100.)), dt=0.001)[source]
Return type

Tuple[Tensor, LIFState]