PySNN Documentation

pysnn.connection

pysnn.connection

A Connection object is used to pass spikes, activations, and traces between two sets of BaseNeuron objects. The Connection is the base class that should be inherited by each custom connection. Each Connection shares a set of basic functionalities/dynamics:

  • Presynaptic Neuron, which is the Neuron that precedes the Connection.

  • Postsynaptic Neuron, which is the Neuron that succedes the Connection.

  • Delay in the transmission of incoming signals from its presynaptic Neuron to its postsynaptic Neuron.

  • Weights, which are the relative weights that are assigned from spikes originating from each presynaptic Neuron.

  • Signals from the presynaptic Neuron that are passed on by the Connection, which are the following
    • Traces

    • Spikes

    • Activation potential, this is not actually an input but a result of multiplying incoming spikes with the connection weight.

class pysnn.connection.Connection(shape, dt, delay)

Base class for defining SNN connection/layer.

This object connects layers of neurons, it also contains the synaptic weights.

convert_spikes(x)

Convert input from Byte Tensor to same data type as the weights.

no_grad()

Set require_gradients to False and turn off training mode.

reset_state()

Set state Parameters (e.g. trace) to their resting state.

reset_weights(distribution='uniform', gain=1.0, a=0.0, b=1.0)

Reinnitialize network weights.

Note: Not all parameters apply to every distribution.

Parameters
  • distribution – Distribution used for initialization

  • gain – Scalar increase of the weight values.

  • a – Lower bound.

  • b – Upper bound.

init_connection()

Collection of all intialization methods.

Assumes weights are implemented by the class that inherits from this base class.

propagate_spike(x)

Track propagation of spikes through synapses if the connection.

class pysnn.connection.Linear(in_features, out_features, batch_size, dt, delay)

SNN linear (fully connected) layer with interface comparable to torch.nn.Linear.

Parameters
  • in_features – Size of each input sample.

  • out_features – Size of each output sample.

  • batch_size – Number of samples in a batch.

  • dt – Duration of each timestep.

  • delay – Time it takes for a spike to propagate through the connection. Should be an integer multiple of dt.

activation_potential(x)

Determine activation potentials from each synapse for current time step.

Parameters

x – Presynaptic spikes.

Returns

Activation potentials.

forward(x, trace_in)

Calculate postsynaptic activation potentials and trace.

Parameters
  • x – Presynaptic spikes.

  • trace_in – Presynaptic trace.

Returns

(Activation potentials, Postsynaptic trace)

class pysnn.connection.Conv2d(in_channels, out_channels, kernel_size, im_dims, batch_size, dt, delay, stride=1, padding=0, dilation=1)

Convolutional SNN layer interface comparable to torch.nn.Conv2d.

Param

Number of channels in the input image.

Parameters
  • out_channels – Number of channels produced by the convolution

  • kernel_size – Size of the convolving kernel

  • im_dims – (Height, Width) of the input image.

  • batch_size – Number of samples in a batch.

  • dt – Duration of each timestep.

  • delay – Time it takes for a spike to propagate through the connection. Should be an integer multiple of dt.

  • stride – Stride of the convolution. Default: 1

  • padding – Zero-padding added to both sides of the input. Default: 0

  • dilation – Spacing between kernel elements. Default: 1

activation_potential(x)

Determine activation potentials from each synapse for current time step.

Parameters

x – Presynaptic spikes.

Returns

Activation potentials.

forward(x, trace_in)

Calculate postsynaptic activation potentials and trace.

Parameters
  • x – Presynaptic spikes.

  • trace_in – Presynaptic trace.

Returns

(Activation potentials, Postsynaptic trace)

class pysnn.connection.MaxPool2d(kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False)

Simple port of PyTorch MaxPool2d with small adjustment for spiking operations.

Currently pooling only supports operations on floating point numbers, thus it casts the uint8 spikes to floats back and forth. The trace of the ‘maximum’ spike is also returned. In case of multiple spikes within pooling window, returns first spike of the window (top left corner).

forward(x, trace)

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.

class pysnn.connection.AdaptiveMaxPool2d(output_size)

Simple port of PyTorch AdaptiveMaxPool2d with small adjustment for spiking operations.

Currently pooling only supports operations on floating point numbers, thus it casts the uint8 spikes to floats back and forth. The trace of the ‘maximum’ spike is also returned. In case of multiple spikes within pooling window, returns first spike of the window (top left corner).

forward(x, trace)

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.