Research-specific Neuron Modules#

特定研究的神经元 模块包含为特定研究目的或实验场景提出的神经元模型。 这些神经元通常源自具体论文,其适用范围和使用频率相比 核心神经元 而言更加有限。

这类神经元通常具有以下特征:

  • 由某一具体论文提出。

  • 专用于特定训练方法或任务,依赖于这些场景所引入的假设。

特定研究的神经元旨在支持研究复现与实验探索。虽然它们同样受到完整支持,但并不被视为核心抽象的一部分。用户在使用时应充分理解其设计初衷、适用范围及潜在局限性。


Research-specific neuron modules contain neuron models that are proposed for particular research purposes or experimental settings. These neurons often originate from specific papers and are not so widely used as Core Neuron Modules.

Typical characteristics of research-specific neurons include:

  • Introduced by a specific paper.

  • Dependence on assumptions introduced by a particular learning method or task setting.

These modules are provided to facilitate reproducibility and experimentation. While fully supported, they are not considered part of the core abstraction. Users should adopt them with an understanding of their intended scope and limitations.

Adaptive Neurons#

class spikingjelly.activation_based.neuron.adapt.AdaptBaseNode(v_threshold: float = 1.0, v_reset: float | None = 0.0, v_rest: float = 0.0, w_rest: float = 0.0, tau_w: float = 2.0, a: float = 0.0, b: float = 0.0, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, step_mode='s', backend='torch', store_v_seq: bool = False)[源代码]#

基类:BaseNode

API Language: 中文 | English


  • 中文

带适应性电流的脉冲神经元基类。在 BaseNode 的基础上增加了膜电位恢复变量 \(w\),用于实现神经元适应性和脉冲频率适应性。

参数:
  • v_threshold (float) -- 神经元的阈值电压

  • v_reset (Optional[float]) -- 重置电压。若为 None 则使用软重置

  • v_rest (float) -- 静息电位

  • w_rest (float) -- 适应性电流的静息值

  • tau_w (float) -- 适应性电流的时间常数

  • a (float) -- 阈下耦合参数,控制亚阈值电位对适应电流的影响

  • b (float) -- 脉冲触发跳跃幅度,控制脉冲后适应电流的增加量

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 替代梯度函数

  • detach_reset (bool) -- 是否将重置过程的计算图分离

  • step_mode (str) -- 步进模式,可为 's' (单步) 或 'm' (多步)

  • backend (str) -- 后端

  • store_v_seq (bool) -- 是否保存中间电压值


  • English

Base neuron with adaptation current. Extends BaseNode with a membrane recovery variable \(w\) that provides spike-frequency adaptation.

参数:
  • v_threshold (float) -- Threshold voltage of the neuron

  • v_reset (Optional[float]) -- Reset voltage. If None, uses soft reset

  • v_rest (float) -- Resting potential

  • w_rest (float) -- Resting value of the adaptation current

  • tau_w (float) -- Time constant of the adaptation current

  • a (float) -- Subthreshold coupling parameter, controls subthreshold influence on adaptation current

  • b (float) -- Spike-triggered jump amplitude, controls adaptation current increase after each spike

  • surrogate_function (surrogate.SurrogateFunctionBase) -- Surrogate gradient function

  • detach_reset (bool) -- Whether to detach the reset computation graph

  • step_mode (str) -- Step mode, can be 's' (single-step) or 'm' (multi-step)

  • backend (str) -- Backend for computation

  • store_v_seq (bool) -- Whether to store intermediate membrane potentials

返回:

None

返回类型:

None

static jit_neuronal_adaptation(w: Tensor, tau_w: float, a: float, v_rest: float, v: Tensor)[源代码]#
neuronal_adaptation()[源代码]#

API Language: 中文 | English


  • 中文

脉冲触发的适应性电流的更新


  • English

Spike-triggered update of adaptation current.

static apply_hard_reset(v: Tensor, w: Tensor, spike_d: Tensor, v_reset: float, b: float, spike: Tensor)[源代码]#
static apply_soft_reset(v: Tensor, w: Tensor, spike_d: Tensor, v_threshold: float, b: float, spike: Tensor)[源代码]#
neuronal_reset(spike)[源代码]#

API Language: 中文 | English


  • 中文

根据当前神经元释放的脉冲,对膜电位进行重置。


  • English

Reset the membrane potential according to neurons' output spikes.

