Skip to content
GitHub

Chapter 2 · Neurons

Membranes and time constants

Chapter 1's neuron forgot its input at a rate set by a number called the time constant. This chapter derives that rate from the cell membrane itself, solves the equation exactly, and shows what happens when a computer approximates it in steps.

A membrane is a capacitor with a leak

A neuron’s membrane is a thin layer of fat that separates two salty solutions. Fat does not conduct, so the membrane holds charge on its two faces the way a capacitor does: push current in and the voltage across it rises. Scattered through the membrane are ion channels, small pores that let charge trickle back out. They act as a resistor in parallel with the capacitor.

So the simplest electrical model of a patch of membrane is a capacitor CC beside a resistor RR, driven by a current I(t)I(t). The current splits two ways. Some charges the capacitor, C dv/dtC\,\mathrm{d}v/\mathrm{d}t, and some leaks through the resistor, (v−EL)/R(v - E_L)/R, where ELE_L is the voltage the membrane rests at when nothing drives it:

I(t)=v(t)−ELR+C dvdtI(t) = \frac{v(t) - E_L}{R} + C\,\frac{\mathrm{d}v}{\mathrm{d}t}

Multiply by RR and call τ=RC\tau = RC the membrane time constant:

τ dvdt=−(v(t)−EL)+R I(t)\tau\,\frac{\mathrm{d}v}{\mathrm{d}t} = -\big(v(t) - E_L\big) + R\,I(t)

Read it as a rule for how the voltage moves. The term −(v−EL)-(v - E_L) pulls vv back toward rest, harder the further away it is. The term R IR\,I pushes it toward EL+R IE_L + R\,I. And τ\tau sets how fast all of it happens. For a typical neuron τ\tau is around 10 ms, long next to a 1 ms spike.

The exact solution

Switch on a constant current I0I_0 at time 0, with the membrane at rest. The voltage climbs toward EL+RI0E_L + R I_0 and slows as it approaches:

v(t)=EL+R I0(1−e−t/τ)v(t) = E_L + R\,I_0\left(1 - e^{-t/\tau}\right)

After one time constant it has covered 1−e−1≈63%1 - e^{-1} \approx 63\% of the way; after three, 95%. Switch the current off and it falls back the same way, losing 63% of what is left every τ\tau.

That is all the leaky membrane does, and it is why the neuron in chapter 1 forgot: whatever charge an input left decays as e−t/τe^{-t/\tau}.

Taking steps

A computer advances time in steps of some Δt\Delta t. The question is what update rule gets from vv at one step to vv at the next.

If the current is constant over the step, the exact solution answers it. Starting from any vv, after Δt\Delta t:

v←EL+(v−EL) e−Δt/τ+R I(1−e−Δt/τ)v \leftarrow E_L + (v - E_L)\,e^{-\Delta t/\tau} + R\,I\left(1 - e^{-\Delta t/\tau}\right)

This is exact for any step size, small or large, as long as the current really is constant within each step. sparx’s physical neurons step this way, as NEST’s do.

The more obvious rule is Euler’s: take the slope at the start of the step and follow it in a straight line.

v←v+Δtτ(−(v−EL)+R I)v \leftarrow v + \frac{\Delta t}{\tau}\big(-(v - E_L) + R\,I\big)

Compare the two by what they keep of the distance from the target each step. The exact rule keeps e−Δt/τe^{-\Delta t/\tau}; Euler keeps 1−Δt/τ1 - \Delta t/\tau. For small steps they agree, since e−x≈1−xe^{-x} \approx 1 - x. For large ones they don’t. At Δt=τ\Delta t = \tau, Euler keeps nothing and lands on the target in one step, where the true membrane has covered only 63% of the way. Past Δt=τ\Delta t = \tau, Euler’s factor is negative and the voltage overshoots, flipping from one side of the target to the other. Past 2τ2\tau its size exceeds 1, and every step throws the voltage further away than the last.

exact vs Euler

The grey curve is the exact solution, the blue dots the exact update at each step, and the orange squares Euler’s. The shaded band is when the current is on. Push the step up and watch Euler fall behind, overshoot, and finally blow up.

The form spiking networks use

Machine learning networks drop the units. Measure time in steps, so Δt=1\Delta t = 1, put rest at 0, and fold R I(1−e−1/τ)R\,I(1 - e^{-1/\tau}) into a single input xx. The exact update becomes

v←β v+x,β=e−1/τv \leftarrow \beta\,v + x, \qquad \beta = e^{-1/\tau}

which is chapter 1’s membrane. The factor 1−β1 - \beta that scaled the input is gone because the weights that produce xx learn whatever scale they need. In sparx, decay(tau) returns β\beta for a time constant in steps, and decay(tau, dt) gives e−Δt/τe^{-\Delta t/\tau} for a time constant and step in the same unit.

