↑↓ move↵ open[] previous / next lesson? all shortcuts
Appearance
Theme
Type size
Reading

Focus mode hides the sidebars. Press f to toggle it anywhere.

Keyboard shortcuts
/
Search
[ ]
Previous / next lesson
t
Jump to the table of contents
r
Review queue
f
Focus mode
?
This panel
ProjectTwo weekends$0Tier 0

Project A: Neurons from the equations up

Hodgkin–Huxley in Python from the four equations, then leaky integrate-and-fire, then Izhikevich, then a spiking network in Brian2. You heard a spike in Phase 1; now you make one.

AssumesWhat was that sound?Python for signalsSpineComputational neuroscience
On this pageTwo weekends
  1. Hodgkin–Huxley
  2. Leaky integrate-and-fire
  3. Izhikevich
  4. A network in Brian2

In 1952 Hodgkin and Huxley wrote down four differential equations for the squid axonA quantitative description of membrane current and its application to conduction and excitation in nerveHodgkin, Huxley · J. Physiol. · 1952The four equations behind every spiking model in Phase 4, still readable in the original. and integrated them by hand on a mechanical calculator, and out came the you heard from a cockroach leg. You can integrate them in twenty lines of Python and watch the same thing happen. Then you simplify them twice, to the models that networks are actually built from, and run a thousand neurons at once. The equations stop being symbols when you have watched them fire.

Hodgkin–Huxley
This interactive needs JavaScript. If you are reading a printout, the caption describes what it shows.
Figure 1. The model you are about to write, running live. Inject current and watch the membrane voltage and the three gating variables.
Try this
  1. Press the brief pulse. One , then rest. Look at the gates: m rises fast, h falls, n rises slowly.
  2. Raise the sustained current slowly. Below about 6 µA/cm² nothing; above it, a train of appears at a nonzero rate straight away. That jump is a property of this model.
  3. Raise it further. The rate rises, then the shrink, then they stop. Too much current holds the sodium channels inactivated.

Hodgkin–Huxley

Four state variables: the membrane voltage V and three gating variables m, h, n between 0 and 1, which are the fraction of sodium activation gates open, sodium inactivation gates open, and potassium gates open.

The current balance, with CC the membrane capacitance, II the injected current, and one leak term:

CdVdt=I−gNam3h (V−ENa)−gKn4 (V−EK)−gL (V−EL)C\frac{dV}{dt} = I - g_{Na}m^3h,(V-E_{Na}) - g_K n^4,(V-E_K) - g_L,(V-E_L)

Each gate relaxes toward a voltage-dependent open fraction:

dxdt=αx(V)(1−x)−βx(V)x\frac{dx}{dt} = \alpha_x(V)(1-x) - \beta_x(V)x

with α\alpha and β\beta the voltage-dependent opening and closing rates that Hodgkin and Huxley fit to their data. Each gate has a steady value and a time constant worth knowing when checking an implementation:

x∞(V)=αx(V)αx(V)+βx(V),τx(V)=1αx(V)+βx(V)x_\infty(V) = \frac{\alpha_x(V)}{\alpha_x(V)+\beta_x(V)}, \quad \tau_x(V) = \frac{1}{\alpha_x(V)+\beta_x(V)}

The squid parameters: gNa=120g_{Na} = 120, gK=36g_K = 36, gL=0.3 mS/cm2g_L = 0.3\ \text{mS/cm}^2; ENa=50E_{Na} = 50, EK=−77E_K = -77, EL=−54.4 mVE_L = -54.4\ \text{mV}; C=1 μF/cm2C = 1\ \mu\text{F/cm}^2. The rate functions are in every textbook and in the site’s widget source.

