spikingjelly.clock_driven.neuron package¶
Module contents¶
-
class
spikingjelly.clock_driven.neuron.
BaseNode
(v_threshold=1.0, v_reset=0.0, surrogate_function=Sigmoid(alpha=1.0, spiking=True), detach_reset=False, monitor_state=False)[源代码]¶ 基类:
torch.nn.modules.module.Module
- 参数
v_threshold – 神经元的阈值电压
v_reset – 神经元的重置电压。如果不为
None
,当神经元释放脉冲后,电压会被重置为v_reset
; 如果设置为None
,则电压会被减去v_threshold
surrogate_function – 反向传播时用来计算脉冲函数梯度的替代函数
detach_reset – 是否将reset过程的计算图分离
monitor_state – 是否设置监视器来保存神经元的电压和释放的脉冲。 若为
True
,则self.monitor
是一个字典,键包括h
,v
s
,分别记录充电后的电压、释放脉冲后的电压、释放的脉冲。 对应的值是一个链表。为了节省显存(内存),列表中存入的是原始变量转换为numpy
数组后的值。 还需要注意,self.reset()
函数会清空这些链表
可微分SNN神经元的基类神经元。
- 参数
v_threshold – threshold voltage of neurons
v_reset – reset voltage of neurons. If not
None
, voltage of neurons that just fired spikes will be set tov_reset
. IfNone
, voltage of neurons that just fired spikes will subtractv_threshold
surrogate_function – surrogate function for replacing gradient of spiking functions during back-propagation
detach_reset – whether detach the computation graph of reset
detach_reset – whether detach the computation graph of reset
monitor_state – whether to set a monitor to recode voltage and spikes of neurons. If
True
,self.monitor
will be a dictionary with keyh
for recording membrane potential after charging,v
for recording membrane potential after firing ands
for recording output spikes. And the value of the dictionary is lists. To save memory, the elements in lists arenumpy
array converted from origin data. Besides,self.reset()
will clear these lists in the dictionary
This class is the base class of differentiable spiking neurons.
-
abstract
neuronal_charge
(dv: torch.Tensor)[源代码]¶ 定义神经元的充电差分方程。子类必须实现这个函数。
Define the charge difference equation. The sub-class must implement this function.
-
neuronal_fire
()[源代码]¶ -
根据当前神经元的电压、阈值,计算输出脉冲。
Calculate out spikes of neurons by their current membrane potential and threshold voltage.
-
neuronal_reset
()[源代码]¶ -
根据当前神经元释放的脉冲,对膜电位进行重置。
Reset the membrane potential according to neurons’ output spikes.
-
set_monitor
(monitor_state=True)[源代码]¶ -
- 参数
monitor_state –
True
或False
,表示开启或关闭monitor- 返回
None
设置开启或关闭monitor。
- 参数
monitor_state –
True
orFalse
, which indicates turn on or turn off the monitor- 返回
None
Turn on or turn off the monitor.
-
forward
(dv: torch.Tensor)[源代码]¶ -
- 参数
dv – 输入到神经元的电压增量
- 返回
神经元的输出脉冲
按照充电、放电、重置的顺序进行前向传播。
- 参数
dv – increment of voltage inputted to neurons
- 返回
out spikes of neurons
Forward by the order of neuronal_charge, neuronal_fire, and neuronal_reset.
-
class
spikingjelly.clock_driven.neuron.
IFNode
(v_threshold=1.0, v_reset=0.0, surrogate_function=Sigmoid(alpha=1.0, spiking=True), detach_reset=False, monitor_state=False)[源代码]¶ 基类:
spikingjelly.clock_driven.neuron.BaseNode
- 参数
v_threshold – 神经元的阈值电压
v_reset – 神经元的重置电压。如果不为
None
,当神经元释放脉冲后,电压会被重置为v_reset
; 如果设置为None
,则电压会被减去v_threshold
surrogate_function – 反向传播时用来计算脉冲函数梯度的替代函数
detach_reset – 是否将reset过程的计算图分离
monitor_state – 是否设置监视器来保存神经元的电压和释放的脉冲。 若为
True
,则self.monitor
是一个字典,键包括h
,v
s
,分别记录充电后的电压、释放脉冲后的电压、释放的脉冲。 对应的值是一个链表。为了节省显存(内存),列表中存入的是原始变量转换为numpy
数组后的值。 还需要注意,self.reset()
函数会清空这些链表
Integrate-and-Fire 神经元模型,可以看作理想积分器,无输入时电压保持恒定,不会像LIF神经元那样衰减。其阈下神经动力学方程为:
\[\frac{\mathrm{d}V(t)}{\mathrm{d} t} = R_{m}I(t)\]- 参数
v_threshold – threshold voltage of neurons
v_reset – reset voltage of neurons. If not
None
, voltage of neurons that just fired spikes will be set tov_reset
. IfNone
, voltage of neurons that just fired spikes will subtractv_threshold
surrogate_function – surrogate function for replacing gradient of spiking functions during back-propagation
detach_reset – whether detach the computation graph of reset
monitor_state – whether to set a monitor to recode voltage and spikes of neurons. If
True
,self.monitor
will be a dictionary with keyh
for recording membrane potential after charging,v
for recording membrane potential after firing ands
for recording output spikes. And the value of the dictionary is lists. To save memory, the elements in lists arenumpy
array converted from origin data. Besides,self.reset()
will clear these lists in the dictionary
The Integrate-and-Fire neuron, which can be seen as a ideal integrator. The voltage of the IF neuron will not decay as that of the LIF neuron. The subthreshold neural dynamics of it is as followed:
\[\frac{\mathrm{d}V(t)}{\mathrm{d} t} = R_{m}I(t)\]-
neuronal_charge
(dv: torch.Tensor)[源代码]¶
-
class
spikingjelly.clock_driven.neuron.
LIFNode
(tau=100.0, v_threshold=1.0, v_reset=0.0, surrogate_function=Sigmoid(alpha=1.0, spiking=True), detach_reset=False, monitor_state=False)[源代码]¶ 基类:
spikingjelly.clock_driven.neuron.BaseNode
- 参数
tau – 膜电位时间常数。
tau
对于这一层的所有神经元都是共享的v_threshold – 神经元的阈值电压
v_reset – 神经元的重置电压。如果不为
None
,当神经元释放脉冲后,电压会被重置为v_reset
; 如果设置为None
,则电压会被减去v_threshold
surrogate_function – 反向传播时用来计算脉冲函数梯度的替代函数
detach_reset – 是否将reset过程的计算图分离
monitor_state – 是否设置监视器来保存神经元的电压和释放的脉冲。 若为
True
,则self.monitor
是一个字典,键包括h
,v
s
,分别记录充电后的电压、释放脉冲后的电压、释放的脉冲。 对应的值是一个链表。为了节省显存(内存),列表中存入的是原始变量转换为numpy
数组后的值。 还需要注意,self.reset()
函数会清空这些链表
Leaky Integrate-and-Fire 神经元模型,可以看作是带漏电的积分器。其阈下神经动力学方程为:
\[\tau_{m} \frac{\mathrm{d}V(t)}{\mathrm{d}t} = -(V(t) - V_{reset}) + R_{m}I(t)\]- 参数
tau – membrane time constant.
tau
is shared by all neurons in this layerv_threshold – threshold voltage of neurons
v_reset – reset voltage of neurons. If not
None
, voltage of neurons that just fired spikes will be set tov_reset
. IfNone
, voltage of neurons that just fired spikes will subtractv_threshold
surrogate_function – surrogate function for replacing gradient of spiking functions during back-propagation
detach_reset – whether detach the computation graph of reset
monitor_state – whether to set a monitor to recode voltage and spikes of neurons. If
True
,self.monitor
will be a dictionary with keyh
for recording membrane potential after charging,v
for recording membrane potential after firing ands
for recording output spikes. And the value of the dictionary is lists. To save memory, the elements in lists arenumpy
array converted from origin data. Besides,self.reset()
will clear these lists in the dictionary
The Leaky Integrate-and-Fire neuron, which can be seen as a leaky integrator. The subthreshold neural dynamics of it is as followed:
\[\tau_{m} \frac{\mathrm{d}V(t)}{\mathrm{d}t} = -(V(t) - V_{reset}) + R_{m}I(t)\]-
neuronal_charge
(dv: torch.Tensor)[源代码]¶