single_step_forward(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

按照充电、适应、放电、重置的顺序进行前向传播。

参数:

x (torch.Tensor) -- 输入到神经元的电压增量

返回:

神经元的输出脉冲

返回类型:

torch.Tensor


  • English

Forward by the order of neuronal_charge, neuronal_adaptation, neuronal_fire, and neuronal_reset.

参数:

x (torch.Tensor) -- increment of voltage inputted to neurons

返回:

out spikes of neurons

返回类型:

torch.Tensor

class spikingjelly.activation_based.neuron.adapt.IzhikevichNode(tau: float = 2.0, v_c: float = 0.8, a0: float = 1.0, v_threshold: float = 1.0, v_reset: float | None = 0.0, v_rest: float = -0.1, w_rest: float = 0.0, tau_w: float = 2.0, a: float = 0.0, b: float = 0.0, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, step_mode='s', backend='torch', store_v_seq: bool = False)[源代码]#

基类:AdaptBaseNode

API Language: 中文 | English


  • 中文

Izhikevich 脉冲神经元模型。参数 \(\tau\) 控制膜电位时间常数,\(v_c\)\(a0\) 控制非线性 dynamics。 继承了 AdaptBaseNode 的适应性电流机制。

参数:
  • tau (float) -- 膜电位时间常数

  • v_c (float) -- 截止电压,控制非线性响应的阈值

  • a0 (float) -- 非线性系数

  • v_threshold (float) -- 阈值电压

  • v_reset (Optional[float]) -- 重置电压

  • v_rest (float) -- 静息电位

  • w_rest (float) -- 适应性电流静息值

  • tau_w (float) -- 适应性电流时间常数

  • a (float) -- 阈下耦合参数

  • b (float) -- 脉冲触发跳跃幅度

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 替代梯度函数

  • detach_reset (bool) -- 是否分离重置计算图

  • step_mode (str) -- 步进模式

  • backend (str) -- 后端

  • store_v_seq (bool) -- 是否保存中间电压值


  • English

Izhikevich spiking neuron model. The parameters \(\tau\), \(v_c\), and \(a0\) control membrane dynamics. Inherits the adaptation current mechanism from AdaptBaseNode.

参数:
  • tau (float) -- Membrane time constant

  • v_c (float) -- Cutoff voltage controlling the nonlinear response threshold

  • a0 (float) -- Nonlinear coefficient

  • v_threshold (float) -- Threshold voltage

  • v_reset (Optional[float]) -- Reset voltage

  • v_rest (float) -- Resting potential

  • w_rest (float) -- Resting value of adaptation current

  • tau_w (float) -- Time constant of adaptation current

  • a (float) -- Subthreshold coupling parameter

  • b (float) -- Spike-triggered jump amplitude

  • surrogate_function (surrogate.SurrogateFunctionBase) -- Surrogate gradient function

  • detach_reset (bool) -- Whether to detach reset computation graph

  • step_mode (str) -- Step mode, 's' or 'm'

  • backend (str) -- Backend

  • store_v_seq (bool) -- Whether to store intermediate membrane potentials

返回:

None

返回类型:

None

neuronal_charge(x: Tensor)[源代码]#
multi_step_forward(x_seq: Tensor)[源代码]#

Nonlinear Integrate-and-fire Neurons#

class spikingjelly.activation_based.neuron.nonlinear_if.QIFNode(tau: float = 2.0, v_c: float = 0.8, a0: float = 1.0, v_threshold: float = 1.0, v_rest: float = 0.0, v_reset: float | None = -0.1, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, step_mode='s', backend='torch', store_v_seq: bool = False)[源代码]#

基类:BaseNode

API Language: 中文 | English


  • 中文

QIF(Quadratic Integrate-and-Fire)神经元的构造函数。

QIF 神经元是一种非线性积分发放神经元模型,也是指数积分发放神经元(EIF)的近似版本。

阈下动力学方程

\[H[t] = V[t-1] + \frac{1}{\tau}\left(X[t] + a_0 (V[t-1] - V_{rest})(V[t-1] - V_c)\right)\]
参数:
  • tau (float) -- 膜电位时间常数

  • v_c (float) -- 临界电压

  • a0 (float) -- 二次系数

  • v_threshold (float) -- 神经元的放电阈值

  • v_rest (float) -- 静息电位

  • v_reset (Optional[float]) -- 神经元的重置电压。若不为 None,放电后膜电位将被重置为 v_reset; 若为 None,则放电后膜电位减去 v_threshold

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 反向传播中用于近似阶跃函数梯度的替代函数

  • detach_reset (bool) -- 是否在反向传播时将 reset 过程从计算图中分离

  • step_mode (str) -- 步进模式,可选 's' (单步)或 'm' (多步)

  • backend (str) -- 计算后端。不同 step_mode 支持的后端可能不同,可通过 self.supported_backends 查看。 在支持的情况下,'cupy''triton' 后端通常具有最高的执行效率

  • store_v_seq (bool) -- 当 step_mode = 'm' 且输入形状为 [T, N, *] 时,是否保存所有时间步的膜电位序列 self.v_seq``(形状为 ``[T, N, *])。 若为 False,仅保留最后一个时间步的膜电位 self.v``(形状为 ``[N, *]),以降低内存开销


  • English

Constructor of the Quadratic Integrate-and-Fire (QIF) neuron.

The QIF neuron is a nonlinear integrate-and-fire model and an approximation of the Exponential Integrate-and-Fire (EIF) neuron.

Sub-threshold neuronal dynamics

\[H[t] = V[t-1] + \frac{1}{\tau}\left(X[t] + a_0 (V[t-1] - V_{rest})(V[t-1] - V_c)\right)\]
参数:
  • tau (float) -- membrane time constant

  • v_c (float) -- critical voltage

  • a0 (float) -- quadratic coefficient

  • v_threshold (float) -- firing threshold of the neuron

  • v_rest (float) -- resting potential

  • v_reset (Optional[float]) -- reset voltage of the neuron. If not None, the membrane potential will be reset to v_reset after firing; otherwise, v_threshold will be subtracted

  • surrogate_function (surrogate.SurrogateFunctionBase) -- surrogate function used to approximate the gradient of the Heaviside step function during backpropagation

  • detach_reset (bool) -- whether to detach the reset operation from the computation graph

  • step_mode (str) -- step mode, either 's' (single-step) or 'm' (multi-step)

  • backend (str) -- backend for this neuron. Different step_mode may support different backends. Supported backends can be queried via self.supported_backends. If available, 'cupy' or 'triton' usually provides the fastest execution

  • store_v_seq (bool) -- when step_mode = 'm' and input shape is [T, N, *], whether to store the membrane potential at all time steps in self.v_seq. If False, only the final membrane potential self.v is kept to reduce memory usage

返回:

None

返回类型:

None

neuronal_charge(x: Tensor)[源代码]#
multi_step_forward(x_seq: Tensor)[源代码]#
class spikingjelly.activation_based.neuron.nonlinear_if.EIFNode(tau: float = 2.0, delta_T: float = 1.0, theta_rh: float = 0.8, v_threshold: float = 1.0, v_rest: float = 0.0, v_reset: float | None = -0.1, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, step_mode='s', backend='torch', store_v_seq: bool = False)[源代码]#

基类:BaseNode

API Language: 中文 | English


  • 中文

EIF(Exponential Integrate-and-Fire)神经元的构造函数。

EIF 神经元是一种非线性积分发放神经元模型,由 Hodgkin-Huxley 模型简化得到的一维模型。 当 \(\Delta_T \to 0\) 时,退化为普通的 LIF 神经元。

阈下动力学方程

\[H[t] = V[t-1] + \frac{1}{\tau}\left(X[t] - (V[t-1] - V_{rest}) + \Delta_T\exp\left(\frac{V[t-1] - \theta_{rh}}{\Delta_T}\right)\right)\]
参数:
  • tau (float) -- 膜电位时间常数

  • delta_T (float) -- 陡峭度参数

  • theta_rh (float) -- 基强度电压阈值

  • v_threshold (float) -- 神经元的放电阈值

  • v_reset (Optional[float]) -- 神经元的重置电压。若不为 None,放电后膜电位将被重置为 v_reset; 若为 None,则放电后膜电位减去 v_threshold

  • v_rest (float) -- 静息电位

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 反向传播中用于近似阶跃函数梯度的替代函数

  • detach_reset (bool) -- 是否在反向传播时将 reset 过程从计算图中分离

  • step_mode (str) -- 步进模式,可选 's' (单步)或 'm' (多步)

  • backend (str) -- 计算后端。不同 step_mode 支持的后端可能不同,可通过 self.supported_backends 查看。 在支持的情况下,'cupy''triton' 后端通常具有最高的执行效率

  • store_v_seq (bool) -- 当 step_mode = 'm' 且输入形状为 [T, N, *] 时,是否保存所有时间步的膜电位序列 self.v_seq``(形状为 ``[T, N, *])。 若为 False,仅保留最后一个时间步的膜电位 self.v``(形状为 ``[N, *]),以降低内存开销


  • English

Constructor of the Exponential Integrate-and-Fire (EIF) neuron.

The EIF neuron is a nonlinear integrate-and-fire model derived from the Hodgkin-Huxley model. It degenerates to the LIF model when \(\Delta_T \to 0\).

Sub-threshold neuronal dynamics

\[H[t] = V[t-1] + \frac{1}{\tau}\left(X[t] - (V[t-1] - V_{rest}) + \Delta_T\exp\left(\frac{V[t-1] - \theta_{rh}}{\Delta_T}\right)\right)\]
参数:
  • tau (float) -- membrane time constant

  • delta_T (float) -- sharpness parameter

  • theta_rh (float) -- rheobase threshold

  • v_threshold (float) -- firing threshold of the neuron

  • v_reset (Optional[float]) -- reset voltage of the neuron. If not None, the membrane potential will be reset to v_reset after firing; otherwise, v_threshold will be subtracted

  • v_rest (float) -- resting potential

  • surrogate_function (surrogate.SurrogateFunctionBase) -- surrogate function used to approximate the gradient of the Heaviside step function during backpropagation

  • detach_reset (bool) -- whether to detach the reset operation from the computation graph

  • step_mode (str) -- step mode, either 's' (single-step) or 'm' (multi-step)

  • backend (str) -- backend for this neuron. Different step_mode may support different backends. Supported backends can be queried via self.supported_backends. If available, 'cupy' or 'triton' usually provides the fastest execution

  • store_v_seq (bool) -- when step_mode = 'm' and input shape is [T, N, *], whether to store the membrane potential at all time steps in self.v_seq. If False, only the final membrane potential self.v is kept to reduce memory usage

返回:

None

返回类型:

None

neuronal_charge(x: Tensor)[源代码]#
multi_step_forward(x_seq: Tensor)[源代码]#

LIF Variants#

class spikingjelly.activation_based.neuron.lif_variants.GatedLIFNode(T: int, inplane=None, init_linear_decay=None, init_v_subreset=None, init_tau: float = 0.25, init_v_threshold: float = 0.5, init_conduct: float = 0.5, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), step_mode='m', backend='torch')[源代码]#

基类:MemoryModule

API Language: 中文 | English


  • 中文

Gated LIF 神经元(GLIF),由 GLIF: A Unified Gated Leaky Integrate-and-Fire Neuron for Spiking Neural Networks 提出。 该模型对 LIF 神经元进行统一门控建模,膜电位相关参数(包括门控系数)均为可学习参数。

参数:
  • T (int) -- 时间步数

  • inplane (int) -- 输入张量的通道数。 若为 None,则使用 layer-wise GLIF;否则使用 channel-wise GLIF

  • init_linear_decay (float) -- 膜电位线性衰减系数的初始值。 若不设置,默认值为 init_v_threshold / (T * 2)

  • init_v_subreset (float) -- 膜电位软复位电压的初始值

  • init_tau (float) -- 膜电位指数衰减时间常数的初始值

  • init_v_threshold (float) -- 神经元阈值电压的初始值

  • init_conduct (float) -- 膜电位电导率的初始值

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 反向传播中用于计算脉冲函数梯度的替代函数

  • step_mode (str) -- 步进模式,仅支持 'm' (多步)

  • backend (str) -- 使用的后端。不同 step_mode 支持的后端可能不同。 可通过 self.supported_backends 查看当前步进模式支持的后端。 Gated LIF 仅支持 'torch' 后端


  • English

Gated LIF neuron (GLIF), proposed in GLIF: A Unified Gated Leaky Integrate-and-Fire Neuron for Spiking Neural Networks. This model introduces unified gating mechanisms into LIF neurons. All membrane-related parameters, including gating coefficients, are learnable.

