spikingjelly.activation_based.base package

Module contents

spikingjelly.activation_based.base.check_backend_library(backend: str)[源代码]
参数:

backend (str) – 'torch', 'cupy''lava'

检查某个后端的python库是否已经安装。若未安装则此函数会报错。

参数:

backend (str) – 'torch', 'cupy' or 'lava'

Check whether the python lib for backend is installed. If not, this function will raise an error.

class spikingjelly.activation_based.base.StepModule[源代码]

基类:object

supported_step_mode()[源代码]
返回:

包含支持的后端的tuple

返回类型:

tuple[str]

返回此模块支持的步进模式。

返回:

a tuple that contains the supported backends

返回类型:

tuple[str]

property step_mode
返回:

模块当前使用的步进模式

返回类型:

str

返回:

the current step mode of this module

返回类型:

str

class spikingjelly.activation_based.base.SingleModule[源代码]

基类:StepModule

只支持单步的模块 (step_mode == 's')。

The module that only supports for single-step (step_mode == 's')

supported_step_mode()[源代码]
class spikingjelly.activation_based.base.MultiStepModule[源代码]

基类:StepModule

只支持多步的模块 (step_mode == 'm')。

The module that only supports for multi-step (step_mode == 'm')

supported_step_mode()[源代码]
class spikingjelly.activation_based.base.MemoryModule[源代码]

基类:Module, StepModule

MemoryModule 是SpikingJelly中所有有状态(记忆)模块的基类。

MemoryModule is the base class of all stateful modules in SpikingJelly.

property supported_backends

返回支持的后端,默认情况下只有 (‘torch’, )

返回:

支持的后端

返回类型:

tuple[str]

Return the supported backends. The default return value is (‘torch’, )

返回:

supported backends

返回类型:

tuple[str]

property backend
abstract single_step_forward(x: Tensor, *args, **kwargs)[源代码]
参数:

x (torch.Tensor) – input tensor with ``shape = [N, *] ``

本模块的单步的前向传播函数

参数:

x (torch.Tensor) – input tensor with ``shape = [N, *] ``

The single-step forward function for this module

multi_step_forward(x_seq: Tensor, *args, **kwargs)[源代码]
参数:

x (torch.Tensor) – input tensor with ``shape = [T, N, *] ``

本模块的多步的前向传播函数,通过调用 Tsingle_step_forward(x[t], *args, **kwargs) 实现

参数:

x (torch.Tensor) – input tensor with ``shape = [T, N, *] ``

The multi-step forward function for this module, which is implemented by calling single_step_forward(x[t], *args, **kwargs) over T times

forward(*args, **kwargs)[源代码]
extra_repr()[源代码]
register_memory(name: str, value)[源代码]
参数:
  • name (str) – 变量的名字

  • value (any) – 变量的值

将变量存入用于保存有状态变量(例如脉冲神经元的膜电位)的字典中。这个变量的重置值会被设置为 value。每次调用 self.reset() 函数后, self.name 都会被重置为 value

参数:
  • name (str) – variable’s name

  • value (any) – variable’s value

Register the variable to memory dict, which saves stateful variables (e.g., the membrane potential of a spiking neuron). The reset value of this variable will be value. self.name will be set to value after each calling of self.reset().

reset()[源代码]

重置所有有状态变量为默认值。

Reset all stateful variables to their default values.

set_reset_value(name: str, value)[源代码]
memories()[源代码]
返回:

返回一个所有状态变量的迭代器

返回类型:

Iterator

返回:

an iterator over all stateful variables

返回类型:

Iterator

named_memories()[源代码]
返回:

返回一个所有状态变量及其名称的迭代器

返回类型:

Iterator

返回:

an iterator over all stateful variables and their names

返回类型:

Iterator

detach()[源代码]

从计算图中分离所有有状态变量。

小技巧

可以使用这个函数实现TBPTT(Truncated Back Propagation Through Time)。

Detach all stateful variables.

Tip

We can use this function to implement TBPTT(Truncated Back Propagation Through Time).

training: bool