Neurons
- class snngrow.base.neuron.BaseNode.BaseNode(v_threshold: float = 1.0, v_reset: float = 0.0, surrogate_function: Callable = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, parallel_optim: bool = False, T: int = 1, spike_out: bool = False)
基类:
Module- 参数:
v_threshold (float) – threshold voltage
v_reset (float) – reset voltage. If not
None, the neuron’s voltage will be set tov_resetafter firing a spike. IfNone, the neuron’s voltage will subtractv_thresholdafter firing a spikesurrogate_function (Callable) – the function for calculating surrogate gradients of the heaviside step function in backward
detach_reset (bool) – detach the computation graph of reset in backward
parallel_optim (bool) – parallel optimization
T (int) – time steps
spike_out (bool) – whether to output SpikeTensor
The base class of differentiable spiking neurons.
- detach()
Detach all stateful variables.
Tip
We can use this function to implement TBPTT(Truncated Back Propagation Through Time).
- extra_repr()
Set the extra representation of the module
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
- forward(x: Tensor)
Defines the computation performed at every call.
Should be overridden by all subclasses.
备注
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- static hard_reset(v: Tensor, spike: Tensor, v_reset: float, spike_out: bool)
- memories()
- 返回:
an iterator over all stateful variables
- 返回类型:
Iterator
- named_memories()
- 返回:
an iterator over all stateful variables and their names
- 返回类型:
Iterator
- abstract neuronal_dynamics(x: Tensor)
The neuronal dynamics difference equation. The sub-class must implement this function.
- neuronal_fire(x: Tensor)
The neuronal fire difference equation.
- neuronal_reset(spike)
The neuronal reset difference equation.
- parallel_optim_forward(x_seq: Tensor)
-
The parallel forward function, which is implemented by calling
simple_forward(x_seq[t])overTtimes
- register_memory(name: str, 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.namewill be set tovalueafter each calling ofself.reset().
- reset()
Reset all stateful variables to their default values.
- set_reset_value(name: str, value)
- simple_forward(x: Tensor)
- 参数:
x (torch.Tensor) – increment of voltage inputted
- 返回:
out spikes
- 返回类型:
torch.Tensor
Forward by the order of dynamics - fire - reset.
- static soft_reset(v: Tensor, spike: Tensor, v_threshold: float, spike_out: bool)
- training: bool
- v_float_to_tensor(x: Tensor)
- class snngrow.base.neuron.LIFNode.LIFNode(tau: float = 2.0, decay_input: bool = True, v_threshold: float = 1.0, v_reset: float = 0.0, surrogate_function: Callable = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, parallel_optim: bool = False, T: int = 1, spike_out: bool = False)
基类:
BaseNode- 参数:
tau (float) – membrane time constant
decay_input (bool) – the input will decay
v_threshold (float) – threshold voltage
v_reset (float) – reset voltage. If not
None, the neuron’s voltage will be set tov_resetafter firing a spike. IfNone, the neuron’s voltage will subtractv_thresholdafter firing a spikesurrogate_function (Callable) – the function for calculating surrogate gradients of the heaviside step function in backward
detach_reset (bool) – detach the computation graph of reset in backward
parallel_optim (bool) – parallel optimization
T (int) – time steps
spike_out (bool) – whether to output SpikeTensor
The Leaky Integrate-and-Fire(LIF) neuron
- extra_repr()
Set the extra representation of the module
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
- neuronal_dynamics(x: Tensor)
The neuronal dynamics difference equation. The sub-class must implement this function.
- static neuronal_dynamics_decay_input(x: Tensor, v: Tensor, v_reset: float, tau: float)
- static neuronal_dynamics_decay_input_reset0(x: Tensor, v: Tensor, tau: float)
- static neuronal_dynamics_no_decay_input(x: Tensor, v: Tensor, v_reset: float, tau: float)
- static neuronal_dynamics_no_decay_input_reset0(x: Tensor, v: Tensor, tau: float)
- training: bool
- class snngrow.base.neuron.IFNode.IFNode(v_threshold: float = 1.0, v_reset: float = 0.0, surrogate_function: Callable = Sigmoid(alpha=4.0, spiking=True), detach_reset: bool = False, parallel_optim: bool = False, T: int = 1, spike_out: bool = False)
基类:
BaseNode- 参数:
v_threshold (float) – threshold voltage
v_reset (float) – reset voltage. If not
None, the neuron’s voltage will be set tov_resetafter firing a spike. IfNone, the neuron’s voltage will subtractv_thresholdafter firing a spikesurrogate_function (Callable) – the function for calculating surrogate gradients of the heaviside step function in backward
detach_reset (bool) – detach the computation graph of reset in backward
parallel_optim (bool) – parallel optimization
T (int) – time steps
spike_out (bool) – whether to output SpikeTensor
The Integrate-and-Fire(IF) neuron, without decay input as LIF neuron.
- neuronal_dynamics(x: Tensor)
The neuronal dynamics difference equation. The sub-class must implement this function.
- training: bool