Learning State Updates#
这些函数显式接收 STDP/mSTDP/mSTDP-ET 的局部状态和 raw tensor 参数,不读取
MemoryModule 的隐式 memory、monitor 缓存,也不负责 step_mode、
training/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>)[源代码]#
-
中文
执行全连接权重的单步 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_spike和out_spike同形状、同 device,且 dtype 可参与对应计算weight (Tensor) -- 权重,形状
[out_features, in_features]tau_pre (float) -- pre-synaptic trace 时间常数
tau_post (float) -- post-synaptic trace 时间常数
- 返回:
(delta_w, (trace_pre_next, trace_post_next));delta_w与weight同形状- 返回类型:
English
Run one STDP update for a linear weight.
traceis(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 asin_spikeandout_spike, respectively, and dtypes compatible with the corresponding computationsweight (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_whas the same shape asweight- 返回类型:
备注
本函数没有独立多步形式;多步执行由调用者逐步循环。 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>)[源代码]#
-
中文
执行全连接权重的单步 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_spike和out_spike同形状、同 deviceweight (Tensor) -- 权重,形状
[out_features, in_features]tau_pre (float) -- pre-synaptic trace 时间常数
tau_post (float) -- post-synaptic trace 时间常数
- 返回:
(eligibility, (trace_pre_next, trace_post_next));eligibility形状为[N, out_features, in_features]- 返回类型:
English
Compute one mSTDP eligibility step for a linear weight.
traceis(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 asin_spikeandout_spike, respectivelyweight (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));eligibilityis shaped[N, out_features, in_features]- 返回类型:
备注
本函数没有独立多步形式;多步执行由调用者逐步循环。 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>)[源代码]#
-
中文
执行无 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_spike和out_spike同形状、同 deviceweight (Tensor) -- 权重,形状
[out_features, in_features]tau_pre (float) -- pre-synaptic trace 时间常数
tau_post (float) -- post-synaptic trace 时间常数
- 返回:
(eligibility, (trace_pre_next, trace_post_next));eligibility与weight同形状- 返回类型:
English
Compute one mSTDP-ET eligibility step for unbatched linear spikes.
traceis(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 asin_spikeandout_spike, respectivelyweight (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));eligibilityhas the same shape asweight- 返回类型:
备注
本函数没有独立多步形式;多步执行由调用者逐步循环。 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>)[源代码]#
-
中文
执行一维卷积权重的单步 STDP 更新。
trace是(trace_pre, trace_post)。in_spike必须已经按突触层的 padding 规则展开;函数因此只表达 dilation 为 1、groups 为 1 的卷积 STDP 方程, 不读取Conv1dmodule 或解释 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_spike和out_spike同形状、同 deviceweight (Tensor) -- 权重,形状
[C_out, C_in, K]stride (Tuple[int]) -- 一维卷积步长
(stride,)tau_pre (float) -- pre-synaptic trace 时间常数
tau_post (float) -- post-synaptic trace 时间常数
- 返回:
(delta_w, (trace_pre_next, trace_post_next));delta_w与weight同形状- 返回类型:
English
Run one STDP update for a 1D convolution weight.
traceis(trace_pre, trace_post).in_spikemust 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 aConv1dmodule 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 asin_spikeandout_spike, respectivelyweight (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_whas the same shape asweight- 返回类型:
备注
本函数没有独立多步形式;多步执行由调用者逐步循环。 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>)[源代码]#
-
中文
执行二维卷积权重的单步 STDP 更新。
trace是(trace_pre, trace_post)。in_spike必须已经按突触层的 padding 规则展开;函数因此只表达 dilation 为 1、groups 为 1 的卷积 STDP 方程, 不读取Conv2dmodule 或解释 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_spike和out_spike同形状、同 deviceweight (Tensor) -- 权重,形状
[C_out, C_in, K_h, K_w]tau_pre (float) -- pre-synaptic trace 时间常数
tau_post (float) -- post-synaptic trace 时间常数
- 返回:
(delta_w, (trace_pre_next, trace_post_next));delta_w与weight同形状- 返回类型:
English
Run one STDP update for a 2D convolution weight.
traceis(trace_pre, trace_post).in_spikemust 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 aConv2dmodule 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 asin_spikeandout_spike, respectivelyweight (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_whas the same shape asweight- 返回类型:
备注
本函数没有独立多步形式;多步执行由调用者逐步循环。 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)[源代码]#
-
中文
更新 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}\]- 参数:
- 返回:
(delta_w, trace_e_next)- 返回类型:
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}\]- 参数:
- 返回:
(delta_w, trace_e_next)- 返回类型:
备注
本函数没有独立多步形式;多步执行由调用者逐步循环。 This function has no independent multi-step form; callers iterate it.