norse.torch.module.snn module

Base module for spiking neural network (SNN) modules.

class norse.torch.module.snn.SNN(activation, state_fallback, p, dt=0.001, activation_sparse=None)[source]

Bases: torch.nn.modules.module.Module

The base module for spiking neural networks (RSNN) with time (without recurrence).

Parameters
  • activation (RecurrentActivation) – The activation function accepting an input tensor, state tensor, input weights, recurrent weights, and parameters module, and returning a tuple of (output spikes (one per timestep), state).

  • state_fallback (Callable[[torch.Tensor], torch.Tensor]) – A function that can return a default state with the correct dimensions, in case no state is provided in the forward pass.

  • p (torch.nn.Module) – The neuron parameters as a torch Module, which allows the module to configure neuron parameters as optimizable.

  • dt (float) – Time step to use in integration. Defaults to 0.001.

  • activation_sparse (Optional[FeedforwardActivation]) – A Sparse activation function - if it exists for the neuron model

Initializes internal Module state, shared by both nn.Module and ScriptModule.

extra_repr()[source]

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.

Return type

str

forward(input_tensor, state=None)[source]

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.

training: bool
class norse.torch.module.snn.SNNCell(activation, state_fallback, p, dt=0.001, activation_sparse=None)[source]

Bases: torch.nn.modules.module.Module

Initializes a feedforward neuron cell without time.

Parameters
  • activation (FeedforwardActivation) – The activation function accepting an input tensor, state tensor, and parameters module, and returning a tuple of (output spikes, state).

  • state_fallback (Callable[[torch.Tensor], Any]) – A function that can return a default state with the correct dimensions, in case no state is provided in the forward pass.

  • p (torch.nn.Module) – The neuron parameters as a torch Module, which allows the module to configure neuron parameters as optimizable.

  • dt (float) – Time step to use in integration. Defaults to 0.001.

  • activation_sparse (Optional[FeedforwardActivation]) – A Sparse activation function - if it exists for the neuron model

Initializes internal Module state, shared by both nn.Module and ScriptModule.

extra_repr()[source]

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.

Return type

str

forward(input_tensor, state=None)[source]

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.

training: bool
class norse.torch.module.snn.SNNRecurrent(activation, state_fallback, input_size, hidden_size, p, input_weights=None, recurrent_weights=None, autapses=False, dt=0.001, activation_sparse=None)[source]

Bases: torch.nn.modules.module.Module

The base module for recurrent spiking neural networks (RSNN) with time.

Parameters
  • activation (RecurrentActivation) – The activation function accepting an input tensor, state tensor, input weights, recurrent weights, and parameters module, and returning a tuple of (output spikes (one per timestep), state).

  • state_fallback (Callable[[torch.Tensor], torch.Tensor]) – A function that can return a default state with the correct dimensions, in case no state is provided in the forward pass.

  • input_size (int) – The number of input neurons

  • hidden_size (int) – The number of hidden neurons

  • p (torch.nn.Module) – The neuron parameters as a torch Module, which allows the module to configure neuron parameters as optimizable.

  • input_weights (torch.Tensor) – Weights used for input tensors. Defaults to a random matrix normalized to the number of hidden neurons.

  • recurrent_weights (torch.Tensor) – Weights used for input tensors. Defaults to a random matrix normalized to the number of hidden neurons.

  • autapses (bool) – Allow self-connections in the recurrence? Defaults to False. Will also remove autapses in custom recurrent weights, if set above.

  • dt (float) – Time step to use in integration. Defaults to 0.001.

  • activation_sparse (Optional[RecurrentActivation]) – A Sparse activation function - if it exists for the neuron model

Initializes internal Module state, shared by both nn.Module and ScriptModule.

extra_repr()[source]

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.

Return type

str

forward(input_tensor, state=None)[source]

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.

training: bool
class norse.torch.module.snn.SNNRecurrentCell(activation, state_fallback, input_size, hidden_size, p, input_weights=None, recurrent_weights=None, autapses=False, dt=0.001, activation_sparse=None)[source]

Bases: torch.nn.modules.module.Module

The base module for recurrent neuron cell without time.

Parameters
  • activation (RecurrentActivation) – The activation function accepting an input tensor, state tensor, input weights, recurrent weights, and parameters module, and returning a tuple of (output spikes (one per timestep), state).

  • state_fallback (Callable[[torch.Tensor], Any]) – A function that can return a default state with the correct dimensions, in case no state is provided in the forward pass.

  • input_size (int) – The number of input neurons

  • hidden_size (int) – The number of hidden neurons

  • p (torch.nn.Module) – The neuron parameters as a torch Module, which allows the module to configure neuron parameters as optimizable.

  • input_weights (torch.Tensor) – Weights used for input tensors. Defaults to a random matrix normalized to the number of hidden neurons.

  • recurrent_weights (torch.Tensor) – Weights used for input tensors. Defaults to a random matrix normalized to the number of hidden neurons.

  • autapses (bool) – Allow self-connections in the recurrence? Defaults to False. Will also remove autapses in custom recurrent weights, if set above.

  • dt (float) – Time step to use in integration. Defaults to 0.001.

  • activation_sparse (Optional[RecurrentActivation]) – A Sparse activation function - if it exists for the neuron model

Initializes internal Module state, shared by both nn.Module and ScriptModule.

extra_repr()[source]

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.

Return type

str

forward(input_tensor, state=None)[source]

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.

training: bool