Introduction to Spiking Neural Networks

A practical introduction to neurons, temporal computation, and learning for machine learning practitioners and software developers.

Abstract

An introduction to spiking neural networks for machine learning practitioners and software developers. Interactive demonstrations explore how a neuron accumulates input and fires, how synaptic weights combine inputs, and how supervised learning changes a small classifier. In one run, validation-selected held-out accuracy rose from 50% to 100% on 128 examples. A training replay highlights a short stretch of the full loss curve. The examples use a synthetic two-class task.

Introduction

A leaky integrate-and-fire neuron’s input current I(t)I(t) charges its membrane capacitance CmC_m. The membrane voltage VmV_m leaks towards rest ELE_L, with time constant τm\tau_m; tt is time.[1]

dVmdt=−Vm−ELτm+I(t)Cm(1)\frac{dV_m}{dt} = -\frac{V_m-E_L}{\tau_m}+\frac{I(t)}{C_m} \tag{1}

Each input pulse jj starts at tjt_j, supplies current IjI_j, and lasts one simulation timestep Δtsim\Delta t_{\mathrm{sim}}. Overlapping pulses add; between pulses the input current is zero.

I(t)=∑j: tj≤t<tj+ΔtsimIj(2)I(t)=\sum_{j:\,t_j\leq t<t_j+\Delta t_{\mathrm{sim}}} I_j \tag{2}

Reaching the firing threshold VthV_{\mathrm{th}} produces a spike.

Vm≥Vth  ⇒  spike(3)V_m\geq V_{\mathrm{th}}\;\Rightarrow\;\text{spike} \tag{3}

The voltage then returns immediately to the reset value VresetV_{\mathrm{reset}}.

Vm←Vreset(4)V_m\leftarrow V_{\mathrm{reset}} \tag{4}

Here, Cm=200C_m=200 pF and Δtsim=0.25\Delta t_{\mathrm{sim}}=0.25 ms. Rest and reset are −65 mV, and threshold is −50 mV. Currents are in nA, voltages in mV, and times in ms. There is no refractory period.

Figure 1: A simulated neuron receives current pulses. Blue shows its voltage; pink marks spikes and the firing threshold. Rest and reset are −65 mV (EL = Vreset); the threshold is −50 mV. Spike motion is illustrative.

Synapses

A synapse connects a presynaptic neuron to a postsynaptic neuron. Its weight sets how strongly an arriving spike affects the receiving neuron.[2] In this simplified current-based model, the inputs add:

I[k]=∑i=1Nwisi[k](5)I[k] = \sum_{i=1}^{N} w_i s_i[k] \tag{5}

NN is the number of presynaptic neurons; wiw_i is the current-pulse amplitude per spike from neuron ii, in nA. The spike count si[k]s_i[k] counts its arrivals during simulation step kk, usually 0 or 1. Multiple arrivals contribute separately. The sum I[k]I[k] is the total current applied throughout that step.

Three independent Poisson spike trains encode rates of 40, 30, and 20 Hz below. These are mean spikes per second, with random exponentially distributed waiting times.[3] Change a weight to change that connection’s contribution; zero removes it. Each arriving spike supplies a rectangular current pulse, without detailed biological synaptic dynamics.

Figure 2: Three random spike streams feed one simulated neuron. Thicker lines mean stronger connections. Blue shows voltage; pink marks spikes and the firing threshold. Rest and reset are −65 mV (EL = Vreset); the threshold is −50 mV. Spike motion is illustrative.

Results

Training

The classifier learns which of its first two inputs has the higher Poisson firing rate; a third supplies background spikes. We trained six nonnegative weights between three input channels and two spiking output neurons. Cross-entropy used their output spike counts. The forward pass retained the hard firing threshold; backpropagation used a smooth surrogate derivative to propagate learning signals through it.[4]

Training follows a loop: run the inputs forward, compare the output spike counts with the correct classes, calculate gradients, and update the weights. A gradient describes how a small weight change would affect the loss; it is a calculation, not a spike travelling backwards.

The animation uses a separate teaching run: 48 updates on the same batch of 128 training examples. The full graph shows the batch loss, while the network shows one example from that batch. Eight consecutive updates from the stretch with the largest loss decrease are replayed slowly. Weight changes and gradients are recorded; their motion is illustrative.

