snn.Alpha
- class snntorch._neurons.alpha.Alpha(alpha, beta, threshold=1.0, spike_grad=None, surrogate_disable=False, init_hidden=False, inhibition=False, learn_alpha=False, learn_beta=False, learn_threshold=False, reset_mechanism='zero', state_quant=False, output=False)[source]
Bases:
LIF
A variant of the leaky integrate and fire neuron where membrane potential follows an alpha function. The time course of the membrane potential response depends on a combination of exponentials. In general, this causes the change in membrane potential to experience a delay with respect to an input spike. For \(U[T] > U_{\rm thr} ⇒ S[T+1] = 1\).
Warning
For a positive input current to induce a positive membrane response, ensure \(α > β\).
If reset_mechanism = “zero”, then \(I_{\rm exc}, I_{\rm inh}\) will both be set to 0 whenever the neuron emits a spike:
\[\begin{split}I_{\rm exc}[t+1] = (αI_{\rm exc}[t] + I_{\rm in}[t+1]) - R(αI_{\rm exc}[t] + I_{\rm in}[t+1]) \\ I_{\rm inh}[t+1] = (βI_{\rm inh}[t] - I_{\rm in}[t+1]) - R(βI_{\rm inh}[t] - I_{\rm in}[t+1]) \\ U[t+1] = τ_{\rm α}(I_{\rm exc}[t+1] + I_{\rm inh}[t+1])\end{split}\]\(I_{\rm exc}\) - Excitatory current
\(I_{\rm inh}\) - Inhibitory current
\(I_{\rm in}\) - Input current
\(U\) - Membrane potential
\(U_{\rm thr}\) - Membrane threshold
\(R\) - Reset mechanism, \(R = 1\) if spike occurs, otherwise \(R = 0\)
\(α\) - Excitatory current decay rate
\(β\) - Inhibitory current decay rate
\(τ_{\rm α} = \frac{log(α)}{log(β)} - log(α) + 1\)
Example:
import torch import torch.nn as nn import snntorch as snn alpha = 0.9 beta = 0.8 # Define Network class Net(nn.Module): def __init__(self): super().__init__() # initialize layers self.fc1 = nn.Linear(num_inputs, num_hidden) self.lif1 = snn.Alpha(alpha=alpha, beta=beta) self.fc2 = nn.Linear(num_hidden, num_outputs) self.lif2 = snn.Alpha(alpha=alpha, beta=beta) def forward(self, x, syn_exc1, syn_inh1, mem1, spk1, syn_exc2, syn_inh2, mem2): cur1 = self.fc1(x) spk1, syn_exc1, syn_inh1, mem1 = self.lif1(cur1, syn_exc1, syn_inh1, mem1) cur2 = self.fc2(spk1) spk2, syn_exc2, syn_inh2, mem2 = self.lif2(cur2, syn_exc2, syn_inh2, mem2) return syn_exc1, syn_inh1, mem1, spk1, syn_exc2, syn_inh2, mem2, spk2 # Too many state variables which becomes cumbersome, so the # following is also an option: alpha = 0.9 beta = 0.8 net = nn.Sequential(nn.Linear(num_inputs, num_hidden), snn.Alpha(alpha=alpha, beta=beta, init_hidden=True), nn.Linear(num_hidden, num_outputs), snn.Alpha(alpha=alpha, beta=beta, init_hidden=True, output=True))
Used to detach hidden states from the current graph. Intended for use in truncated backpropagation through time where hidden state variables are instance variables.
- forward(input_, syn_exc=None, syn_inh=None, mem=None)[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- init_alpha()[source]
Deprecated, use
Alpha.reset_mem
instead
Used to clear hidden state variables to zero. Intended for use where hidden state variables are instance variables.