Learning State Updates#

这些函数显式接收 STDP/mSTDP/mSTDP-ET 的局部状态和 raw tensor 参数,不读取 MemoryModule 的隐式 memory、monitor 缓存,也不负责 step_modetraining/eval 或梯度写入。


These functions receive STDP/mSTDP/mSTDP-ET local state and raw tensor parameters explicitly. They do not read implicit MemoryModule memory or monitor buffers, and do not manage step_mode, training/eval, or gradient writes.

spikingjelly.activation_based.functional.learning.stdp_linear_step(in_spike, out_spike, trace, weight, *, tau_pre, tau_post, f_pre=<function _identity>, f_post=<function _identity>)[源代码]#

API Language - 中文 | English


  • 中文

执行全连接权重的单步 STDP 更新。trace(trace_pre, trace_post);函数先更新两个 trace,再用更新后的 trace 计算权重增量,返回 (delta_w, trace_next)。输入状态不会被原地修改。

\[\begin{split}tr_{pre}^{t+1} &= tr_{pre}^{t} - tr_{pre}^{t} / \tau_{pre} + s_{pre}^{t} \\ tr_{post}^{t+1} &= tr_{post}^{t} - tr_{post}^{t} / \tau_{post} + s_{post}^{t}\end{split}\]
参数:
  • in_spike (Tensor) -- 输入脉冲,形状 [N, in_features]

  • out_spike (Tensor) -- 输出脉冲,形状 [N, out_features]

  • trace (Tuple[Tensor, Tensor]) -- 当前 (trace_pre, trace_post),两者分别与 in_spikeout_spike 同形状、同 device,且 dtype 可参与对应计算

  • weight (Tensor) -- 权重,形状 [out_features, in_features]

  • tau_pre (float) -- pre-synaptic trace 时间常数

  • tau_post (float) -- post-synaptic trace 时间常数

  • f_pre (Callable[[Tensor], Tensor]) -- 作用于 pre 分支权重的调制函数

  • f_post (Callable[[Tensor], Tensor]) -- 作用于 post 分支权重的调制函数

返回:

(delta_w, (trace_pre_next, trace_post_next))delta_wweight 同形状

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]


  • English

Run one STDP update for a linear weight. trace is (trace_pre, trace_post). The function updates both traces first, computes the weight increment from the updated traces, and returns (delta_w, trace_next). It does not mutate the input state in place.

\[\begin{split}tr_{pre}^{t+1} &= tr_{pre}^{t} - tr_{pre}^{t} / \tau_{pre} + s_{pre}^{t} \\ tr_{post}^{t+1} &= tr_{post}^{t} - tr_{post}^{t} / \tau_{post} + s_{post}^{t}\end{split}\]
参数:
  • in_spike (Tensor) -- Input spikes shaped [N, in_features]

  • out_spike (Tensor) -- Output spikes shaped [N, out_features]

  • trace (Tuple[Tensor, Tensor]) -- Current (trace_pre, trace_post). The tensors have the same shapes and devices as in_spike and out_spike, respectively, and dtypes compatible with the corresponding computations

  • weight (Tensor) -- Weight shaped [out_features, in_features]

  • tau_pre (float) -- Time constant of the pre-synaptic trace

  • tau_post (float) -- Time constant of the post-synaptic trace

  • f_pre (Callable[[Tensor], Tensor]) -- Weight modulation function for the pre branch

  • f_post (Callable[[Tensor], Tensor]) -- Weight modulation function for the post branch

返回:

(delta_w, (trace_pre_next, trace_post_next)); delta_w has the same shape as weight

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.

spikingjelly.activation_based.functional.learning.mstdp_linear_step(in_spike, out_spike, trace, weight, *, tau_pre, tau_post, f_pre=<function _identity>, f_post=<function _identity>)[源代码]#

API Language - 中文 | English


  • 中文

