Surrogate Gradicent

class snngrow.base.surrogate.BaseFunction.SurrogateFunctionBase(alpha, spike_out=False, spiking=True)

Bases: Module

Parameters:
  • alpha – parameter to control smoothness of gradient

  • spiking – output spikes. The default is True which means that using heaviside in forward propagation and using surrogate gradient in backward propagation. If False, in forward propagation, using the primitive function of the surrogate gradient function used in backward propagation

The base class of surrogate spiking function.

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.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

static primitive_function(x, alpha)
set_spiking_mode(spiking: bool)
static spiking_function(x, alpha, spike_out)
training: bool
class snngrow.base.surrogate.ATan.ATan(alpha=2.0, spike_out=False, spiking=True)

Bases: SurrogateFunctionBase

Parameters:
  • alpha – parameter to control smoothness of gradient

  • spiking – output spikes. The default is True which means that using heaviside in forward propagation and using surrogate gradient in backward propagation. If False, in forward propagation, using the primitive function of the surrogate gradient function used in backward propagation

The arc tangent surrogate spiking function

static backward(grad_output, x, alpha)
static primitive_function(x: Tensor, alpha: float)
static spiking_function(x, alpha, spike_out)
training: bool
class snngrow.base.surrogate.Sigmoid.Sigmoid(alpha=4.0, spike_out=False, spiking=True)

Bases: SurrogateFunctionBase

Parameters:
  • alpha – parameter to control smoothness of gradient

  • spiking – output spikes. The default is True which means that using heaviside in forward propagation and using surrogate gradient in backward propagation. If False, in forward propagation, using the primitive function of the surrogate gradient function used in backward propagation

The sigmoid surrogate spiking function.

static backward(grad_output, x, alpha)
static primitive_function(x: Tensor, alpha: float)
static spiking_function(x, alpha, spike_out)
training: bool