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 within the Integrator.

static aggregate(inputs: list[torch.Tensor], identifiers: list[str] = None) Tensor

Determines how presynaptic inputs from multiple sources should be aggregated.

By default, neurons sum their inputs. However, many use cases may require more sophistication. Shunting inhibition, for instance, can be expressed with torch.div (or torch.prod, if the source synapse is expected to send the inverse).

Parameters:
  • inputs (list of Tensor) – Input arriving at this layer, synaptic or external.

  • identifiers (list of str, optional) – Labels by which to micromanage input aggregation. Since some inputs may not be synaptic, users are responsible for passing identifiers in an order matching that of the input tensors.

Note

If your model requires identifier-dependent preprocessing of synaptic inputs to this neuron (e.g., a combination of addition and multiplication), it can be implemented by overriding this method.

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 derivative classes.

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 and encapsulate 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.