执行全连接权重的单步 mSTDP eligibility 计算。trace(trace_pre, trace_post)。返回的 eligibility 保留 batch 维,供调用者 进一步施加 reward;本函数不接收或处理 reward。

参数:
  • in_spike (Tensor) -- 输入脉冲,形状 [N, in_features]

  • out_spike (Tensor) -- 输出脉冲,形状 [N, out_features]

  • trace (Tuple[Tensor, Tensor]) -- 当前 (trace_pre, trace_post),两者分别与 in_spikeout_spike 同形状、同 device

  • weight (Tensor) -- 权重,形状 [out_features, in_features]

  • tau_pre (float) -- pre-synaptic trace 时间常数

  • tau_post (float) -- post-synaptic trace 时间常数

  • f_pre (Callable[[Tensor], Tensor]) -- 作用于 pre 分支权重的调制函数

  • f_post (Callable[[Tensor], Tensor]) -- 作用于 post 分支权重的调制函数

返回:

(eligibility, (trace_pre_next, trace_post_next))eligibility 形状为 [N, out_features, in_features]

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]


  • English

Compute one mSTDP eligibility step for a linear weight. trace is (trace_pre, trace_post). The returned eligibility retains its batch dimension for subsequent reward modulation; this function neither receives nor applies a reward.

参数:
  • in_spike (Tensor) -- Input spikes shaped [N, in_features]

  • out_spike (Tensor) -- Output spikes shaped [N, out_features]

  • trace (Tuple[Tensor, Tensor]) -- Current (trace_pre, trace_post) with the same shapes and devices as in_spike and out_spike, respectively

  • weight (Tensor) -- Weight shaped [out_features, in_features]

  • tau_pre (float) -- Time constant of the pre-synaptic trace

  • tau_post (float) -- Time constant of the post-synaptic trace

  • f_pre (Callable[[Tensor], Tensor]) -- Weight modulation function for the pre branch

  • f_post (Callable[[Tensor], Tensor]) -- Weight modulation function for the post branch

返回:

(eligibility, (trace_pre_next, trace_post_next)); eligibility is shaped [N, out_features, in_features]

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.

spikingjelly.activation_based.functional.learning.mstdpet_linear_step(in_spike, out_spike, trace, weight, *, tau_pre, tau_post, f_pre=<function _identity>, f_post=<function _identity>)[源代码]#

API Language - 中文 | English


  • 中文

执行无 batch 维全连接脉冲的单步 mSTDP-ET eligibility 计算。trace(trace_pre, trace_post)。本函数只更新神经元 trace 并计算 eligibility; eligibility trace 的衰减与 reward 调制由 mstdpet_reward_step() 完成。

参数:
  • in_spike (Tensor) -- 输入脉冲,形状 [in_features]

  • out_spike (Tensor) -- 输出脉冲,形状 [out_features]

  • trace (Tuple[Tensor, Tensor]) -- 当前 (trace_pre, trace_post),两者分别与 in_spikeout_spike 同形状、同 device

  • weight (Tensor) -- 权重,形状 [out_features, in_features]

  • tau_pre (float) -- pre-synaptic trace 时间常数

  • tau_post (float) -- post-synaptic trace 时间常数

  • f_pre (Callable[[Tensor], Tensor]) -- 作用于 pre 分支权重的调制函数

  • f_post (Callable[[Tensor], Tensor]) -- 作用于 post 分支权重的调制函数

返回:

(eligibility, (trace_pre_next, trace_post_next))eligibilityweight 同形状

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]


  • English

Compute one mSTDP-ET eligibility step for unbatched linear spikes. trace is (trace_pre, trace_post). This function only updates the neuronal traces and computes eligibility. mstdpet_reward_step() handles eligibility-trace decay and reward modulation.