Forward spikesCalculate lossBackward gradientsUpdate weights
Weights (nA)
s1 → A—
s2 → A—
s3 → A—
s1 → B—
s2 → B—
s3 → B—
Figure 3: Recorded training on 128 examples. The graph shows all 48 updates; the shaded stretch is replayed slowly. Dots show spikes moving forward and gradients moving back; line thickness and numbers show the changing weights. The pink bar shows batch loss. Backward motion and weight transitions are illustrative.

Inference

Once trained, the classifier runs inputs forward with fixed weights to make a prediction. The output with more spikes wins; ties are assigned to Class A.

Training used 128 examples, with 64 separate validation examples selecting the checkpoint. On 128 held-out examples, accuracy increased from 50% to 100%. Toggle Before Training / After Training to compare the same recorded input. Before training, both outputs respond equally and fail to discriminate; training changes their relative responses. This is one training run on a synthetic task.

Figure 4: Recorded SNNLab responses to the same inputs before and after training. Thicker lines mean stronger connections; gauges show voltage and bars count spikes. Pink marks the firing threshold. Rest and reset are −65 mV (EL = Vreset); the threshold is −50 mV. Spike motion is illustrative.

Network diagrams

Three spike-input channels connect through six nonnegative synapses to two spiking output neurons.
Figure A1.

Circuit view rendered from the original compute’s saved classifier bundle. The teaching loop and validation-selected classifier share this architecture; their learned weights differ. The presentation reuses the original recordings.

Parameters

ParameterRecorded value
Network
Native parameter snapshotUnavailable
Input channelsUnavailable
PopulationsUnavailable
Membrane modelUnavailable
Neurons
Membrane capacitanceUnavailable
Leak conductanceUnavailable
Resting potentialUnavailable
Reset potentialUnavailable
ThresholdUnavailable
Refractory periodUnavailable
Membrane time constantUnavailable
Synapses and weights
Native synapse and weight parametersUnavailable
Input and simulation
Seed127
Timestep1 ms
Presentation duration200 ms
Training / validation / test samples128
Validation samples64
Held-out test samples128
Input encodingindependent Poisson counts in 1 ms bins, clipped to binary occupancy for SNNLab spike inputs
Rate patterns[[125,12.5,31.25],[12.5,125,31.25]] Hz
Rate jitter multipliers[0.85,1.15]
Checkpoint selectionminimum validation cross-entropy, earliest epoch on ties, including initial
Readouttotal output spike counts over 200 ms; ties choose class A
Replay selectionfirst held-out example of each class, independent of model responses
Training
Epochs24
Batch size64
Learning rate0.02
Surrogate slope1
Gradient clipping5
Teaching updates48
Teaching replay window8
Analysis
Selected epoch24
Decision minimum spikes / lead5 / 3
Teaching replay selectionConsecutive window with the greatest recorded batch-loss decrease
Table A1. Model parameters follow the selected presentation to its original compute's native snapshot; input and protocol settings come from that compute's recorded configuration. Paired neuron values follow E / I order. Missing snapshots or fields are unavailable. Historical figures retain their original evidence; current recipe defaults are never substituted.

Dataset

Upstream: —

Downstream: —

RunDateDurationSizeEvidenceStorageRan onVerification
exp127-r015-present<1s460.6 KBCurrentR2LocalLocal: absent; R2: catalog-verified
exp127-r013-analyse<1s44.5 KBCurrentR2LocalLocal: absent; R2: catalog-verified
exp127-r012-compute3s741.5 KBCurrentR2LocalLocal: absent; R2: catalog-verified

References

  1. W. Gerstner, W. M. Kistler, R. Naud, and L. Paninski. Neuronal Dynamics: From Single Neurons to Networks and Models of Cognition. Cambridge University Press (2014), §1.3, “Integrate-And-Fire Models.”
  2. W. Gerstner, W. M. Kistler, R. Naud, and L. Paninski. Neuronal Dynamics: From Single Neurons to Networks and Models of Cognition. Cambridge University Press (2014), §3.1, “Synapses.”
  3. W. Gerstner, W. M. Kistler, R. Naud, and L. Paninski. Neuronal Dynamics: From Single Neurons to Networks and Models of Cognition. Cambridge University Press (2014), §7.5, “Renewal statistics.”
  4. E. O. Neftci, H. Mostafa, and F. Zenke. “Surrogate Gradient Learning in Spiking Neural Networks.” arXiv (2019). arXiv:1901.09948