参数:
  • T (int) -- number of time-steps

  • inplane (int) -- number of channels of the input tensor. If None, layer-wise GLIF is used; otherwise, channel-wise GLIF is applied

  • init_linear_decay (float) -- initial value of the linear decay coefficient. Defaults to init_v_threshold / (T * 2) if not specified

  • init_v_subreset (float) -- initial soft-reset voltage of the membrane potential

  • init_tau (float) -- initial exponential decay time constant of the membrane potential

  • init_v_threshold (float) -- initial membrane potential threshold

  • init_conduct (float) -- initial membrane conductance

  • surrogate_function (surrogate.SurrogateFunctionBase) -- surrogate function used to compute spike gradients during backpropagation

  • step_mode (str) -- step mode, only 'm' (multi-step) is supported

  • backend (str) -- backend of this neuron layer. Supported backends depend on step_mode. Users can print self.supported_backends to check availability. Gated LIF only supports the 'torch' backend

返回:

None

返回类型:

None

neuronal_charge(x: Tensor, alpha: Tensor, beta: Tensor, t)[源代码]#
neuronal_reset(spike, alpha: Tensor, gamma: Tensor)[源代码]#
neuronal_fire()[源代码]#
multi_step_forward(x_seq: Tensor)[源代码]#
class spikingjelly.activation_based.neuron.lif_variants.KLIFNode(scale_reset: bool = False, tau: float = 2.0, decay_input: bool = True, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, step_mode='s', backend='torch', store_v_seq: bool = False)[源代码]#

基类:BaseNode

API Language: 中文 | English


  • 中文

K-based Leaky Integrate-and-Fire(KLIF)神经元的构造函数。

KLIF 神经元模型源自 KLIF: An optimized spiking neuron unit for tuning surrogate gradient slope and membrane potential, 可视为一种带漏电项的积分器,其在阈下阶段与放电 / 重置阶段均具有不同于传统 LIF 的动力学形式。

阈下动力学方程

decay_input == True

\[H[t] = V[t-1] + \frac{1}{\tau}(X[t] - (V[t-1] - V_{reset}))\]

decay_input == False

\[H[t] = V[t-1] - \frac{1}{\tau}(V[t-1] - V_{reset}) + X[t]\]

放电与重置机制

KLIF 神经元的放电与重置形式如下:

\[\begin{split}F[t] &= \mathrm{ReLU}(kH[t]) \\ S[t] &= \Theta(F[t] - V_{th})\end{split}\]

scale_reset == False

\[\begin{split}V[t] = \begin{cases} F[t](1-S[t]) + V_{reset}S[t], & \text{hard reset} \\ F[t] - S[t]V_{th}, & \text{soft reset} \end{cases}\end{split}\]

scale_reset == True

\[\begin{split}V[t] = \begin{cases} \frac{F[t]}{k}(1-S[t]) + V_{reset}S[t], & \text{hard reset} \\ \frac{1}{k}(F[t] - S[t]V_{th}), & \text{soft reset} \end{cases}\end{split}\]
参数:
  • scale_reset (bool) -- 是否在 neuronal_reset 阶段对膜电位 v 进行缩放

  • tau (float) -- 膜电位的时间常数

  • decay_input (bool) -- 输入项是否参与膜电位衰减

  • v_threshold (float) -- 神经元的放电阈值

  • v_reset (Optional[float]) -- 神经元的重置电压。若不为 None,放电后膜电位将被重置为 v_reset; 若为 None,则放电后膜电位减去 v_threshold

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 反向传播中用于近似阶跃函数梯度的替代函数

  • detach_reset (bool) -- 是否在反向传播时将 reset 过程从计算图中分离

  • step_mode (str) -- 步进模式,可选 's' (单步)或 'm' (多步)

  • backend (str) -- 计算后端。不同 step_mode 支持的后端可能不同, 可通过 self.supported_backends 查看当前步进模式支持的后端。 在支持的情况下,'cupy''triton' 后端通常具有最高的执行效率

  • store_v_seq (bool) -- 当 step_mode = 'm' 且输入形状为 [T, N, *] 时, 是否保存所有时间步的膜电位序列 self.v_seq``(形状为 ``[T, N, *])。 若为 False,仅保留最后一个时间步的膜电位 self.v``(形状为 ``[N, *]), 以降低内存开销


  • English

Constructor of the K-based Leaky Integrate-and-Fire (KLIF) neuron.

The KLIF neuron is proposed in KLIF: An optimized spiking neuron unit for tuning surrogate gradient slope and membrane potential. It can be regarded as a leaky integrator with a modified firing and reset mechanism compared to conventional LIF neurons.

Sub-threshold neuronal dynamics

If decay_input == True:

\[H[t] = V[t-1] + \frac{1}{\tau}(X[t] - (V[t-1] - V_{reset}))\]

If decay_input == False:

\[H[t] = V[t-1] - \frac{1}{\tau}(V[t-1] - V_{reset}) + X[t]\]

Firing and reset mechanism

The firing and reset equations of KLIF are as follows:

\[\begin{split}F[t] &= \mathrm{ReLU}(kH[t]) \\ S[t] &= \Theta(F[t] - V_{th})\end{split}\]

If scale_reset == False:

\[\begin{split}V[t] = \begin{cases} F[t](1-S[t]) + V_{reset}S[t], & \text{hard reset} \\ F[t] - S[t]V_{th}, & \text{soft reset} \end{cases}\end{split}\]

If scale_reset == True:

\[\begin{split}V[t] = \begin{cases} \frac{F[t]}{k}(1-S[t]) + V_{reset}S[t], & \text{hard reset} \\ \frac{1}{k}(F[t] - S[t]V_{th}), & \text{soft reset} \end{cases}\end{split}\]
参数:
  • scale_reset (bool) -- whether to scale the membrane potential v during neuronal_reset

  • tau (float) -- membrane time constant

  • decay_input (bool) -- whether the input term participates in decay

  • v_threshold (float) -- firing threshold of the neuron

  • v_reset (Optional[float]) -- reset voltage of the neuron. If not None, the membrane potential will be reset to v_reset after firing; otherwise, v_threshold will be subtracted

  • surrogate_function (surrogate.SurrogateFunctionBase) -- surrogate function used to approximate the gradient of the Heaviside step function during backpropagation

  • detach_reset (bool) -- whether to detach the reset operation from the computation graph

  • step_mode (str) -- step mode, either 's' (single-step) or 'm' (multi-step)

  • backend (str) -- backend for this neuron. Different step_mode may support different backends. Supported backends can be queried via self.supported_backends. If available, 'cupy' or 'triton' usually provides the fastest execution

  • store_v_seq (bool) -- when step_mode = 'm' and input shape is [T, N, *], whether to store the membrane potential at all time steps in self.v_seq. If False, only the final membrane potential self.v is kept to reduce memory usage

返回:

None

返回类型:

None