参数:
  • in_spike (Tensor) -- Input spikes shaped [in_features]

  • out_spike (Tensor) -- Output spikes shaped [out_features]

  • trace (Tuple[Tensor, Tensor]) -- Current (trace_pre, trace_post) with the same shapes and devices as in_spike and out_spike, respectively

  • weight (Tensor) -- Weight shaped [out_features, in_features]

  • tau_pre (float) -- Time constant of the pre-synaptic trace

  • tau_post (float) -- Time constant of the post-synaptic trace

  • f_pre (Callable[[Tensor], Tensor]) -- Weight modulation function for the pre branch

  • f_post (Callable[[Tensor], Tensor]) -- Weight modulation function for the post branch

返回:

(eligibility, (trace_pre_next, trace_post_next)); eligibility has the same shape as weight

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.

spikingjelly.activation_based.functional.learning.stdp_conv1d_step(in_spike, out_spike, trace, weight, *, stride, tau_pre, tau_post, f_pre=<function _identity>, f_post=<function _identity>)[源代码]#

API Language - 中文 | English


  • 中文

执行一维卷积权重的单步 STDP 更新。trace(trace_pre, trace_post)in_spike 必须已经按突触层的 padding 规则展开;函数因此只表达 dilation 为 1、groups 为 1 的卷积 STDP 方程, 不读取 Conv1d module 或解释 padding mode。

参数:
  • in_spike (Tensor) -- 已 padding 的输入脉冲,形状 [N, C_in, L_pad]

  • out_spike (Tensor) -- 输出脉冲,形状 [N, C_out, L_out]

  • trace (Tuple[Tensor, Tensor]) -- 当前 (trace_pre, trace_post),两者分别与 in_spikeout_spike 同形状、同 device

  • weight (Tensor) -- 权重,形状 [C_out, C_in, K]

  • stride (Tuple[int]) -- 一维卷积步长 (stride,)

  • tau_pre (float) -- pre-synaptic trace 时间常数

  • tau_post (float) -- post-synaptic trace 时间常数

  • f_pre (Callable[[Tensor], Tensor]) -- 作用于 pre 分支权重的调制函数

  • f_post (Callable[[Tensor], Tensor]) -- 作用于 post 分支权重的调制函数

返回:

(delta_w, (trace_pre_next, trace_post_next))delta_wweight 同形状

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]


  • English

Run one STDP update for a 1D convolution weight. trace is (trace_pre, trace_post). in_spike must already include the synaptic layer's padding. The function consequently expresses only the convolutional STDP equation for dilation 1 and one group; it neither reads a Conv1d module nor interprets a padding mode.

参数:
  • in_spike (Tensor) -- Padded input spikes shaped [N, C_in, L_pad]

  • out_spike (Tensor) -- Output spikes shaped [N, C_out, L_out]

  • trace (Tuple[Tensor, Tensor]) -- Current (trace_pre, trace_post) with the same shapes and devices as in_spike and out_spike, respectively

  • weight (Tensor) -- Weight shaped [C_out, C_in, K]

  • stride (Tuple[int]) -- Convolution stride (stride,)

  • tau_pre (float) -- Time constant of the pre-synaptic trace

  • tau_post (float) -- Time constant of the post-synaptic trace

  • f_pre (Callable[[Tensor], Tensor]) -- Weight modulation function for the pre branch

  • f_post (Callable[[Tensor], Tensor]) -- Weight modulation function for the post branch

返回:

(delta_w, (trace_pre_next, trace_post_next)); delta_w has the same shape as weight

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.

spikingjelly.activation_based.functional.learning.stdp_conv2d_step(in_spike, out_spike, trace, weight, *, stride, tau_pre, tau_post, f_pre=<function _identity>, f_post=<function _identity>)[源代码]#

API Language - 中文 | English


  • 中文

执行二维卷积权重的单步 STDP 更新。trace(trace_pre, trace_post)in_spike 必须已经按突触层的 padding 规则展开;函数因此只表达 dilation 为 1、groups 为 1 的卷积 STDP 方程, 不读取 Conv2d module 或解释 padding mode。

