engine.neuron

Neurons are units that receive, integrate, and emit signals.

Neuron instance attributes are 1D tensors of arbitrary length, initialized with a single element by default.

Neurons maintain a numeric state akin to a membrane potential in the float32 tensor voltage, and sometimes a binary integer tensor spiked representing emitted action potential events.

All classes derived from Neuron must implement the parent forward() method.

class engine.neuron.Neuron(equation: Callable = None, integrator: Integrator = None, **kwargs)

Generic neuron base class.

Defines and initializes instance attributes shared by all neuron objects, over and above the universal specifications handled by the parent class Component.

Parameters:
  • equation (Callable or tuple, optional) –

    Anonymous function(s) specifying this neuron’s difference equation(s). Provided here since all neurons may utilize an explicit declaration of their update rule for numeric approximation purposes.

    This is strictly optional but necessary for utilizing Sapicore’s integrators. If provided, the lambda syntax should be used (lambda x, data: f(x, data)).

    If the Euler update rule is v[t+1] = v[t] + f(v[t])*DT, self.equation should be the f(v[t]) portion. This is because RK4 needs to compute f(v[t]) at different points, e.g. half a time step forward.

  • integrator (Integrator, optional) – Specifies an Integrator to be used when approximating the next value(s) of this neuron’s dynamic variable(s), e.g. voltage. Requires explicitly defining equation. Defaults to Runge-Kutta of order 4 to increase accuracy at a small performance penalty.

  • input (Tensor) – PyTorch registered buffer tracking the input current(s) received in this simulation step.

  • voltage (Tensor) – PyTorch registered buffer tracking the numeric state of the unit represented by this neuron instance, corresponding to a membrane voltage.

  • kwargs – Additional instance attributes that the user may set.

Warning

When defining equation for a custom neuron model, the present value of voltage should NOT be added to the right hand side. Do NOT multiply by DT. These operations will be performed as part of the generic Euler forward.

forward(data: Tensor) dict

Passes input through the neuron.

Parameters:

data (Tensor) – Input current whose value is used to compute the next value of the numeric state tensor voltage.

Returns:

A dictionary whose keys are loggable attributes and whose values are their states as of this time step. For potential use by a SimpleSimulator or any other Pipeline script handling runtime operations.

Return type:

dict

Raises:

NotImplementedError – The forward method must be implemented by each derived class.

inject(current: Tensor)

Injects a current into this neuron.

Parameters:

current (Tensor) – Float tensor containing value(s) to be added to this neuron’s voltage tensor.

integrate(**kwargs) Tensor

Generic support for numeric approximation.

This wrapper is meant to be called from within forward() in the voltage update step. Its purpose is to take the difference equation defining a neuron and approximate the voltage value at time t + DT. Keyword arguments should include variables that equation depends on. The argument x is the tensor’s state at time t, typically voltage.

See also

RungeKutta

property num_units

Number of functional units represented by this object.

Neurons are singletons by coercion, as they are meant to express unit dynamics. Derivatives of Ensemble can modify this property and duplicate units as necessary.

Modules

engine.neuron.analog

Analog neurons emit real numbers, usually onto static synapses.

engine.neuron.spiking

Spiking neurons emit all-or-none events once their numeric state surpasses a critical threshold.