The sparx way

LeakyIntegrateAndFire takes its parameters in ms, pF and mV, and its input current in pA. With a 20 ms time constant and 200 pF, its leak conductance is 10 nS, so 150 pA should lift the membrane 150 pA/10 nS=15150\text{ pA} / 10\text{ nS} = 15 mV above rest. Run the same 120 ms at steps of 0.1 ms and of 5 ms, and compare the two at the instants they share:

import jax
import jax.numpy as jnp
import numpy as np
import sparx
from sparx.dynamics import LeakyIntegrateAndFire, SynapticInput
jax.config.update("jax_enable_x64", True)
# 20 ms and 200 pF give a leak of 10 nS; the threshold is out of
# reach, so the membrane only charges and leaks.
cell = LeakyIntegrateAndFire(tau_m=20.0, c_m=200.0, e_l=-60.0,
v_th=0.0)
def charge(dt):
"""The membrane over 120 ms with 150 pA from 10 ms to 70 ms."""
k = jnp.arange(round(120 / dt))
on = (k >= round(10 / dt)) & (k < round(70 / dt))
current = jnp.where(on, 150.0, 0.0)
_, v = sparx.run(cell, SynapticInput(current), dt=dt,
record=lambda s: s.v)[0]
return np.asarray(v)
fine, coarse = charge(0.1), charge(5.0)
# The same instants: every 50th fine step is a coarse step.
print(np.abs(fine[49::50] - coarse).max(), "mV apart")
print(coarse[13], "mV at 70 ms; the exact value is",
-60 + 15 * (1 - np.exp(-60 / 20)))

The two runs agree to within 3×10−143 \times 10^{-14} mV, rounding error in float64, because the current switches on and off exactly on a 5 ms boundary. Fifty steps of 0.1 ms land where one step of 5 ms does. The value at 70 ms is the exact solution’s, −60+15(1−e−3)≈−45.75-60 + 15(1 - e^{-3}) \approx -45.75 mV.

Try this

  1. Set the step equal to the time constant, 10 ms. How far off is Euler’s first value after the current turns on?
  2. Find the step size at which Euler’s values start to grow instead of settle. Why that value?
  3. Set the step to 4 ms. The exact update now shows an error too, but only around two moments. Which ones, and why?
  4. With τ=20\tau = 20 ms, how small must the step be for Euler’s factor to be within 1% of the exact one?
Answers
  1. Euler jumps straight to the target, 1.2, in one step. The exact value after 10 ms is 1.2(1−e−1)≈0.761.2(1 - e^{-1}) \approx 0.76, so Euler is off by about 0.44, more than a third of the whole rise.
  2. At Δt=2τ\Delta t = 2\tau, 20 ms with τ=10\tau = 10. Euler’s factor 1−Δt/τ1 - \Delta t/\tau then reaches −1-1, so each step flips the distance from the target without shrinking it. Beyond that, the size of the factor exceeds 1 and the error grows.
  3. The current switches on at 10 ms and off at 70 ms, and with a 4 ms step neither falls on a step boundary. The stepped model reads the current at the start of each step, so it switches on at 12 ms and off at 72 ms. The exact update is exact for the input it is given; the input itself moved. A real simulation has the same issue with spikes that arrive between steps.
  4. With x=Δt/τx = \Delta t/\tau, the ratio of Euler’s factor to the exact one is (1−x) ex(1 - x)\,e^{x}, which falls to 0.99 at x≈0.135x \approx 0.135: a step below about 2.7 ms.

Summary

A membrane is a capacitor with a leak, and its voltage relaxes toward EL+R IE_L + R\,I with time constant τ=RC\tau = RC. With the current held constant over each step, that relaxation can be stepped exactly at any step size; Euler’s straight-line step drifts, overshoots past Δt=τ\Delta t = \tau, and diverges past 2τ2\tau. Dropping the units turns the exact step into the v←βv+xv \leftarrow \beta v + x of every spiking network. The next chapter adds the threshold back and asks how fast a neuron fires.

References

  • W. Gerstner, W. M. Kistler, R. Naud and L. Paninski, Neuronal Dynamics, section 1.3, Cambridge University Press, 2014, doi:10.1017/CBO9781107447615. Equations 1.3 to 1.7 and the typical time constant.
  • S. Rotter and M. Diesmann, “Exact digital simulation of time-invariant linear systems with applications to neuronal modeling”, Biological Cybernetics 81, 1999, doi:10.1007/s004220050570. The exact update NEST and sparx use, extended to synaptic currents.