参数:
  • in_spike (Tensor) -- 已 padding 的输入脉冲,形状 [N, C_in, H_pad, W_pad]

  • out_spike (Tensor) -- 输出脉冲,形状 [N, C_out, H_out, W_out]

  • trace (Tuple[Tensor, Tensor]) -- 当前 (trace_pre, trace_post),两者分别与 in_spikeout_spike 同形状、同 device

  • weight (Tensor) -- 权重,形状 [C_out, C_in, K_h, K_w]

  • stride (Tuple[int, int]) -- 二维卷积步长 (stride_h, stride_w)

  • tau_pre (float) -- pre-synaptic trace 时间常数

  • tau_post (float) -- post-synaptic trace 时间常数

  • f_pre (Callable[[Tensor], Tensor]) -- 作用于 pre 分支权重的调制函数

  • f_post (Callable[[Tensor], Tensor]) -- 作用于 post 分支权重的调制函数

返回:

(delta_w, (trace_pre_next, trace_post_next))delta_wweight 同形状

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]


  • English

Run one STDP update for a 2D convolution weight. trace is (trace_pre, trace_post). in_spike must already include the synaptic layer's padding. The function consequently expresses only the convolutional STDP equation for dilation 1 and one group; it neither reads a Conv2d module nor interprets a padding mode.

参数:
  • in_spike (Tensor) -- Padded input spikes shaped [N, C_in, H_pad, W_pad]

  • out_spike (Tensor) -- Output spikes shaped [N, C_out, H_out, W_out]

  • trace (Tuple[Tensor, Tensor]) -- Current (trace_pre, trace_post) with the same shapes and devices as in_spike and out_spike, respectively

  • weight (Tensor) -- Weight shaped [C_out, C_in, K_h, K_w]

  • stride (Tuple[int, int]) -- Convolution stride (stride_h, stride_w)

  • tau_pre (float) -- Time constant of the pre-synaptic trace

  • tau_post (float) -- Time constant of the post-synaptic trace

  • f_pre (Callable[[Tensor], Tensor]) -- Weight modulation function for the pre branch

  • f_post (Callable[[Tensor], Tensor]) -- Weight modulation function for the post branch

返回:

(delta_w, (trace_pre_next, trace_post_next)); delta_w has the same shape as weight

返回类型:

Tuple[Tensor, Tuple[Tensor, Tensor]]

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.

spikingjelly.activation_based.functional.learning.mstdpet_reward_step(reward, eligibility, trace_e, *, tau_trace)[源代码]#

API Language - 中文 | English


  • 中文

更新 mSTDP-ET eligibility trace,并用 reward 调制更新后的 trace。

\[\begin{split}tr_e^{t+1} &= tr_e^t \exp(-1 / \tau_{trace}) + e^t / \tau_{trace} \\ \Delta W^t &= r^t tr_e^{t+1}\end{split}\]
参数:
  • reward (Tensor or float) -- 标量或可与 trace_e 广播的 reward

  • eligibility (Tensor) -- 当前 eligibility,形状与 trace_e 相同或可广播

  • trace_e (Tensor) -- 当前 eligibility trace

  • tau_trace (float) -- eligibility trace 时间常数

返回:

(delta_w, trace_e_next)

返回类型:

Tuple[Tensor, Tensor]


  • English

Update the mSTDP-ET eligibility trace and modulate the updated trace with the reward.

\[\begin{split}tr_e^{t+1} &= tr_e^t \exp(-1 / \tau_{trace}) + e^t / \tau_{trace} \\ \Delta W^t &= r^t tr_e^{t+1}\end{split}\]
参数:
  • reward (Tensor or float) -- Scalar reward or a tensor broadcastable with trace_e

  • eligibility (Tensor) -- Current eligibility with the same shape as trace_e or a broadcast-compatible shape

  • trace_e (Tensor) -- Current eligibility trace

  • tau_trace (float) -- Time constant of the eligibility trace

返回:

(delta_w, trace_e_next)

返回类型:

Tuple[Tensor, Tensor]

备注

本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.