spikingjelly.activation_based.learning module#
- spikingjelly.activation_based.learning.stdp_linear_single_step(fc: ~torch.nn.modules.linear.Linear, in_spike: ~torch.Tensor, out_spike: ~torch.Tensor, trace_pre: float | ~torch.Tensor | None, trace_post: float | ~torch.Tensor | None, tau_pre: float, tau_post: float, f_pre: ~typing.Callable = <function <lambda>>, f_post: ~typing.Callable = <function <lambda>>)[源代码]#
-
中文
对单步脉冲输入执行全连接层的 STDP 更新,返回更新后的 pre/post trace 与权重增量。
- 参数:
fc (torch.nn.Linear) -- 需要执行 STDP 的全连接层
in_spike (torch.Tensor) -- 输入脉冲,
shape = [batch_size, in_features]out_spike (torch.Tensor) -- 输出脉冲,
shape = [batch_size, out_features]trace_pre (Union[float, torch.Tensor, None]) -- pre-synaptic trace。若为
None,则使用标量0.0初始化trace_post (Union[float, torch.Tensor, None]) -- post-synaptic trace。若为
None,则使用标量0.0初始化tau_pre (float) -- pre trace 的时间常数,要求为正数
tau_post (float) -- post trace 的时间常数,要求为正数
f_pre (Callable) -- 作用在当前权重上的 pre-update 调制函数
f_post (Callable) -- 作用在当前权重上的 post-update 调制函数
- 返回:
(trace_pre, trace_post, delta_w),其中delta_w的形状与fc.weight相同- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
English
Apply one STDP update step to a linear layer driven by single-step spike inputs, and return the updated pre/post traces together with the weight increment.
- 参数:
fc (torch.nn.Linear) -- Linear layer updated by STDP
in_spike (torch.Tensor) -- Input spikes with
shape = [batch_size, in_features]out_spike (torch.Tensor) -- Output spikes with
shape = [batch_size, out_features]trace_pre (Union[float, torch.Tensor, None]) -- Pre-synaptic trace. If
None, it is initialized as scalar0.0trace_post (Union[float, torch.Tensor, None]) -- Post-synaptic trace. If
None, it is initialized as scalar0.0tau_pre (float) -- Time constant of the pre trace. Expected to be positive
tau_post (float) -- Time constant of the post trace. Expected to be positive
f_pre (Callable) -- Pre-update modulation function applied to the current weight
f_post (Callable) -- Post-update modulation function applied to the current weight
- 返回:
(trace_pre, trace_post, delta_w), wheredelta_whas the same shape asfc.weight- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
- spikingjelly.activation_based.learning.mstdp_linear_single_step(fc: ~torch.nn.modules.linear.Linear, in_spike: ~torch.Tensor, out_spike: ~torch.Tensor, trace_pre: float | ~torch.Tensor | None, trace_post: float | ~torch.Tensor | None, tau_pre: float, tau_post: float, f_pre: ~typing.Callable = <function <lambda>>, f_post: ~typing.Callable = <function <lambda>>)[源代码]#
-
中文
对单步脉冲输入执行全连接层的 reward-modulated STDP eligibility 计算。
- 参数:
fc (torch.nn.Linear) -- 需要执行 mSTDP 的全连接层
in_spike (torch.Tensor) -- 输入脉冲,
shape = [batch_size, in_features]out_spike (torch.Tensor) -- 输出脉冲,
shape = [batch_size, out_features]trace_pre (Union[float, torch.Tensor, None]) -- pre-synaptic trace。若为
None,则使用标量0.0初始化trace_post (Union[float, torch.Tensor, None]) -- post-synaptic trace。若为
None,则使用标量0.0初始化tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
- 返回:
(trace_pre, trace_post, eligibility),其中eligibility的形状为[batch_size, out_features, in_features]- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
English
Compute the reward-modulated STDP eligibility tensor for a linear layer under single-step spike inputs.
- 参数:
fc (torch.nn.Linear) -- Linear layer updated by mSTDP
in_spike (torch.Tensor) -- Input spikes with
shape = [batch_size, in_features]out_spike (torch.Tensor) -- Output spikes with
shape = [batch_size, out_features]trace_pre (Union[float, torch.Tensor, None]) -- Pre-synaptic trace. If
None, it is initialized as scalar0.0trace_post (Union[float, torch.Tensor, None]) -- Post-synaptic trace. If
None, it is initialized as scalar0.0tau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- 返回:
(trace_pre, trace_post, eligibility), whereeligibilityhas shape[batch_size, out_features, in_features]- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
- spikingjelly.activation_based.learning.mstdpet_linear_single_step(fc: ~torch.nn.modules.linear.Linear, in_spike: ~torch.Tensor, out_spike: ~torch.Tensor, trace_pre: float | ~torch.Tensor | None, trace_post: float | ~torch.Tensor | None, tau_pre: float, tau_post: float, tau_trace: float, f_pre: ~typing.Callable = <function <lambda>>, f_post: ~typing.Callable = <function <lambda>>)[源代码]#
-
中文
对单步脉冲输入执行全连接层的 mSTDP-ET eligibility 计算。
- 参数:
fc (torch.nn.Linear) -- 需要执行 mSTDP-ET 的全连接层
in_spike (torch.Tensor) -- 输入脉冲,
shape = [in_features]out_spike (torch.Tensor) -- 输出脉冲,
shape = [out_features]trace_pre (Union[float, torch.Tensor, None]) -- pre-synaptic trace。若为
None,则使用标量0.0初始化trace_post (Union[float, torch.Tensor, None]) -- post-synaptic trace。若为
None,则使用标量0.0初始化tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
tau_trace (float) -- eligibility trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
- 返回:
(trace_pre, trace_post, eligibility),其中eligibility的形状与fc.weight相同- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
English
Compute the mSTDP-ET eligibility update for a linear layer under single-step spike inputs.
- 参数:
fc (torch.nn.Linear) -- Linear layer updated by mSTDP-ET
in_spike (torch.Tensor) -- Input spikes with
shape = [in_features]out_spike (torch.Tensor) -- Output spikes with
shape = [out_features]trace_pre (Union[float, torch.Tensor, None]) -- Pre-synaptic trace. If
None, it is initialized as scalar0.0trace_post (Union[float, torch.Tensor, None]) -- Post-synaptic trace. If
None, it is initialized as scalar0.0tau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
tau_trace (float) -- Time constant of the eligibility trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- 返回:
(trace_pre, trace_post, eligibility), whereeligibilityhas the same shape asfc.weight- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
- spikingjelly.activation_based.learning.stdp_conv2d_single_step(conv: ~torch.nn.modules.conv.Conv2d, in_spike: ~torch.Tensor, out_spike: ~torch.Tensor, trace_pre: ~torch.Tensor | None, trace_post: ~torch.Tensor | None, tau_pre: float, tau_post: float, f_pre: ~typing.Callable = <function <lambda>>, f_post: ~typing.Callable = <function <lambda>>)[源代码]#
-
中文
对单步脉冲输入执行二维卷积层的 STDP 更新。
当前仅支持
dilation == (1, 1)且groups == 1的卷积。- 参数:
conv (torch.nn.Conv2d) -- 需要执行 STDP 的二维卷积层
in_spike (torch.Tensor) -- 输入脉冲,
shape = [batch_size, C_in, H_in, W_in]out_spike (torch.Tensor) -- 输出脉冲,
shape = [batch_size, C_out, H_out, W_out]trace_pre (Union[torch.Tensor, None]) -- pre-synaptic trace。若为
None,则初始化为与in_spike同形状零张量trace_post (Union[torch.Tensor, None]) -- post-synaptic trace。若为
None,则初始化为与out_spike同形状零张量tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
- 返回:
(trace_pre, trace_post, delta_w),其中delta_w的形状与conv.weight相同- 返回类型:
- 抛出:
NotImplementedError -- 当
conv.dilation != (1, 1)或conv.groups != 1时抛出
English
Apply one STDP update step to a 2D convolution layer driven by single-step spike inputs.
Only convolutions with
dilation == (1, 1)andgroups == 1are currently supported.- 参数:
conv (torch.nn.Conv2d) -- 2D convolution layer updated by STDP
in_spike (torch.Tensor) -- Input spikes with
shape = [batch_size, C_in, H_in, W_in]out_spike (torch.Tensor) -- Output spikes with
shape = [batch_size, C_out, H_out, W_out]trace_pre (Union[torch.Tensor, None]) -- Pre-synaptic trace. If
None, initialized as zeros with the same shape asin_spiketrace_post (Union[torch.Tensor, None]) -- Post-synaptic trace. If
None, initialized as zeros with the same shape asout_spiketau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- 返回:
(trace_pre, trace_post, delta_w), wheredelta_whas the same shape asconv.weight- 返回类型:
- 抛出:
NotImplementedError -- Raised when
conv.dilation != (1, 1)orconv.groups != 1
- spikingjelly.activation_based.learning.stdp_conv1d_single_step(conv: ~torch.nn.modules.conv.Conv1d, in_spike: ~torch.Tensor, out_spike: ~torch.Tensor, trace_pre: ~torch.Tensor | None, trace_post: ~torch.Tensor | None, tau_pre: float, tau_post: float, f_pre: ~typing.Callable = <function <lambda>>, f_post: ~typing.Callable = <function <lambda>>)[源代码]#
-
中文
对单步脉冲输入执行一维卷积层的 STDP 更新。
当前仅支持
dilation == (1,)且groups == 1的卷积。- 参数:
conv (torch.nn.Conv1d) -- 需要执行 STDP 的一维卷积层
in_spike (torch.Tensor) -- 输入脉冲,
shape = [batch_size, C_in, L_in]out_spike (torch.Tensor) -- 输出脉冲,
shape = [batch_size, C_out, L_out]trace_pre (Union[torch.Tensor, None]) -- pre-synaptic trace。若为
None,则初始化为与in_spike同形状零张量trace_post (Union[torch.Tensor, None]) -- post-synaptic trace。若为
None,则初始化为与out_spike同形状零张量tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
- 返回:
(trace_pre, trace_post, delta_w),其中delta_w的形状与conv.weight相同- 返回类型:
- 抛出:
NotImplementedError -- 当
conv.dilation != (1,)或conv.groups != 1时抛出
English
Apply one STDP update step to a 1D convolution layer driven by single-step spike inputs.
Only convolutions with
dilation == (1,)andgroups == 1are currently supported.- 参数:
conv (torch.nn.Conv1d) -- 1D convolution layer updated by STDP
in_spike (torch.Tensor) -- Input spikes with
shape = [batch_size, C_in, L_in]out_spike (torch.Tensor) -- Output spikes with
shape = [batch_size, C_out, L_out]trace_pre (Union[torch.Tensor, None]) -- Pre-synaptic trace. If
None, initialized as zeros with the same shape asin_spiketrace_post (Union[torch.Tensor, None]) -- Post-synaptic trace. If
None, initialized as zeros with the same shape asout_spiketau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- 返回:
(trace_pre, trace_post, delta_w), wheredelta_whas the same shape asconv.weight- 返回类型:
- 抛出:
NotImplementedError -- Raised when
conv.dilation != (1,)orconv.groups != 1
- spikingjelly.activation_based.learning.stdp_multi_step(layer: ~torch.nn.modules.linear.Linear | ~torch.nn.modules.conv.Conv1d | ~torch.nn.modules.conv.Conv2d, in_spike: ~torch.Tensor, out_spike: ~torch.Tensor, trace_pre: float | ~torch.Tensor | None, trace_post: float | ~torch.Tensor | None, tau_pre: float, tau_post: float, f_pre: ~typing.Callable = <function <lambda>>, f_post: ~typing.Callable = <function <lambda>>)[源代码]#
-
中文
对线性层、一维卷积层或二维卷积层执行多步 STDP 更新。
该函数沿时间维遍历
in_spike与out_spike,并在每个时间步调用对应的 单步 STDP 规则,最终累加得到整段序列的权重增量。- 参数:
layer (Union[torch.nn.Linear, torch.nn.Conv1d, torch.nn.Conv2d]) -- 支持的突触层,目前为
nn.Linear、nn.Conv1d或nn.Conv2din_spike (torch.Tensor) -- 输入脉冲序列,时间维位于第 0 维
out_spike (torch.Tensor) -- 输出脉冲序列,时间维位于第 0 维
trace_pre (Union[float, torch.Tensor, None]) -- pre-synaptic trace 的初始值
trace_post (Union[float, torch.Tensor, None]) -- post-synaptic trace 的初始值
tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
- 返回:
(trace_pre, trace_post, delta_w),其中delta_w的形状与layer.weight相同- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
English
Apply multi-step STDP updates to a linear layer, a 1D convolution layer, or a 2D convolution layer.
The function iterates over the time dimension of
in_spikeandout_spike, applies the matching single-step STDP rule at each time step, and accumulates the weight increment over the whole sequence.- 参数:
layer (Union[torch.nn.Linear, torch.nn.Conv1d, torch.nn.Conv2d]) -- Supported synaptic layer. Currently
nn.Linear,nn.Conv1dornn.Conv2din_spike (torch.Tensor) -- Input spike sequence with the time axis at dimension 0
out_spike (torch.Tensor) -- Output spike sequence with the time axis at dimension 0
trace_pre (Union[float, torch.Tensor, None]) -- Initial value of the pre-synaptic trace
trace_post (Union[float, torch.Tensor, None]) -- Initial value of the post-synaptic trace
tau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- 返回:
(trace_pre, trace_post, delta_w), wheredelta_whas the same shape aslayer.weight- 返回类型:
tuple[Union[float, torch.Tensor], Union[float, torch.Tensor], torch.Tensor]
- class spikingjelly.activation_based.learning.STDPLearner(step_mode: str, synapse: ~torch.nn.modules.conv.Conv2d | ~torch.nn.modules.linear.Linear, sn: ~spikingjelly.activation_based.neuron.base_node.BaseNode, tau_pre: float, tau_post: float, f_pre: ~typing.Callable = <function STDPLearner.<lambda>>, f_post: ~typing.Callable = <function STDPLearner.<lambda>>)[源代码]#
基类:
MemoryModule
中文
基于监视器的 STDP 学习器。
该学习器通过
InputMonitor和OutputMonitor自动记录突触层输入脉冲与神经元输出脉冲,并在调用step()时根据step_mode选择单步或多步 STDP 规则。- 参数:
step_mode (str) --
's'表示单步 STDP,'m'表示多步 STDPsynapse (Union[torch.nn.Conv2d, torch.nn.Linear]) -- 需要执行 STDP 的突触层,目前支持
nn.Linear、nn.Conv1d、nn.Conv2dsn (spikingjelly.activation_based.neuron.BaseNode) -- 产生输出脉冲的脉冲神经元模块
tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
English
Monitor-based STDP learner.
The learner automatically records synaptic input spikes and neuronal output spikes with
InputMonitorandOutputMonitor. Whenstep()is called, it selects the single-step or multi-step STDP rule according tostep_mode.- 参数:
step_mode (str) --
's'for single-step STDP and'm'for multi-step STDPsynapse (Union[torch.nn.Conv2d, torch.nn.Linear]) -- Synaptic layer updated by STDP. Currently supports
nn.Linear,nn.Conv1d, andnn.Conv2dsn (spikingjelly.activation_based.neuron.BaseNode) -- Spiking neuron module that generates output spikes
tau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- reset()[源代码]#
-
中文
重置学习器内部状态,并清空输入/输出脉冲监视器中已记录的数据。
- 返回:
None- 返回类型:
None
English
Reset the learner state and clear all recorded data in the input/output spike monitors.
- 返回:
None- 返回类型:
None
- disable()[源代码]#
-
中文
禁用输入脉冲与输出脉冲监视器,使其停止记录新数据。
- 返回:
None- 返回类型:
None
English
Disable the input and output spike monitors so they stop recording new data.
- 返回:
None- 返回类型:
None
- enable()[源代码]#
-
中文
启用输入脉冲与输出脉冲监视器,使其恢复记录。
- 返回:
None- 返回类型:
None
English
Enable the input and output spike monitors so they resume recording.
- 返回:
None- 返回类型:
None
- step(on_grad: bool = True, scale: float = 1.0)[源代码]#
-
中文
使用当前监视器中缓存的脉冲记录执行一次 STDP 权重更新。
当
on_grad=True时,函数会把-delta_w累加到self.synapse.weight.grad; 当on_grad=False时,返回累计的delta_w而不写入梯度。- 参数:
- 返回:
当
on_grad=False时返回累计的权重增量;否则返回None- 返回类型:
Optional[torch.Tensor]
- 抛出:
NotImplementedError -- 当
self.step_mode与突触层类型组合当前不受支持时抛出ValueError -- 当
self.step_mode不是's'或'm'时抛出
English
Perform one STDP update using the spike records currently buffered in the monitors.
When
on_grad=True, the function accumulates-delta_wintoself.synapse.weight.grad. Whenon_grad=False, it returns the accumulateddelta_wwithout writing gradients.- 参数:
- 返回:
The accumulated weight increment when
on_grad=False; otherwiseNone- 返回类型:
Optional[torch.Tensor]
- 抛出:
NotImplementedError -- Raised when the current
step_mode/ synapse-type combination is unsupportedValueError -- Raised when
self.step_modeis neither's'nor'm'
- class spikingjelly.activation_based.learning.MSTDPLearner(step_mode: str, batch_size: float, synapse: ~torch.nn.modules.conv.Conv2d | ~torch.nn.modules.linear.Linear, sn: ~spikingjelly.activation_based.neuron.base_node.BaseNode, tau_pre: float, tau_post: float, f_pre: ~typing.Callable = <function MSTDPLearner.<lambda>>, f_post: ~typing.Callable = <function MSTDPLearner.<lambda>>)[源代码]#
基类:
MemoryModule
中文
reward-modulated STDP(mSTDP)学习器。
该学习器维护每个样本对应的 eligibility,并在
step()中结合外部奖励reward把 eligibility 转换为权重更新。- 参数:
step_mode (str) --
's'表示单步 mSTDPbatch_size (float) -- 每次奖励调制时使用的 batch 大小
synapse (Union[torch.nn.Conv2d, torch.nn.Linear]) -- 需要执行 mSTDP 的突触层
sn (spikingjelly.activation_based.neuron.BaseNode) -- 产生输出脉冲的脉冲神经元模块
tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
English
Reward-modulated STDP (mSTDP) learner.
The learner maintains per-sample eligibility tensors and converts them into weight updates inside
step()using the external rewardreward.- 参数:
step_mode (str) --
's'for single-step mSTDPbatch_size (float) -- Batch size used when modulating eligibility with rewards
synapse (Union[torch.nn.Conv2d, torch.nn.Linear]) -- Synaptic layer updated by mSTDP
sn (spikingjelly.activation_based.neuron.BaseNode) -- Spiking neuron module that generates output spikes
tau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- reset()[源代码]#
-
中文
重置学习器内部状态,并清空监视器缓存。
- 返回:
None- 返回类型:
None
English
Reset the learner state and clear the monitor buffers.
- 返回:
None- 返回类型:
None
- disable()[源代码]#
-
中文
禁用输入/输出监视器。
- 返回:
None- 返回类型:
None
English
Disable the input/output monitors.
- 返回:
None- 返回类型:
None
- enable()[源代码]#
-
中文
启用输入/输出监视器。
- 返回:
None- 返回类型:
None
English
Enable the input/output monitors.
- 返回:
None- 返回类型:
None
- step(reward, on_grad: bool = True, scale: float = 1.0)[源代码]#
-
中文
使用外部奖励
reward对当前 eligibility 进行调制,并生成一次 mSTDP 权重更新。- 参数:
reward (torch.Tensor) -- 每个样本对应的奖励,通常
shape = [batch_size]on_grad (bool) -- 是否将结果写入
self.synapse.weight.gradscale (float) -- 权重增量的缩放因子
- 返回:
当
on_grad=False时返回累计的权重增量;否则返回None- 返回类型:
Optional[torch.Tensor]
- 抛出:
NotImplementedError -- 当前仅部分支持特定
step_mode与突触层组合ValueError -- 当
self.step_mode不合法时抛出
English
Modulate the current eligibility with the external reward
rewardand generate one mSTDP weight update.- 参数:
reward (torch.Tensor) -- Reward for each sample, typically with
shape = [batch_size]on_grad (bool) -- Whether to write the result into
self.synapse.weight.gradscale (float) -- Scaling factor applied to the weight increment
- 返回:
The accumulated weight increment when
on_grad=False; otherwiseNone- 返回类型:
Optional[torch.Tensor]
- 抛出:
NotImplementedError -- Only some
step_mode/ synapse-type combinations are currently supportedValueError -- Raised when
self.step_modeis invalid
- class spikingjelly.activation_based.learning.MSTDPETLearner(step_mode: str, synapse: ~torch.nn.modules.conv.Conv2d | ~torch.nn.modules.linear.Linear, sn: ~spikingjelly.activation_based.neuron.base_node.BaseNode, tau_pre: float, tau_post: float, tau_trace: float, f_pre: ~typing.Callable = <function MSTDPETLearner.<lambda>>, f_post: ~typing.Callable = <function MSTDPETLearner.<lambda>>)[源代码]#
基类:
MemoryModule
中文
mSTDP-ET 学习器。
与
MSTDPLearner相比,该学习器额外维护随时间衰减的 eligibility tracetrace_e,并在step()中结合奖励生成最终权重更新。- 参数:
step_mode (str) --
's'表示单步 mSTDP-ETsynapse (Union[torch.nn.Conv2d, torch.nn.Linear]) -- 需要执行 mSTDP-ET 的突触层
sn (spikingjelly.activation_based.neuron.BaseNode) -- 产生输出脉冲的脉冲神经元模块
tau_pre (float) -- pre trace 的时间常数
tau_post (float) -- post trace 的时间常数
tau_trace (float) -- eligibility trace 的时间常数
f_pre (Callable) -- pre 分支的权重调制函数
f_post (Callable) -- post 分支的权重调制函数
English
mSTDP-ET learner.
Compared with
MSTDPLearner, this learner additionally maintains a temporally decaying eligibility tracetrace_eand combines it with rewards insidestep()to produce the final weight update.- 参数:
step_mode (str) --
's'for single-step mSTDP-ETsynapse (Union[torch.nn.Conv2d, torch.nn.Linear]) -- Synaptic layer updated by mSTDP-ET
sn (spikingjelly.activation_based.neuron.BaseNode) -- Spiking neuron module that generates output spikes
tau_pre (float) -- Time constant of the pre trace
tau_post (float) -- Time constant of the post trace
tau_trace (float) -- Time constant of the eligibility trace
f_pre (Callable) -- Weight modulation function for the pre branch
f_post (Callable) -- Weight modulation function for the post branch
- reset()[源代码]#
-
中文
重置学习器内部状态,并清空监视器缓存。
- 返回:
None- 返回类型:
None
English
Reset the learner state and clear the monitor buffers.
- 返回:
None- 返回类型:
None
- disable()[源代码]#
-
中文
禁用输入/输出监视器。
- 返回:
None- 返回类型:
None
English
Disable the input/output monitors.
- 返回:
None- 返回类型:
None
- enable()[源代码]#
-
中文
启用输入/输出监视器。
- 返回:
None- 返回类型:
None
English
Enable the input/output monitors.
- 返回:
None- 返回类型:
None
- step(reward, on_grad: bool = True, scale: float = 1.0)[源代码]#
-
中文
使用外部奖励
reward对 eligibility trace 进行调制,并生成一次 mSTDP-ET 权重更新。- 参数:
reward (torch.Tensor) -- 奖励信号,通常为标量或
shape = [batch_size]的张量on_grad (bool) -- 是否将结果写入
self.synapse.weight.gradscale (float) -- 权重增量的缩放因子
- 返回:
当
on_grad=False时返回累计的权重增量;否则返回None- 返回类型:
Optional[torch.Tensor]
- 抛出:
NotImplementedError -- 当前仅部分支持特定
step_mode与突触层组合ValueError -- 当
self.step_mode不合法时抛出
English
Modulate the eligibility trace with the external reward
rewardand generate one mSTDP-ET weight update.- 参数:
reward (torch.Tensor) -- Reward signal, typically a scalar or a tensor with
shape = [batch_size]on_grad (bool) -- Whether to write the result into
self.synapse.weight.gradscale (float) -- Scaling factor applied to the weight increment
- 返回:
The accumulated weight increment when
on_grad=False; otherwiseNone- 返回类型:
Optional[torch.Tensor]
- 抛出:
NotImplementedError -- Only some
step_mode/ synapse-type combinations are currently supportedValueError -- Raised when
self.step_modeis invalid