PySNN Documentation

pysnn.neuron

pysnn.neuron

The Neuron is the basic and most fundamental object that is used in constructing a spiking neural network (SNN). Each new neuron design should inherit from the BaseNeuron class. Each Neuron shares a set of basic functionalities/dynamics:

  • Internal (possibly decaying) voltage that represents recent incoming activity.

  • Spiking mechanism, once the voltage of the neuron surpasses its threshold value it will generate a Boolean spike.

  • Refractory period/mechanism that is activated once a Neuron has spiked. During this period the Neuron is incapable, or less likely, to spike again.

  • Trace that is a numerical representation of recent activity of the Neuron.

class pysnn.neuron.BaseInput(cells_shape, dt)

Simple feed-through layer of neurons used for generating a trace.

Parameters
  • cells_shape – a list or tuple that specifies the shape of the neurons in the conventional PyTorch format, but with the batch size as the first dimension.

  • dt – duration of a single timestep.

reset_state()

Reset cell states that accumulate over time during simulation.

no_grad()

Turn off gradient storing.

init_neuron()

Initialize state, and turn off gradients.

convert_input(x)

Convert torch.bool input to the datatype set for arithmetics.

Parameters

x – Input Tensor of torch.bool type.

forward(x)

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.

update_trace(x)

Placeholder for trace update function.

class pysnn.neuron.Input(cells_shape, dt, alpha_t, tau_t, update_type='linear')

Standard input neuron, used to propagate input traces to the following Connection object, and calculates a trace.

Parameters
  • cells_shape – a list or tuple that specifies the shape of the neurons in the conventional PyTorch format, but with the batch size as the first dimension.

  • dt – duration of a single timestep.

  • alpha_t – scaling constant for the increase of the trace by a single spike.

  • tau_t – decay parameter for the trace.

  • update_type – string, either 'linear' or 'exponential', default is 'linear'.

update_trace(x)

Converts input spikes and updates the trace.

Parameters

x – Tensor with the input spikes.

forward(x)

Propagate spikes through input neurons and compute trace.

Parameters

x – Input spikes

class pysnn.neuron.BaseNeuron(cells_shape, thresh, v_rest, alpha_v, alpha_t, dt, duration_refrac, store_trace=False)

Base neuron model, is a container to define basic neuron functionalties.

Defines basic spiking, voltage and trace characteristics. Just has to adhere to the API functionalities to integrate within Connection modules.

Make sure the Neuron class receives input voltage for each neuron and returns a Tensor indicating which neurons have spiked.

Parameters
  • cells_shape – a list or tuple that specifies the shape of the neurons in the conventional PyTorch format, but with the batch size as the first dimension.

  • thresh – spiking threshold, when the cells’ voltage surpasses this value it generates a spike.

  • v_rest – voltage resting value, the Neuron will default back to this over time or after spiking.

  • alpha_v – scaling constant for the increase of the voltage by a single spike.

  • alpha_t – scaling constant for the increase of the trace by a single spike.

  • dt – duration of a single timestep.

  • duration_refrac – Number of timesteps the Neuron is dormant after spiking. Make sure dt fits an integer number of times in duration refrac.

  • update_type – string, either 'linear' or 'exponential', default is 'linear'.

  • store_traceBoolean flag to store the complete spiking history, defaults to False.

spiking()

Return cells that are in spiking state.

refrac(spikes)

Basic counting version of cell refractory period.

Can be overwritten in case of the need of more refined functionality.

concat_trace(x)

Concatenate most recent timestep to the trace storage.

fold(x)

Fold incoming spike train by summing last dimension.

unfold(x)

Move the last dimension (all incoming to single neuron in current layer) to first dim.

This is done because PyTorch broadcasting does not support broadcasting over the last dim.

convert_spikes(spikes)

Cast torch.bool spikes to datatype that is used for voltage and weights

reset_state()

Reset cell states that accumulate over time during simulation.

reset_thresh()

Reset threshold to initialization values, allows for different standard thresholds per neuron.

no_grad()

Turn off learning and gradient storing.

init_neuron()

Initialize state, parameters, and turn off gradients.

forward(x)

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.

update_trace(x)

Placeholder for trace update function.

update_voltage(x)

Placeholder for voltage update function.

class pysnn.neuron.IFNeuron(cells_shape, thresh, v_rest, alpha_v, alpha_t, dt, duration_refrac, tau_t, update_type='linear', store_trace=False)

Basic integrate and fire neuron, cell voltage does not decay over time.

Parameters
  • cells_shape – a list or tuple that specifies the shape of the neurons in the conventional PyTorch format, but with the batch size as the first dimension.

  • thresh – spiking threshold, when the cells’ voltage surpasses this value it generates a spike.

  • v_rest – voltage resting value, the Neuron will default back to this over time or after spiking.

  • alpha_v – scaling constant for the increase of the voltage by a single spike.

  • alpha_t – scaling constant for the increase of the trace by a single spike.

  • dt – duration of a single timestep.

  • duration_refrac – Number of timesteps the Neuron is dormant after spiking. Make sure dt fits an integer number of times in duration refrac.

  • tau_t – decay parameter for the trace.

  • update_type – string, either 'linear' or 'exponential', default is 'linear'.

  • store_traceBoolean flag to store the complete spiking history, defaults to False.

