What you will learn
Implement and test LIF dynamics, then explain what richer models add and what they cost.
Before you begin: Biological neuroscience; Foundations: matter, mathematics & computation
START WITH A QUESTION
Picture this.
If a model looks like a neuron on a screen, is it correct? A smooth line can still come from a wrong equation. We will give our simulator a test with a known answer before asking it to produce spikes.
- Euler step
- A short update using the current rate of change.
- Convergence check
- Testing whether finer numerical resolution approaches a stable answer.
- Subthreshold
- Below the chosen spike-triggering threshold.
Read for the idea first. Work through the numbers next. Try answering the questions before opening the explanations.
Choose the simplest model that answers the question
A threshold unit asks whether a weighted sum crosses a boundary. An integrate-and-fire model adds an evolving state. A leaky integrate-and-fire model, or LIF, also lets that state relax toward a reference. More detailed models can include recovery variables or voltage-dependent ion conductances. These models answer different questions; they are not just levels in a competition for realism. For understanding accumulation over time, start with one passive voltage variable and test it carefully.
The next step is old value plus change
A derivative is a rate of change. Forward Euler freezes that rate briefly: V_next = V + dt × current slope. In the membrane equation, the leak term −(V−E) pulls toward E, and RI pushes toward a shifted equilibrium. Divide by τ to turn the displacement into a rate. If V = E = −65 mV, RI = 20 mV and dt/τ = 1/20, the first increment is 1 mV. The next increment is smaller because leakage has increased. Each step must use the old voltage on the right-hand side.
A benchmark you can calculate
For constant input beginning at E, the passive solution is V(t) = E + RI[1−exp(−t/τ)]. exp is the exponential function; here it describes the shrinking fraction of the initial gap. We use a subthreshold current of 0.1 nA below. The destination is −55 mV, and after 20 ms the exact value is about −58.679 mV. Compare numerical solutions at the same physical time with dt = 1 ms and dt = 0.5 ms. Comparing equal step counts would compare different durations.
Then add the event rules
The passive equation alone never generates a spike. A LIF simulator also needs a threshold, an event time convention, a reset value and any refractory rule. A simple discrete implementation updates voltage, checks whether it is at least the threshold, records a spike at the step end, then resets. This rounds crossing times to the grid. State that convention before comparing two simulators. The interactive model is useful for intuition; the passive reference test below isolates numerical accuracy from threshold and reset behavior.
SEE THE RELATIONSHIPS
From structure to behavior.
CHANGE A PARAMETER. TEST YOUR INTUITION.
A neuron as a leaky integrator
Hold current constant for 200 ms. The voltage leaks toward rest, rises with input, and resets after a threshold crossing. Values are a toy model, not fitted biology.
R = 100 MΩ; rest/reset = −65 mV; threshold = −50 mV; refractory period = 2 ms; Euler step = 0.1 ms. A threshold crossing is counted as a spike, without modelling its biological waveform.
Interactive controls load with JavaScript. The worked example below is available without it.
MAKE THE IDEA PRECISE
The mathematics.
| Symbol | Meaning |
|---|---|
| V, V_next | Current and next membrane potential, mV |
| dt, tau | Timestep and membrane time constant, ms |
| E | Leak reference potential, mV |
| R | Resistance, megaohms |
| I | Input current, nanoamps; R I is mV |
Build the equation, step by step
- Begin with τ dV/dt = −(V − E) + RI. The leak term pulls voltage toward E; the input term shifts the equilibrium to E + RI.
- Approximate dV/dt by (V_next − V)/dt, evaluate the right-hand side at the old voltage, and solve for V_next. This produces the explicit Euler update.
- Threshold and reset are additional rules, not consequences of that linear differential equation. For constant suprathreshold input, the first crossing time from E is −τ ln(1 − (V_threshold − E)/(RI)); this gives a numerical reference check.
WORK THROUGH THE NUMBERS
Worked example
For V = E = -65 mV, tau = 20 ms, dt = 1 ms, R = 100 megaohms and I = 0.2 nA, the first update is -64 mV. That is a numerical subthreshold step, not a full action-potential waveform.
A small Python experiment.
Python 3 · Standard library only · Synthetic educational example. Run this in your own notebook or a local file.
from math import exp
E, R, I, tau, duration = -65.0, 100.0, 0.1, 20.0, 20.0
def simulate(dt):
voltage = E
for _ in range(round(duration / dt)):
voltage += dt / tau * (-(voltage - E) + R * I)
return voltage
coarse = simulate(1.0)
fine = simulate(0.5)
exact = E + R * I * (1 - exp(-duration / tau))
print(f"dt 1.0 ms: {coarse:.3f} mV")
print(f"dt 0.5 ms: {fine:.3f} mV")
print(f"exact: {exact:.3f} mV")Read the code as a story
simulate keeps total duration fixed at 20 ms and changes how many steps fit into it. The function returns the final voltage, so we can compare coarse, fine and exact answers. The finer step should reduce error here; it need not make every complicated model accurate automatically. All voltage calculations use mV and all time calculations use ms consistently.
Expected output
dt 1.0 ms: -58.585 mV dt 0.5 ms: -58.632 mV exact: -58.679 mV
Change one quantity, predict the result, and then run the code again. Explain any difference before adding complexity.
Test your understanding.
Try it: Compute the second step by hand. Then halve dt while keeping total simulated time fixed.
Self-check: What happens if the time step is too large?
An explicit update can miss threshold timing and distort decay; sufficiently large steps can become unstable even when the continuous model is stable. Compare results after halving dt, and test a passive subthreshold trace against its analytic exponential solution before trusting spike counts.
Where this model stops: LIF omits detailed channel and dendritic dynamics. A one-step example does not establish numerical convergence.
A research question: Which behavior changes when you replace fixed-current synapses with conductance-based ones?
Record evidence in your mastery worksheet →PREDICT / TRY / EXPLAIN
Make accuracy visible
Use paper, a calculator or the Python example. Write your prediction before checking the result.
- Run both step sizes and subtract the exact answer from each numerical answer. Compare absolute errors.
- Add dt = 0.25 ms. Predict whether its error will be smaller, then test.
- Return to the original 0.2 nA example and calculate its first two 1 ms steps by hand. Do not confuse that current with the subthreshold benchmark's 0.1 nA.
Compare with a worked solution
At 0.1 nA the 1 ms estimate is about −58.585 mV and the 0.5 ms estimate about −58.632 mV; their errors are approximately 0.094 and 0.046 mV. A 0.25 ms step is closer again. For the separate 0.2 nA example, the first two steps are −64 and −63.05 mV. A smaller step improves this numerical approximation, not the biological completeness of LIF.
CLOSE YOUR NOTES
Can you explain it back?
These questions test the reasoning, not just a remembered phrase. Say your answer out loud or write a sentence first.
01Why does halving dt while keeping 20 steps fail to test the same endpoint?
Reveal the reasoning for question 1
It halves the total simulated time. To compare accuracy at 20 ms, use 20 one-millisecond steps or 40 half-millisecond steps.
02If the threshold is −50 mV and the passive destination is −55 mV, will constant input eventually trigger a spike from E?
Reveal the reasoning for question 2
No, under these deterministic passive dynamics starting at E. Voltage approaches −55 mV and stays below −50 mV. Noise or changing inputs would define a different experiment.
TAKE THE IDEA WITH YOU
Three things to remember.
- Test passive dynamics against an analytic reference first.
- Compare timestep refinements at equal physical times.
- Threshold, reset and refractory behavior are separate model rules.
A neuron simulation carries state. Next we connect states into a network and fill in the missing step between choosing weights and learning them.
Continue to Part 7 →THE NEXT LAYER
Chapter depth map.
This introduction provides a first model. The following chapters are outlines for deeper future editions; their full treatments have not yet been published.
From idealized units to dynamical neurons
6.1 Threshold units and integrators · Outline
- 6.1.1 McCulloch-Pitts logic and its biological limits
- 6.1.2 Integrate-and-fire state and threshold
- 6.1.3 Derive tau_m dV/dt = -(V - V_rest) + R I(t)
- 6.1.4 Meaning and units of every parameter
- 6.1.5 Constant-current solution and a worked voltage update
6.2 A reliable LIF simulator · Outline
- 6.2.1 Euler steps and analytic subthreshold comparison
- 6.2.2 Spike detection, reset and refractory periods
- 6.2.3 Synaptic currents, delays and noise
- 6.2.4 Timestep refinement and event-order conventions
- 6.2.5 Voltage traces, spike rasters and firing-rate curves
Model fidelity and scale
6.3 Beyond LIF · Outline
- 6.3.1 Izhikevich recovery variable and reset dynamics
- 6.3.2 Hodgkin-Huxley conductance and gating variables
- 6.3.3 Conductance-based synapses and reversal potentials
- 6.3.4 Parameter fitting and identifiability
- 6.3.5 Match model complexity to measurements
6.4 Simulating networks · Outline
- 6.4.1 One, ten, one hundred and one thousand cells
- 6.4.2 Sparse connectivity and event queues
- 6.4.3 Reproducibility, seeds and deterministic comparisons
- 6.4.4 Memory and throughput estimates for larger networks
- 6.4.5 Brian2 and NEST as tools to evaluate after the baseline
Read with the original sources.
These readings support the concepts and deeper investigation. The worked numbers and illustrations above are teaching examples.
Author-hosted textbook
Neuronal Dynamics — Gerstner, Kistler, Naud & Paninski (2014) ↗
Use for neuron-model prerequisites and notation; this site provides an original curriculum, not a reproduction of the textbook.
Primary paper
Hodgkin & Huxley (1952): membrane-current model ↗
A mechanistic modeling milestone. Read after RC circuits and differential equations; distinguish squid-axon measurements from universal neuron parameters.
Optional simulation tool
Brian 2 — official documentation ↗
Evaluate equation-oriented modeling after a small independent simulator. Availability of documentation does not establish compatibility with this website environment.
Optional simulation tool
NEST — official simulator documentation ↗
Evaluate for network simulation requirements. Pin the version and model semantics in a separate experiment environment.
Author-hosted textbook
Gerstner et al. — passive membrane and integrate-and-fire equations ↗
Reference for the passive-membrane approximation and integrate-and-fire conventions.