SpikingLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Represents a layer of spiking neurons that model the biological dynamics of neural activity.

Inheritance: LayerBase<T> → SpikingLayer<T>

Implements: IShapeContract

For Beginners

This layer mimics how real neurons in the brain work, using “spikes” instead of smooth values.

Think of each neuron as a tiny battery that:

  • Builds up electrical charge over time (membrane potential)
  • Fires a signal (spike) when the charge reaches a threshold
  • Needs a short recovery period after firing (refractory period)
  • Has different ways of charging and discharging (different neuron models)

Benefits include:

  • More biologically realistic modeling of neural activity
  • Potential for energy-efficient computation (spikes are sparse)
  • Ability to process time-dependent information naturally

For example, spiking neurons can directly model the timing patterns in speech or detect motion in video by responding to when things change rather than constantly processing every value.

How It Works

A spiking layer implements various biologically-inspired neuron models that operate with discrete spike events rather than continuous activation values. The layer supports several neuron types including Leaky Integrate-and-Fire, Izhikevich, Adaptive Exponential, and Hodgkin-Huxley models. Spiking neurons are characterized by their membrane potential dynamics, threshold-crossing spike generation, and refractory periods after firing.

Constructors

Constructor Summary
SpikingLayer(int inputSize, int outputSize, SpikingNeuronType neuronType, double tau, double refractoryPeriod) Initializes a new instance of the SpikingLayer class with the specified dimensions and neuron type.

Properties

Property Summary
bool SupportsTraining { get; } Gets a value indicating whether this layer supports training through backpropagation.

Methods

Method Summary
Dictionary<string, string> GetParameterRoles() Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases).
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
IReadOnlyList<Tensor<T>> GetTrainableParameters() Returns all trainable parameter tensors marked with [TrainableParameter].
IReadOnlyList<ValueTuple<string, Tensor<T>>> GetRegisteredBuffers()
void ClearGradients()
void ResetState() Resets the internal state of the spiking layer.
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) Replaces trainable parameter tensors (e.g., with ParameterBuffer views).
void UpdateParameters(T learningRate) Updates the parameters of the layer using the calculated gradients and learning rate.
void UpdateParameters(Vector<T> parameters) Updates the parameters of the layer using the calculated gradients and learning rate.
void ZeroGrad() Clears all gradient fields discovered by convention ({paramName}Gradient).