update_trace(x)
Parameters

x – Incoming/presynaptic spikes

update_voltage(x)
Parameters

x – Incoming/presynaptic spikes

forward(x)
Parameters

x – Incoming/presynaptic spikes

Returns

Neuron output spikes and trace

class pysnn.neuron.LIFNeuron(cells_shape, thresh, v_rest, alpha_v, alpha_t, dt, duration_refrac, tau_v, tau_t, update_type='linear', store_trace=False)

Leaky integrate and fire neuron, cell voltage decays over time.

Parameters
  • cells_shape – a list or tuple that specifies the shape of the neurons in the conventional PyTorch format, but with the batch size as the first dimension.

  • thresh – spiking threshold, when the cells’ voltage surpasses this value it generates a spike.

  • v_rest – voltage resting value, the Neuron will default back to this over time or after spiking.

  • alpha_v – scaling constant for the increase of the voltage by a single spike.

  • alpha_t – scaling constant for the increase of the trace by a single spike.

  • dt – duration of a single timestep.

  • duration_refrac – Number of timesteps the Neuron is dormant after spiking. Make sure dt fits an integer number of times in duration refrac.

  • tau_v – decay parameter for the voltage.

  • tau_t – decay parameter for the trace.

  • update_type – string, either 'linear' or 'exponential', default is 'linear'.

  • store_traceBoolean flag to store the complete spiking history, defaults to False.

update_trace(x)
Parameters

x – Incoming/presynaptic spikes

update_voltage(x)
Parameters

x – Incoming/presynaptic spikes

forward(x)
Parameters

x – Incoming/presynaptic spikes

Returns

Neuron output spikes and trace

class pysnn.neuron.AdaptiveLIFNeuron(cells_shape, thresh, v_rest, alpha_v, alpha_t, dt, duration_refrac, tau_v, tau_t, alpha_thresh, tau_thresh, update_type='linear', store_trace=False)

Adaptive leaky integrate and fire neuron.

The cell voltage decays over time, the spiking threshold adapts based on the recent spiking activity of the Neuron.

Parameters
  • cells_shape – a list or tuple that specifies the shape of the neurons in the conventional PyTorch format, but with the batch size as the first dimension.

  • thresh – spiking threshold, when the cells’ voltage surpasses this value it generates a spike.

  • v_rest – voltage resting value, the Neuron will default back to this over time or after spiking.

  • alpha_v – scaling constant for the increase of the voltage by a single spike.

  • alpha_t – scaling constant for the increase of the trace by a single spike.

  • dt – duration of a single timestep.

  • duration_refrac – Number of timesteps the Neuron is dormant after spiking. Make sure dt fits an integer number of times in duration refrac.

  • tau_v – decay parameter for the voltage.

  • tau_t – decay parameter for the trace.

  • alpha_thresh – scaling constant for the increase of the threshold by a single spike.

  • tau_thresh – decay parameter for the threshold.

  • update_type – string, either 'linear' or 'exponential', default is 'linear'.

  • store_traceBoolean flag to store the complete spiking history, defaults to False.

update_trace(x)
Parameters

x – Incoming/presynaptic spikes

update_thresh(x)
Parameters

x – Incoming/presynaptic spikes

update_voltage(x)
Parameters

x – Incoming/presynaptic spikes

forward(x)
Parameters

x – Incoming/presynaptic spikes

Returns

Neuron output spikes and trace

reset_state()

Reset cell states that accumulate over time during simulation.

class pysnn.neuron.FedeNeuron(cells_shape, thresh, v_rest, alpha_v, alpha_t, dt, duration_refrac, tau_v, tau_t, store_trace=False)

Leaky Integrate and Fire neuron.

Defined in “Unsupervised Learning of a Hierarchical Spiking Neural Network for Optical Flow Estimation: From Events to Global Motion Perception - F.P. Valles, et al.”

Parameters
  • cells_shape – a list or tuple that specifies the shape of the neurons in the conventional PyTorch format, but with the batch size as the first dimension.

  • thresh – spiking threshold, when the cells’ voltage surpasses this value it generates a spike.

  • v_rest – voltage resting value, the Neuron will default back to this over time or after spiking.

  • alpha_v – scaling constant for the increase of the voltage by a single spike.

  • alpha_t – scaling constant for the increase of the trace by a single spike.

  • dt – duration of a single timestep.

  • duration_refrac – Number of timesteps the Neuron is dormant after spiking. Make sure dt fits an integer number of times in duration refrac.

  • tau_v – decay parameter for the voltage.

  • tau_t – decay parameter for the trace.

  • store_traceBoolean flag to store the complete spiking history, defaults to False.

update_trace(x)
Parameters

x – Incoming/presynaptic spikes

update_voltage(x, pre_trace)
Parameters
  • x – Incoming/presynaptic spikes

  • pre_trace – Incoming/presynaptic trace

forward(x, pre_trace)
Parameters
  • x – Incoming/presynaptic spikes

  • pre_trace – Incoming/presynaptic trace

Returns

Neuron output spikes and trace