import numpy as np
def hh(I_ext, T=100.0, dt=0.01):
    gNa, gK, gL, ENa, EK, EL, C = 120., 36., 0.3, 50., -77., -54.4, 1.
    an = lambda v: 0.01*(v+55)/(1-np.exp(-(v+55)/10)); bn = lambda v: 0.125*np.exp(-(v+65)/80)
    am = lambda v: 0.1*(v+40)/(1-np.exp(-(v+40)/10));  bm = lambda v: 4*np.exp(-(v+65)/18)
    ah = lambda v: 0.07*np.exp(-(v+65)/20);            bh = lambda v: 1/(1+np.exp(-(v+35)/10))
    n_steps = int(T/dt); V = np.empty(n_steps)
    v, m, h, n = -65., 0.05, 0.6, 0.32
    for i in range(n_steps):
        I = I_ext(i*dt)
        dv = (I - gNa*m**3*h*(v-ENa) - gK*n**4*(v-EK) - gL*(v-EL)) / C
        m += dt*(am(v)*(1-m) - bm(v)*m); h += dt*(ah(v)*(1-h) - bh(v)*h); n += dt*(an(v)*(1-n) - bn(v)*n)
        v += dt*dv; V[i] = v
    return V

Forward Euler with a 0.01 ms step is fine here. Plot V for a 2 ms pulse of 30 µA/cm²: one . Plot the gates alongside and you have reproduced Figure 1.

Then the classic experiments. Sweep the sustained current and count per second: the frequency-current curve, with its jump at threshold. Deliver two pulses with a variable gap and find the shortest gap that produces a second : the . Block the potassium channels (set g_K to zero) and watch the fail to repolarize. Each is an afternoon and each is a figure for the build log.

Leaky integrate-and-fire

Throw away the gates. The membrane is a leaky capacitor:

τdVdt=−(V−EL)+RI\tau\frac{dV}{dt} = -(V-E_L) + RI

When VV crosses a threshold, record a and reset VV. Two lines of dynamics. It cannot produce a shape, but it captures when happen, which for networks is what matters, and it runs ten thousand times faster. Reproduce the f-I curve and compare its shape to ’s: the curve rises smoothly from zero, the curve jumps.

Izhikevich

Two equations with four parameters that, by choosing the parameters, reproduce twenty different firing patterns real neurons show: regular spiking, bursting, chattering, fast spiking.

dvdt=0.04v2+5v+140−u+I,dudt=a(bv−u)\frac{dv}{dt} = 0.04v^2 + 5v + 140 - u + I, \quad \frac{du}{dt} = a(bv-u)

On , v←cv \gets c and u←u+du \gets u+d. With a=0.02a = 0.02, b=0.2b = 0.2, c=−65c = -65, d=8d = 8 it is a regular-spiking cortical neuron. Change dd to 2 and cc to −55 and it bursts. Reproduce the figure from the 2003 paper with all twenty patterns; it is the single most educational plot in computational neuroscience.

A network in Brian2

lets you write the equations as strings and simulate thousands of neurons connected by . The classic first network: 4000 neurons, 80 percent excitatory and 20 percent inhibitory, randomly connected, driven by noise. Depending on the balance of excitation and inhibition it sits quietly, fires asynchronously, or falls into synchronized oscillations, and you can see population rhythms emerge from cells that individually have none. That emergence is where the oscillations explainer picks up.

from brian2 import *
eqs = 'dv/dt = (-(v - El) + I)/tau : volt (unless refractory)\nI : volt'
G = NeuronGroup(4000, eqs, threshold='v > -50*mV', reset='v = -65*mV', refractory=2*ms, method='euler')
  1. Implement and reproduce a single with gates. Save the figure.
  2. Sweep current for the f-I curve. Find the threshold current and the .
  3. Implement . Overlay its f-I curve on ’s.
  4. Implement Izhikevich and reproduce at least eight of the twenty firing patterns.
  5. Install and run the balanced random network. Vary the inhibitory weight and plot the population rate’s ; find the setting where an oscillation appears.
  6. Write the build log with all five figures.
Recall
What are the four state variables of the Hodgkin–Huxley model and what does each represent?
Membrane voltage V, and three gating variables: m (sodium activation), h (sodium inactivation), n (potassium activation), each the fraction of that gate type open.
Recall
What does the leaky integrate-and-fire model keep and throw away relative to Hodgkin–Huxley?
It keeps the membrane as a leaky capacitor and the timing of threshold crossings; it throws away the gating dynamics and therefore the spike shape and refractory mechanics.
Recall
Why is the Izhikevich model useful?
Two equations and four parameters reproduce most known cortical firing patterns at a tiny fraction of HH's cost, making large networks of realistic neurons feasible.