static neuronal_charge_decay_input(x: Tensor, v: Tensor, v_reset: float, tau: float, k: Tensor)[源代码]#
static neuronal_charge_no_decay_input(x: Tensor, v: Tensor, v_reset: float, tau: float, k: Tensor)[源代码]#
neuronal_charge(x: Tensor)[源代码]#
neuronal_reset(spike)[源代码]#
class spikingjelly.activation_based.neuron.lif_variants.CUBALIFNode(c_decay: float = 0.5, v_decay: float = 0.75, v_threshold: float = 0.5, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:BaseNode

CUrrent-BAsed LIF neuron.

警告

CLIFNode is renamed to CUBALIFNode in version 0.0.0.1.0.

参数:
  • c_decay (float) -- decay factor for input current. Defaults to 0.5

  • v_decay (float) -- decay factor for membrane potential. Defaults to 0.75

  • v_threshold (float) -- firing threshold of the neuron

  • v_reset (Optional[float]) -- reset voltage of the neuron. If not None, the membrane potential will be reset to v_reset after firing; otherwise, v_threshold will be subtracted

  • surrogate_function (surrogate.SurrogateFunctionBase) -- surrogate function used to compute spike gradients during backpropagation

返回:

None

返回类型:

None

neuronal_charge(x: Tensor)[源代码]#
single_step_forward(x: Tensor)[源代码]#
multi_step_forward(x_seq: Tensor)[源代码]#
c_float_to_tensor(c: Tensor)[源代码]#
class spikingjelly.activation_based.neuron.lif_variants.LIAFNode(act: Callable, threshold_related: bool, *args, **kwargs)[源代码]#

基类:LIFNode

API Language: 中文 | English


  • 中文

LIAF(Leaky Integrate and Analog Fire)神经元的构造函数。

LIAF 神经元由 LIAF-Net: Leaky Integrate and Analog Fire Network for Lightweight and Efficient Spatiotemporal Information Processing 提出,其行为与 LIF 神经元相同,但输出经过连续激活函数而非二值脉冲。

警告

该神经元层的输出不是二值脉冲,而是连续值。

参数:
  • act (Callable) -- 激活函数

  • threshold_related (bool) -- 是否使用阈值依赖模式(TR mode)。若为 True,输出为 y = act(h - v_th), 否则为 y = act(h)

其他参数请参考 LIFNode


  • English

Constructor of the LIAF (Leaky Integrate and Analog Fire) neuron.

The LIAF neuron is proposed in LIAF-Net: Leaky Integrate and Analog Fire Network for Lightweight and Efficient Spatiotemporal Information Processing. It behaves like a LIF neuron, but the output passes through a continuous activation function instead of generating binary spikes.

Warning

The outputs of this neuron layer are not binary spikes.

参数:
  • act (Callable) -- the activation function

  • threshold_related (bool) -- whether the neuron uses threshold-related (TR) mode. If True, the output is y = act(h - v_th), otherwise y = act(h)

Other parameters in *args, **kwargs are the same as LIFNode.

返回:

None

返回类型:

None

single_step_forward(x: Tensor)[源代码]#

Neurons with Membrane Potential Batch Normalization#

class spikingjelly.activation_based.neuron.mpbn.MPBNBaseNode(v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, step_mode='s', backend='torch', store_v_seq: bool = False, mpbn: bool = True, out_features=None, out_channels=None, learnable_vth: bool = False, bn_momentum: float = 0.1, bn_decay_momentum: float = 0.94, bn_min_momentum: float = 0.005)[源代码]#

基类:BaseNode

API Language: 中文 | English


  • 中文

该基类神经元实现了 Membrane Potential Batch Normalization for Spiking Neural Networks 中提出的膜电压批量归一化方法,并在 Threshold Modulation for Online Test-Time Adaptation of Spiking Neural Networks 的基础上引入阈值调制模块,用于测试时适应任务并降低能耗。

神经动力学方程如下:

\[\begin{split}H'[t] &= \mathbf{BN}(H[t]), & \text{(训练时)} \\ (\tilde{V}_{th})_{i} &= \frac{(V_{th}-\beta_{i})\sqrt{\sigma_{i}^{2}}}{\gamma_{i}}+\mu_{i}, & \text{(测试时适应)}\end{split}\]
参数:
  • mpbn (bool) -- 是否启用 MPBN

  • out_features (int) -- 特征维度,用于线性层后

  • out_channels (int) -- 特征通道数,用于 2D 卷积层后

  • learnable_vth (bool) -- 阈值是否可训练

  • bn_momentum (float) -- 阈值重参数化后,更新统计量时使用的动量

  • bn_decay_momentum (float) -- 阈值重参数化后,更新统计量时使用的动量衰减

  • bn_min_momentum (float) -- 阈值重参数化后,更新统计量时使用的最小动量

其余参数与 BaseNode 相同。


  • English

Base class of neuron with membrane potential batch normalization proposed in Membrane Potential Batch Normalization for Spiking Neural Networks. Threshold Modulation for Online Test-Time Adaptation of Spiking Neural Networks further introduces a Threshold Modulation module after threshold re-parameterization to enable test-time adaptation and reduce energy consumption.

The neuronal dynamics are described as:

\[\begin{split}H'[t] &= \mathbf{BN}(H[t]), & \text{(training)} \\ (\tilde{V}_{th})_{i} &= \frac{(V_{th}-\beta_{i})\sqrt{\sigma_{i}^{2}}}{\gamma_{i}}+\mu_{i}, & \text{(test-time adaptation)}\end{split}\]
参数:
  • mpbn (bool) -- whether to enable MPBN

  • out_features (int) -- feature dimension, when used after Linear

  • out_channels (int) -- number of channels, when used after Conv2d

  • learnable_vth (bool) -- whether to train a (positive) threshold

  • bn_momentum (float) -- the momentum used in statistics update after threshold re-parameterization

  • bn_decay_momentum (float) -- the momentum decay used in statistics update after threshold re-parameterization

  • bn_min_momentum (float) -- the minimum momentum used in statistics update after threshold re-parameterization

Other parameters are the same as BaseNode. :return: None :rtype: None

init_vth(x: Tensor)[源代码]#
compute_running_stats(v: Tensor)[源代码]#
pre_charge(x: Tensor)[源代码]#
neuronal_charge(x: Tensor)[源代码]#
neuronal_fire()[源代码]#
single_step_forward(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

  • 中文

参数:

x (torch.Tensor) -- 当前时间步输入张量(2D 或 4D)

返回:

当前时间步输出脉冲

返回类型:

torch.Tensor

抛出:

NotImplementedError -- 当输入维度不是 2D 或 4D 时,内部放电逻辑会抛出异常


  • English

  • English

参数:

x (torch.Tensor) -- Input tensor at current time step (2D or 4D)

返回:

Output spike at current time step

返回类型:

torch.Tensor

抛出:

NotImplementedError -- Raised by internal firing logic when input rank is neither 2D nor 4D

re_parameterize_v_threshold(normalize_residual: bool = False, running_stats: bool = False)[源代码]#
class spikingjelly.activation_based.neuron.mpbn.MPBNLIFNode(tau: float = 2.0, decay_input: bool = False, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, step_mode='s', backend='torch', store_v_seq: bool = False, mpbn: bool = True, out_features=None, out_channels=None, learnable_vth: bool = False, bn_momentum: float = 0.1, bn_decay_momentum: float = 0.94, bn_min_momentum: float = 0.005)[源代码]#

基类:MPBNBaseNode

API Language: 中文 | English


  • 中文

该神经元模型在 Membrane Potential Batch Normalization for Spiking Neural Networks 中对膜电压进行了批量归一化,并在 Threshold Modulation for Online Test-Time Adaptation of Spiking Neural Networks 的基础上引入阈值调制模块,用于测试时适应任务并降低能耗。

神经动力学方程如下:

\[\begin{split}H'[t] &= \mathbf{BN}(H[t]), & \text{(训练时)} \\ (\tilde{V}_{th})_{i} &= \frac{(V_{th}-\beta_{i})\sqrt{\sigma_{i}^{2}}}{\gamma_{i}}+\mu_{i}, & \text{(测试时适应)}\end{split}\]
参数:
  • tau (float) -- LIF中的时间常数

  • decay_input (bool) -- 输入是否参与衰减

其余参数与 MPBNBaseNode 相同。


  • English

This neuron model applies membrane potential batch normalization as in Membrane Potential Batch Normalization for Spiking Neural Networks. Threshold Modulation for Online Test-Time Adaptation of Spiking Neural Networks further introduces a Threshold Modulation module for test-time adaptation and energy efficiency.

The neuronal dynamics are described as:

\[\begin{split}H'[t] &= \mathbf{BN}(H[t]), & \text{(training)} \\ (\tilde{V}_{th})_{i} &= \frac{(V_{th}-\beta_{i})\sqrt{\sigma_{i}^{2}}}{\gamma_{i}}+\mu_{i}, & \text{(test-time adaptation)}\end{split}\]
参数:
  • tau (float) -- time constant in LIF

  • decay_input (bool) -- whether the input current is decayed

Other parameters are the same as MPBNBaseNode. :return: None :rtype: None

pre_charge(x: Tensor)[源代码]#
static neuronal_charge_decay_input_reset0(x: Tensor, v: Tensor, tau: float)[源代码]#
static neuronal_charge_decay_input(x: Tensor, v: Tensor, v_reset: float, tau: float)[源代码]#
static neuronal_charge_no_decay_input_reset0(x: Tensor, v: Tensor, tau: float)[源代码]#
static neuronal_charge_no_decay_input(x: Tensor, v: Tensor, v_reset: float, tau: float)[源代码]#

Differentiation on Spike Representation (DSR)#

class spikingjelly.activation_based.neuron.dsr.DSRIFNode(T: int = 20, v_threshold: float = 6.0, alpha: float = 0.5, v_threshold_training: bool = True, v_threshold_grad_scaling: float = 1.0, v_threshold_lower_bound: float = 0.01, step_mode='m', backend='torch', **kwargs)[源代码]#

基类:MemoryModule

API Language: 中文 | English


  • 中文

DSR IF 神经元,由 Training High-Performance Low-Latency Spiking Neural Networks by Differentiation on Spike Representation 提出。 该模型基于对脉冲表示的可微建模,用于低时延、高性能脉冲神经网络训练。

参数:
  • T (int) -- 时间步数

  • v_threshold (float) -- 神经元阈值电压的初始值

  • alpha (float) -- 阈值电压的缩放因子

  • v_threshold_training (bool) -- 是否将阈值电压设为可学习参数,默认为 True

  • v_threshold_grad_scaling (float) -- 对阈值电压梯度进行缩放的系数

  • v_threshold_lower_bound (float) -- 训练过程中阈值电压允许的最小值

  • step_mode (str) -- 步进模式,仅支持 'm' (多步)

  • backend (str) -- 使用的后端。不同 step_mode 支持的后端可能不同。 可通过 self.supported_backends 查看当前步进模式支持的后端。 DSR-IF 仅支持 'torch' 后端


  • English

DSR IF neuron, proposed in Training High-Performance Low-Latency Spiking Neural Networks by Differentiation on Spike Representation. This model enables low-latency and high-performance SNN training via differentiable spike representations.

参数:
  • T (int) -- number of time-steps

  • v_threshold (float) -- initial membrane potential threshold

  • alpha (float) -- scaling factor of the membrane potential threshold

  • v_threshold_training (bool) -- whether the membrane potential threshold is learnable, default: True

  • v_threshold_grad_scaling (float) -- scaling factor applied to the gradient of the membrane potential threshold

  • v_threshold_lower_bound (float) -- minimum allowable membrane potential threshold during training

  • step_mode (str) -- step mode, only 'm' (multi-step) is supported

  • backend (str) -- backend of this neuron layer. Supported backends depend on step_mode. Users can print self.supported_backends to check availability. DSR-IF only supports the 'torch' backend

返回:

None

返回类型:

None

multi_step_forward(x_seq: Tensor)[源代码]#
class DSRIFFunction(*args, **kwargs)[源代码]#

基类:Function

static forward(ctx, inp, T=10, v_threshold=1.0, alpha=0.5, v_threshold_grad_scaling=1.0)[源代码]#
static backward(ctx, grad_output)[源代码]#
class spikingjelly.activation_based.neuron.dsr.DSRLIFNode(T: int = 20, v_threshold: float = 1.0, tau: float = 2.0, delta_t: float = 0.05, alpha: float = 0.3, v_threshold_training: bool = True, v_threshold_grad_scaling: float = 1.0, v_threshold_lower_bound: float = 0.1, step_mode='m', backend='torch', **kwargs)[源代码]#

基类:MemoryModule

API Language: 中文 | English


  • 中文

DSR LIF 神经元,由 Training High-Performance Low-Latency Spiking Neural Networks by Differentiation on Spike Representation 提出。该模型通过对脉冲表示进行可微建模,实现低时延、高性能的脉冲神经网络训练。

参数:
  • T (int) -- 时间步数

  • v_threshold (float) -- 神经元阈值电压的初始值

  • tau (float) -- 膜电位时间常数

  • delta_t (float) -- 对连续时间 LIF 微分方程进行离散化的时间步长

  • alpha (float) -- 阈值电压的缩放因子

  • v_threshold_training (bool) -- 是否将阈值电压设为可学习参数,默认为 True

  • v_threshold_grad_scaling (float) -- 对阈值电压梯度进行缩放的系数

  • v_threshold_lower_bound (float) -- 训练过程中阈值电压允许的最小值

  • step_mode (str) -- 步进模式,仅支持 'm' (多步)

  • backend (str) -- 使用的后端。不同 step_mode 支持的后端可能不同。 可通过 self.supported_backends 查看当前步进模式支持的后端。 DSR-LIF 仅支持 'torch' 后端


  • English

DSR LIF neuron, proposed in Training High-Performance Low-Latency Spiking Neural Networks by Differentiation on Spike Representation. This model enables low-latency and high-performance SNN training by differentiating spike representations.

参数:
  • T (int) -- number of time-steps

  • v_threshold (float) -- initial membrane potential threshold

  • tau (float) -- membrane time constant

  • delta_t (float) -- discretization step for the continuous-time LIF differential equation

  • alpha (float) -- scaling factor of the membrane potential threshold

  • v_threshold_training (bool) -- whether the membrane potential threshold is learnable, default: True

  • v_threshold_grad_scaling (float) -- scaling factor applied to the gradient of the membrane potential threshold

  • v_threshold_lower_bound (float) -- minimum allowable membrane potential threshold during training

  • step_mode (str) -- step mode, only 'm' (multi-step) is supported

  • backend (str) -- backend of this neuron layer. Supported backends depend on step_mode. Users can print self.supported_backends to check availability. DSR-LIF only supports the 'torch' backend

返回:

None

返回类型:

None

multi_step_forward(x_seq: Tensor)[源代码]#
classmethod weight_rate_spikes(data, tau, delta_t)[源代码]#
class DSRLIFFunction(*args, **kwargs)[源代码]#

基类:Function

static forward(ctx, inp, T, v_threshold, tau, delta_t=0.05, alpha=0.3, v_threshold_grad_scaling=1.0)[源代码]#
static backward(ctx, grad_output)[源代码]#

Neurons for Online Learning#

class spikingjelly.activation_based.neuron.online_learning.OTTTLIFNode(tau: float = 2.0, decay_input: bool = False, v_threshold: float = 1.0, v_reset: float | None = None, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = True, step_mode='s', backend='torch', store_v_seq: bool = False)[源代码]#

基类:LIFNode

API Language: 中文 | English


  • 中文

用于 OTTT 训练的单步 LIF 神经元。该类继承 LIFNode 的放电行为,但仅支持 step_mode='s'backend='torch',并在训练时额外维护迹以供后续模块使用。


  • English

Single-step LIF neuron for OTTT training. This class inherits the firing behavior of LIFNode, but only supports step_mode='s' and backend='torch'. During training it also maintains a trace for downstream modules.

API Language: 中文 | English


  • 中文

OTTT LIF 神经元模型,来源于 Online Training Through Time for Spiking Neural Networks。 其正向传播过程与 Leaky Integrate-and-Fire(LIF)神经元相同。

参数:
  • tau (float) -- 膜电位时间常数

  • decay_input (bool) -- 输入是否也会参与衰减

  • v_threshold (float) -- 神经元的阈值电压

  • v_reset (Optional[float]) -- 神经元的重置电压。如果不为 None ,当神经元释放脉冲后, 电压会被重置为 v_reset ;如果设置为 None ,当神经元释放脉冲后, 电压会被减去 v_threshold

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 反向传播时用来计算脉冲函数梯度的替代函数

  • detach_reset (bool) -- 是否将 reset 过程的计算图分离。 该参数在本模块中不起作用,仅为保持代码接口统一而保留

  • step_mode (str) -- 步进模式。为了保证神经元的显存占用较小,仅支持 's' (单步)

  • backend (str) -- 使用的后端。当前实现仅支持 'torch',其他取值会在前向传播时触发 ValueError

  • store_v_seq (bool) -- 为保持与 LIFNode 接口一致而保留的参数。本类仅支持 单步模式,不会使用 self.v_seq


  • English

OTTT LIF neuron, proposed in Online Training Through Time for Spiking Neural Networks. This neuron is designed for OTTT. Its forward propagation is identical to that of the Leaky Integrate-and-Fire (LIF) neuron.

参数:
  • tau (float) -- membrane time constant

  • decay_input (bool) -- whether the input will decay

  • v_threshold (float) -- threshold voltage of the neuron

  • v_reset (Optional[float]) -- reset voltage of the neuron. If not None, the membrane potential will be reset to v_reset after firing a spike. If None, the membrane potential will subtract v_threshold after firing a spike

  • surrogate_function (surrogate.SurrogateFunctionBase) -- the function used to compute surrogate gradients of the Heaviside step function in backward propagation

  • detach_reset (bool) -- whether to detach the computation graph of the reset operation in backward propagation. This parameter has no effect in this module and is retained solely for interface consistency

  • step_mode (str) -- step mode. To guarantee memory-efficient computation, only 's' (single-step) mode is supported

  • backend (str) -- backend for this neuron layer. The current implementation only supports 'torch'; other values raise ValueError during forward

  • store_v_seq (bool) -- retained for interface consistency with LIFNode. This class only supports single-step mode and does not use self.v_seq

返回:

None

返回类型:

None

reset()[源代码]#
neuronal_charge(x: Tensor)[源代码]#
static track_trace(spike: Tensor, trace: Tensor, tau: float)[源代码]#
single_step_forward(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

训练时,输出脉冲和迹;推理时,输出脉冲。

训练时需要将后续参数模块用layer.py中定义的GradwithTrace进行包装,根据迹计算梯度。

参数:

x (torch.Tensor) -- 当前时间步的输入张量

返回:

训练模式下返回 [spike, trace],推理模式下仅返回 spike

返回类型:

Union[list[torch.Tensor], torch.Tensor]


  • English

Output spike and trace during training; output spike during inference.

During training, successive parametric modules shoule be wrapped by GradwithTrace defined in layer.py, to calculate gradients with traces.

参数:

x (torch.Tensor) -- input tensor at the current time step

返回:

[spike, trace] in training mode, and spike in eval mode

返回类型:

Union[list[torch.Tensor], torch.Tensor]

class spikingjelly.activation_based.neuron.online_learning.SLTTLIFNode(tau: float = 2.0, decay_input: bool = True, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = True, step_mode='s', backend='torch', store_v_seq: bool = False)[源代码]#

基类:LIFNode

API Language: 中文 | English


  • 中文

用于 SLTT 训练的单步 LIF 神经元。该类继承 LIFNode 的放电行为,但仅支持 step_mode='s'backend='torch',并通过截断时间梯度来降低训练的时间与显存开销。


  • English

Single-step LIF neuron for SLTT training. This class inherits the firing behavior of LIFNode, but only supports step_mode='s' and backend='torch'. It reduces training time and memory cost by truncating temporal gradients.

API Language: 中文 | English


  • 中文

SLTT LIF 神经元模型,来源于 Towards Memory- and Time-Efficient Backpropagation for Training Spiking Neural Networks。 该模型在正向传播过程中与 Leaky Integrate-and-Fire(LIF)神经元相同, 通过截断时间梯度实现更高的时间与显存效率。

参数:
  • tau (float) -- 膜电位时间常数

  • decay_input (bool) -- 输入是否也会参与衰减

  • v_threshold (float) -- 神经元的阈值电压

  • v_reset (Optional[float]) -- 神经元的重置电压。如果不为 None ,当神经元释放脉冲后, 电压会被重置为 v_reset ;如果设置为 None ,当神经元释放脉冲后, 电压会被减去 v_threshold

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 反向传播时用来计算脉冲函数梯度的替代函数

  • detach_reset (bool) -- 是否将 reset 过程的计算图分离。 该参数在本模块中不起作用,仅为保持代码接口统一而保留

  • step_mode (str) -- 步进模式。为了保证神经元的显存占用较小,仅支持 's' (单步)

  • backend (str) -- 使用的后端。当前实现仅支持 'torch',其他取值会在前向传播时触发 ValueError

  • store_v_seq (bool) -- 为保持与 LIFNode 接口一致而保留的参数。本类仅支持 单步模式,不会使用 self.v_seq


  • English

SLTT LIF neuron, proposed in Towards Memory- and Time-Efficient Backpropagation for Training Spiking Neural Networks. The forward propagation of this neuron is identical to that of the Leaky Integrate-and-Fire (LIF) neuron, while it truncates temporal gradients to enable more memory- and time-efficient training.

参数:
  • tau (float) -- membrane time constant

  • decay_input (bool) -- whether the input will decay

  • v_threshold (float) -- threshold voltage of the neuron

  • v_reset (Optional[float]) -- reset voltage of the neuron. If not None, the membrane potential will be reset to v_reset after firing a spike. If None, the membrane potential will subtract v_threshold after firing a spike

  • surrogate_function (surrogate.SurrogateFunctionBase) -- the function used to compute surrogate gradients of the Heaviside step function in backward propagation

  • detach_reset (bool) -- whether to detach the computation graph of the reset operation in backward propagation. This parameter has no effect in this module and is retained solely for interface consistency

  • step_mode (str) -- step mode. To guarantee memory-efficient computation, only 's' (single-step) mode is supported

  • backend (str) -- backend for this neuron layer. The current implementation only supports 'torch'; other values raise ValueError during forward

  • store_v_seq (bool) -- retained for interface consistency with LIFNode. This class only supports single-step mode and does not use self.v_seq

返回:

None

返回类型:

None

reset()[源代码]#
neuronal_charge(x: Tensor)[源代码]#
single_step_forward(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

执行单步前向传播并返回当前时间步的输出脉冲。

参数:

x (torch.Tensor) -- 当前时间步的输入张量

返回:

当前时间步的输出脉冲

返回类型:

torch.Tensor


  • English

Run single-step forward propagation and return the output spike at the current time step.

参数:

x (torch.Tensor) -- input tensor at the current time step

返回:

output spike at the current time step

返回类型:

torch.Tensor

Neurons with Inter-layer Connection#

class spikingjelly.activation_based.neuron.inter_layer_connection.ILCBaseNode(act_dim, dec_pop_dim, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:Module, MultiStepModule

API Language: 中文 | English


  • 中文

层间连接(Inter-Layer Connection,ILC)神经元基类,是构建跨层脉冲传播连接的抽象基类。

ILC 神经元与普通神经元类似,在每个时间步按顺序执行充电、放电、重置三个步骤。 与普通神经元的区别在于,它将输出脉冲通过一个可学习的一维卷积连接 (torch.nn.Conv1d)传递给下一层的输入,从而实现层间的结构化连接。

各子类通过重写 neuronal_charge() 实现不同的充电动力学:

  • ILCIFNode — 积分发放(IF)动力学

  • ILCLIFNode — 漏电积分发放(LIF)动力学,增加膜电位衰减

  • ILCCUBALIFNode — 基于电流的 LIF 动力学,增加电流衰减

参数:
  • act_dim (int) -- 输入激活的特征维度

  • dec_pop_dim (int) -- 解码种群维度,每个特征对应的神经元数量

  • v_threshold (float) -- 神经元的阈值电压,膜电位超过该值时发放脉冲

  • v_reset (Optional[float]) -- 重置电压。若为 None,采用软重置(减去阈值);否则硬重置到此值

  • surrogate_function (surrogate.SurrogateFunctionBase) -- 替代梯度函数,用于在反向传播中计算脉冲函数的近似梯度

返回:

None

返回类型:

None


  • English

Inter-Layer Connection (ILC) neuron base class. An abstract base class for building cross-layer spike-propagation connections.

At each time step, the ILC neuron performs charge-fire-reset dynamics. Unlike standard neurons, it passes the output spike through a learnable 1D convolution (torch.nn.Conv1d) to the next layer's input, enabling structured inter-layer connections.

Subclasses override neuronal_charge() to implement different charging dynamics:

  • ILCIFNode — Integrate-and-Fire dynamics

  • ILCLIFNode — Leaky Integrate-and-Fire dynamics with membrane decay

  • ILCCUBALIFNode — Current-Based LIF dynamics with current decay

参数:
  • act_dim (int) -- Feature dimension of the input activation

  • dec_pop_dim (int) -- Decoding population dimension, number of neurons per feature

  • v_threshold (float) -- Threshold voltage. A spike is emitted when membrane potential exceeds this

  • v_reset (Optional[float]) -- Reset voltage. If None, soft reset (subtract threshold); otherwise hard reset

  • surrogate_function (surrogate.SurrogateFunctionBase) -- Surrogate gradient function for approximating the spike function gradient

返回:

None

返回类型:

None

abstractmethod neuronal_charge(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

神经元充电动力学方程(抽象方法)。根据输入 x 更新膜电位 self.v

充电是神经元动力学的第一步。对于 IF 和 LIF 神经元,这一步将输入电流 累积到膜电位上;对于 CUBALIF 神经元,这一步会同时更新突触电流和膜电位。 具体的充电方式由子类实现。

参数:

x (torch.Tensor) -- 当前时间步的输入张量

返回:

None

返回类型:

None


  • English

Neuronal charging dynamics (abstract method). Updates membrane potential self.v based on the input x.

This is the first step of the charge-fire-reset cycle. IF and LIF neurons accumulate the input current into the membrane potential, while CUBALIF updates both synaptic current and membrane potential. The specific charging behavior is defined by the subclass implementation.

参数:

x (torch.Tensor) -- Input tensor for the current time step

返回:

None

返回类型:

None

neuronal_fire()[源代码]#

API Language: 中文 | English


  • 中文

神经元放电函数。根据当前膜电位与阈值的差值生成脉冲。

通过替代梯度函数 self.surrogate_function 计算脉冲: 当膜电位 self.v 超过阈值 self.v_threshold 时输出 1, 否则输出 0。在反向传播时,替代梯度函数会用一个平滑的近似梯度 替代脉冲函数的不可导部分。

这是充电-放电-重置循环的第二步。

返回:

脉冲张量,元素为 0 或 1

返回类型:

torch.Tensor


  • English

Neuronal fire function. Generates a spike based on the difference between the membrane potential and the threshold.

Uses the surrogate function self.surrogate_function to compute the spike: outputs 1 when the membrane potential self.v exceeds the threshold self.v_threshold, and 0 otherwise. During backpropagation, the surrogate function provides a smooth approximation of the spike function's gradient.

This is the second step of the charge-fire-reset cycle.

返回:

Spike tensor with elements 0 or 1

返回类型:

torch.Tensor

neuronal_reset(spike)[源代码]#

API Language: 中文 | English


  • 中文

神经元重置函数。在脉冲发放后重置膜电位。

支持两种重置模式:

  • **软重置**(当 v_resetNone 时):膜电位减去阈值,即 \(V = V - S \\cdot V_{th}\)

  • **硬重置**(当 v_reset 为数值时):膜电位重置为固定值,即 \(V = V_{reset}\)\(V = (1 - S) \\cdot V + S \\cdot V_{reset}\)

这是充电-放电-重置循环的第三步。

参数:

spike (torch.Tensor) -- 由 neuronal_fire() 生成的脉冲张量

返回:

None

返回类型:

None


  • English

Neuronal reset function. Resets the membrane potential after spike emission.

Supports two reset modes:

  • Soft reset (when v_reset is None): subtracts the threshold, i.e., \(V = V - S \\cdot V_{th}\)

  • Hard reset (when v_reset is a float): resets the membrane potential to a fixed value, i.e., \(V = V_{reset}\) or \(V = (1 - S) \\cdot V + S \\cdot V_{reset}\)

This is the third step of the charge-fire-reset cycle.

参数:

spike (torch.Tensor) -- Spike tensor generated by neuronal_fire()

返回:

None

返回类型:

None

init_tensor(data: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

初始化膜电位张量。根据输入数据 data 的形状创建初始膜电位。

将膜电位 self.v 初始化为形状与 data 相同、所有元素为 self.v_reset 的张量。在 forward() 开始时调用。

参数:

data (torch.Tensor) -- 用于确定形状的参考张量

返回:

None

返回类型:

None


  • English

Initialize the membrane potential tensor. Creates the initial membrane potential based on the shape of the input data.

Initializes self.v to a tensor with the same shape as data, filled with self.v_reset. Called at the beginning of forward().

参数:

data (torch.Tensor) -- Reference tensor used to determine shape

返回:

None

返回类型:

None

forward(x_seq: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

多步前向传播函数。对输入的时间序列逐时间步执行充电-放电-重置循环。

在每个时间步 \(t\)

  1. 调用 neuronal_charge() 更新膜电位

  2. 调用 neuronal_fire() 生成脉冲(判断是否放电)

  3. 调用 neuronal_reset() 重置膜电位

  4. 将当前步输出的脉冲通过可学习卷积连接 self.conn 传递到下一时间步的输入

参数:

x_seq (torch.Tensor) -- 输入序列,形状 [T, N, *],其中 T 为时间步数,N 为 batch 大小

返回:

脉冲序列,形状与 x_seq 相同

返回类型:

torch.Tensor


  • English

Multi-step forward function. Performs the charge-fire-reset cycle at each time step on the input sequence.

At each time step \(t\):

  1. Call neuronal_charge() to update the membrane potential

  2. Call neuronal_fire() to generate a spike

  3. Call neuronal_reset() to reset the membrane potential

  4. Pass the current output spike through the learnable convolution connection self.conn to the next time step's input

参数:

x_seq (torch.Tensor) -- Input sequence, shape [T, N, *], where T is the number of time steps and N is the batch size

返回:

Spike sequence with the same shape as x_seq

返回类型:

torch.Tensor

class spikingjelly.activation_based.neuron.inter_layer_connection.ILCIFNode(act_dim, dec_pop_dim, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:ILCBaseNode

API Language: 中文 | English


  • 中文

ILC-IF 神经元。使用积分发放(Integrate-and-Fire)充电动力学的 层间连接神经元子类。

充电公式为 \(V[t] = V[t-1] + X[t]\),即直接将输入累加到膜电位上, 不引入漏电衰减。适合对输入信号进行简单累加的场景。

返回:

None

返回类型:

None


  • English

ILC Integrate-and-Fire neuron. An ILC neuron subclass that uses Integrate-and-Fire charging dynamics.

The charging equation is \(V[t] = V[t-1] + X[t]\), where the input is directly accumulated into the membrane potential without leakage. Suitable for simple accumulation of input signals.

返回:

None

返回类型:

None

neuronal_charge(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

IF 充电动力学。直接将输入 x 累加到膜电位上。

实现公式 \(V = V + x\)。无漏电项,输入完全累积到膜电位中。

参数:

x (torch.Tensor) -- 当前时间步的输入

返回:

None

返回类型:

None


  • English

IF charging dynamics. Directly accumulates the input x into the membrane potential.

Implements \(V = V + x\). No leakage — the input is fully accumulated into the membrane potential.

参数:

x (torch.Tensor) -- Input at the current time step

返回:

None

返回类型:

None

class spikingjelly.activation_based.neuron.inter_layer_connection.ILCLIFNode(act_dim, dec_pop_dim, v_decay: float = 0.75, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:ILCBaseNode

API Language: 中文 | English


  • 中文

ILC-LIF 神经元。使用漏电积分发放(Leaky Integrate-and-Fire)充电动力学的 层间连接神经元子类。

充电公式为 \(V[t] = V[t-1] \\cdot v_{decay} + X[t]\),其中 \(v_{decay}\) 是膜电位衰减系数(默认 0.75)。每一步膜电位会先按比例衰减,再累加输入。 适合需要短期记忆的场景。

返回:

None

返回类型:

None


  • English

ILC Leaky Integrate-and-Fire neuron. An ILC neuron subclass that uses Leaky Integrate-and-Fire charging dynamics.

The charging equation is \(V[t] = V[t-1] \\cdot v_{decay} + X[t]\), where \(v_{decay}\) is the membrane decay factor (default 0.75). The membrane potential decays proportionally at each step before accumulating the input. Suitable for tasks requiring short-term memory.

返回:

None

返回类型:

None

neuronal_charge(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

LIF 充电动力学。膜电位先按因子衰减,再累加输入。

实现公式 \(V = V \\cdot v_{decay} + x\)。其中 v_decay 控制 膜电位在每一步的保留比例,值越接近 1 衰减越慢,记忆越长。

参数:

x (torch.Tensor) -- 当前时间步的输入

返回:

None

返回类型:

None


  • English

LIF charging dynamics. The membrane potential decays by a factor before accumulating the input.

Implements \(V = V \\cdot v_{decay} + x\). The v_decay parameter controls how much of the membrane potential is retained at each step — values closer to 1 mean slower decay and longer memory.

参数:

x (torch.Tensor) -- Input at the current time step

返回:

None

返回类型:

None

class spikingjelly.activation_based.neuron.inter_layer_connection.ILCCUBALIFNode(act_dim, dec_pop_dim, c_decay: float = 0.5, v_decay: float = 0.75, v_threshold: float = 0.5, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:ILCBaseNode

API Language: 中文 | English


  • 中文

ILC-CUBALIF 神经元。使用基于电流的 CUBALIF(Current-Based LIF)充电动力学的 层间连接神经元子类。

充电过程分为两步:

  1. 突触电流衰减:\(C[t] = C[t-1] \\cdot c_{decay} + X[t]\)

  2. 膜电位衰减并累加电流:\(V[t] = V[t-1] \\cdot v_{decay} + C[t]\)

与 ILCLIFNode 相比,此处多了一层电流衰减,使神经元能对输入的时间模式 进行更丰富的建模。c_decay 控制电流衰减速度,v_decay 控制膜电位衰减速度。

返回:

None

返回类型:

None


  • English

ILC Current-Based LIF neuron. An ILC neuron subclass that uses Current-Based LIF (CUBALIF) charging dynamics.

The charging process has two steps:

  1. Synaptic current decay: \(C[t] = C[t-1] \\cdot c_{decay} + X[t]\)

  2. Membrane potential decay with current accumulation: \(V[t] = V[t-1] \\cdot v_{decay} + C[t]\)

Compared to ILCLIFNode, the additional current decay layer enables richer temporal modeling. c_decay controls the current decay rate, while v_decay controls the membrane potential decay rate.

返回:

None

返回类型:

None

neuronal_charge(x: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

CUBALIF 充电动力学。先更新突触电流,再更新膜电位。

实现两步更新:

  • 电流衰减:\(C = C \\cdot c_{decay} + x\)

  • 膜电位更新:\(V = V \\cdot v_{decay} + C\)

参数:

x (torch.Tensor) -- 当前时间步的输入

返回:

None

返回类型:

None


  • English

CUBALIF charging dynamics. First updates the synaptic current, then updates the membrane potential.

Two-step update:

  • Current decay: \(C = C \\cdot c_{decay} + x\)

  • Membrane update: \(V = V \\cdot v_{decay} + C\)

参数:

x (torch.Tensor) -- Input at the current time step

返回:

None

返回类型:

None

init_tensor(data: Tensor)[源代码]#

API Language: 中文 | English


  • 中文

初始化膜电位和突触电流张量。

与基类的 ILCBaseNode.init_tensor() 不同,此处还需要额外初始化 突触电流 self.c 为全零张量。这是因为 CUBALIF 维护了独立的 电流状态,而不仅仅是膜电位。

参数:

data (torch.Tensor) -- 用于确定形状的参考张量

返回:

None

返回类型:

None


  • English

Initialize the membrane potential and synaptic current tensors.

Unlike the base class ILCBaseNode.init_tensor(), this also initializes the synaptic current self.c to zero, because CUBALIF maintains an independent current state in addition to the membrane potential.

参数:

data (torch.Tensor) -- Reference tensor used to determine shape

返回:

None

返回类型:

None

Neurons with Input or Output Noise#

spikingjelly.activation_based.neuron.noisy.powerlaw_psd_gaussian(exponent: float, size: int | Iterable[int], fmin: float = 0.0, random_state: int | Generator | RandomState | None = None)[源代码]#

API Language: 中文 | English


  • 中文

生成具有 \((1/f)^\beta\) 功率谱的高斯噪声。生成的噪声满足

\[S(f) = (1 / f)^\beta\]

Flicker / pink noise:

\[\beta = 1\]

Brown noise:

\[\beta = 2\]

自相关衰减比例为 \(\text{lag}^{-\gamma}\),其中 \(\gamma = 1 - \beta (0 < \beta < 1)\)。 对于接近 1 的 \(\beta\) 值可能存在有限大小效应。该算法基于文章 Timmer, J. and Koenig, M.: On generating power law noise. Astron. Astrophys. 300, 707-710 (1995).

参数:
  • exponent (float) -- 噪声的功率谱指数 \(\beta\)

  • size (Union[int, Iterable[int]]) -- 输出样本的形状,最后一个维度作为时间轴,其余维度独立。

  • fmin (float, optional) -- 低频截止,默认为 0,对应原始论文。低于 fmin 的频率功率谱平坦。fmin 定义为 相对于单位采样率。内部会映射为 max(fmin, 1/samples)。最大值为 fmin = 0.5, 即 Nyquist 频率,此时输出为白噪声。

  • random_state (int, numpy.integer, numpy.random.Generator, numpy.random.RandomState, optional) -- 可选,设置 NumPy 随机数生成器状态。支持整数、None、 np.random.Generator 或 np.random.RandomState。

返回:

生成的噪声样本

返回类型:

array


  • English

Generate Gaussian noise with a power spectrum proportional to \((1/f)^\beta\). The generated noise satisfies

\[S(f) = (1 / f)^\beta\]

Flicker / pink noise:

\[\beta = 1\]

Brown noise:

\[\beta = 2\]

The autocorrelation decays proportional to \(\text{lag}^{-\gamma}\), where \(\gamma = 1 - \beta\) for \(0 < \beta < 1\). Finite-size effects may occur when \(\beta\) is close to 1. The algorithm is based on: Timmer, J. and Koenig, M.: On generating power law noise. Astron. Astrophys. 300, 707-710 (1995).

参数:
  • exponent (float) -- the power spectrum exponent $beta$.

  • size (Union[int, Iterable[int]]) -- shape of the output samples. The last axis is taken as time, and all other axes are independent.

  • fmin (float, optional) -- low-frequency cutoff. Default 0 corresponds to the original paper. Frequencies below fmin are flat. fmin is defined relative to unit sampling rate. Internally mapped to max(fmin, 1/samples). The maximum allowed value is 0.5 (Nyquist frequency), producing white noise.

  • random_state (int, numpy.integer, numpy.random.Generator, numpy.random.RandomState, optional) -- optional, sets the state of NumPy's underlying random number generator. Supports int, None, np.random.Generator, or np.random.RandomState.

返回:

generated Gaussian noise samples

返回类型:

array


Examples:

# generate 1/f noise == pink noise == flicker noise
>>> import colorednoise as cn
>>> y = cn.powerlaw_psd_gaussian(1, 5)
class spikingjelly.activation_based.neuron.noisy.NoisyBaseNode(num_node, is_training: bool = True, T: int = 5, sigma_init: float = 0.5, beta: float = 0.0, v_threshold: float = 0.5, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:Module, MultiStepModule

abstractmethod neuronal_charge(x: Tensor)[源代码]#
neuronal_fire()[源代码]#
neuronal_reset(spike)[源代码]#
init_tensor(data: Tensor)[源代码]#
forward(x_seq: Tensor)[源代码]#
reset_noise(num_rl_step)[源代码]#
get_colored_noise()[源代码]#
load_colored_noise(cn)[源代码]#
cancel_load()[源代码]#
class spikingjelly.activation_based.neuron.noisy.NoisyCUBALIFNode(num_node, c_decay: float = 0.5, v_decay: float = 0.75, is_training: bool = True, T: int = 5, sigma_init: float = 0.5, beta: float = 0.0, v_threshold: float = 0.5, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:NoisyBaseNode

neuronal_charge(x: Tensor)[源代码]#
init_tensor(data: Tensor)[源代码]#
class spikingjelly.activation_based.neuron.noisy.NoisyILCBaseNode(act_dim, dec_pop_dim, is_training: bool = True, T: int = 5, sigma_init: float = 0.5, beta: float = 0.0, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:Module, MultiStepModule

abstractmethod neuronal_charge(x: Tensor)[源代码]#
neuronal_fire()[源代码]#
neuronal_reset(spike)[源代码]#
init_tensor(data: Tensor)[源代码]#
forward(x_seq: Tensor)[源代码]#
reset_noise(num_rl_step)[源代码]#
get_colored_noise()[源代码]#
load_colored_noise(cn)[源代码]#
cancel_load()[源代码]#
class spikingjelly.activation_based.neuron.noisy.NoisyILCCUBALIFNode(act_dim, dec_pop_dim, c_decay: float = 0.5, v_decay: float = 0.75, is_training: bool = True, T: int = 5, sigma_init: float = 0.5, beta: float = 0.0, v_threshold: float = 1.0, v_reset: float | None = 0.0, surrogate_function: SurrogateFunctionBase = Rect(alpha=1.0, spiking=True))[源代码]#

基类:NoisyILCBaseNode

neuronal_charge(x: Tensor)[源代码]#
init_tensor(data: Tensor)[源代码]#
class spikingjelly.activation_based.neuron.noisy.NoisyNonSpikingBaseNode(num_node, is_training: bool = True, T: int = 5, sigma_init: float = 0.5, beta: float = 0.0, decode: str | None = None)[源代码]#

基类:Module, MultiStepModule

abstractmethod neuronal_charge(x: Tensor)[源代码]#
init_tensor(data: Tensor)[源代码]#
forward(x_seq: Tensor)[源代码]#
reset_noise(num_rl_step)[源代码]#
get_colored_noise()[源代码]#
load_colored_noise(cn)[源代码]#
cancel_load()[源代码]#
class spikingjelly.activation_based.neuron.noisy.NoisyNonSpikingIFNode(num_node, is_training: bool = True, T: int = 5, sigma_init: float = 0.5, beta: float = 0.0, decode: str | None = None)[源代码]#

基类:NoisyNonSpikingBaseNode

neuronal_charge(x: Tensor)[源代码]#