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 beside a resistor , driven by a current . The current splits two ways. Some charges the capacitor, , and some leaks through the resistor, , where is the voltage the membrane rests at when nothing drives it:
Multiply by and call the membrane time constant:
Read it as a rule for how the voltage moves. The term pulls back toward rest, harder the further away it is. The term pushes it toward . And sets how fast all of it happens. For a typical neuron is around 10 ms, long next to a 1 ms spike.
The exact solution
Switch on a constant current at time 0, with the membrane at rest. The voltage climbs toward and slows as it approaches:
After one time constant it has covered of the way; after three, 95%. Switch the current off and it falls back the same way, losing 63% of what is left every .
That is all the leaky membrane does, and it is why the neuron in chapter 1 forgot: whatever charge an input left decays as .
Taking steps
A computer advances time in steps of some . The question is what update rule gets from at one step to at the next.
If the current is constant over the step, the exact solution answers it. Starting from any , after :
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.
Compare the two by what they keep of the distance from the target each step. The exact rule keeps ; Euler keeps . For small steps they agree, since . For large ones they don’t. At , Euler keeps nothing and lands on the target in one step, where the true membrane has covered only 63% of the way. Past , Euler’s factor is negative and the voltage overshoots, flipping from one side of the target to the other. Past its size exceeds 1, and every step throws the voltage further away than the last.
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 , put rest at 0, and fold into a single input . The exact update becomes
which is chapter 1’s membrane. The factor that scaled the input is gone because the weights that produce learn whatever scale they need. In sparx, decay(tau) returns for a time constant in steps, and decay(tau, dt) gives 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 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 jaximport jax.numpy as jnpimport numpy as np
import sparxfrom 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 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, mV.
Try this
- Set the step equal to the time constant, 10 ms. How far off is Euler’s first value after the current turns on?
- Find the step size at which Euler’s values start to grow instead of settle. Why that value?
- Set the step to 4 ms. The exact update now shows an error too, but only around two moments. Which ones, and why?
- With ms, how small must the step be for Euler’s factor to be within 1% of the exact one?
Answers
- Euler jumps straight to the target, 1.2, in one step. The exact value after 10 ms is , so Euler is off by about 0.44, more than a third of the whole rise.
- At , 20 ms with . Euler’s factor then reaches , 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.
- 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.
- With , the ratio of Euler’s factor to the exact one is , which falls to 0.99 at : a step below about 2.7 ms.
Summary
A membrane is a capacitor with a leak, and its voltage relaxes toward with time constant . 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 , and diverges past . Dropping the units turns the exact step into the 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.