warming up your workspace

Computational Neuroscience with Python

Learn Python through computational models of membranes, spikes, synapses, networks and decisions. Assemble a simulated spiking circuit with NumPy and examine what its outputs do and do not show.

11 projects, 275 hands-on levels, run in your browser.

Syllabus

  • Foundations: code through neuroscience: Never written code before? Start here. You will learn the basics of Python, output, variables, types, decisions, loops, and functions, through neurons, spikes, and firing rates. By the end you are ready for Project 1.
  • The Neuron as a Circuit: A neuron's membrane is a tiny electrical circuit: a capacitor (the lipid bilayer) in parallel with resistors (ion channels). Start from charge, capacitance, and Ohm's law, build the exponential dynamics that follow, then integrate them numerically to simulate a passive membrane responding to injected current. This is the foundation every neuron model is built on.
  • The Integrate-and-Fire Neuron: Add one rule to the passive membrane and it becomes a spiking neuron: when the voltage reaches a threshold, fire a spike and reset. The leaky integrate-and-fire (LIF) neuron is the workhorse of computational neuroscience. Build it, measure its firing-rate response to current (the F-I curve), add a refractory period, and quantify spike-train irregularity. Units here are mV, ms, nA, and megaohms, so R times I is a voltage in mV.
  • The Hodgkin-Huxley Neuron: Build the classical squid-axon model from voltage-dependent channel rates, gates and ionic currents. Advance all four state variables from the same old state, then inspect simulated spikes and firing responses. These are numerical model outputs, not measurements of living tissue.
  • Synapses: Build conductance-based synaptic currents, decaying gates, summed inputs and short-term resource dynamics. Separate the direction of voltage movement from the effect on spiking: inhibitory conductance may act by shunting, even without hyperpolarizing below rest.
  • Networks of Neurons: Represent connectivity with weight matrices and evolve recurrent firing-rate models. Measure population activity and E-I interactions while distinguishing finite-time diagnostics from mathematical guarantees of convergence or stability.
  • Plasticity and Learning: Implement Hebbian, Oja, STDP, covariance and BCM learning rules, then examine clipping, normalization and homeostatic updates. Finish with a sequential Oja learner and an explicit final normalization; convergence depends on inputs and step size.
  • Neural Coding: Measure firing rates, build tuning curves and encode stimuli with a population. Distinguish exact Poisson count sampling from the one-event-per-bin approximation used for binary spike trains, and quantify finite-sample variability.
  • Decoding and Information: Compare center-of-mass, direction-vector, likelihood and linear decoders. Make model assumptions explicit, measure information and discrimination, and fit a linear decoder on training counts before evaluating separate held-out responses.
  • Dynamics and Models: Study FitzHugh-Nagumo and Wilson-Cowan dynamics, synchronous Hopfield recall, and bounded noisy evidence accumulation. Use traces and diagnostics to distinguish a stable state from a cycle, and a completed decision from a timeout.
  • Capstone: A Spiking Circuit: Assemble a NumPy spiking circuit from vectorized LIF cells, decaying synaptic conductances, directed weights, tuned input and a count readout. Compare the zero-coupling baseline with a coupled circuit, then measure decoding error from the resulting spike raster.

Key concepts

  • Action potential: The spike: a fast, all-or-none ~100 mV swing produced by voltage-gated sodium and potassium channels, described by the Hodgkin-Huxley model.
  • Attractor network: A recurrent system with states or sets that nearby trajectories approach. Memory retrieval succeeds only when the initial state lies in a suitable attraction b…
  • Capacitance: Charge stored per voltage difference: Q=C*V. For fixed injected charge, smaller capacitance gives a larger voltage change. Whole-cell excitability also depends…
  • Coefficient of variation: The standard deviation of the inter-spike intervals divided by their mean. Near 0 for a clock-like neuron, near 1 for Poisson-irregular firing.
  • d-prime: A signal-detection measure of how separable two responses are: the difference of their means in units of noise standard deviation. Larger d-prime means easier…
  • Drift-diffusion model: A model of decision-making as noisy evidence accumulating over time until it reaches a bound. It captures both the choice made and the time it takes.
  • Driving force: How far the membrane is from a channel's reversal potential, V - E . The current through a channel is its conductance times this driving force, and it vani…
  • Entropy: The average uncertainty of a distribution, -sum p log2 p in bits. Largest when all outcomes are equally likely.
  • EPSP: Excitatory postsynaptic potential: the transient depolarization an excitatory synapse produces. Many EPSPs can sum in time and space to reach threshold.
  • Euler method: The simplest numerical integration: step a differential equation forward by value + dt * rate . The engine behind every simulation in this track.
  • Excitation-inhibition balance: Large excitatory and inhibitory inputs nearly cancel to leave a smaller net drive. This alone does not establish irregular spiking; network structure, dynamics…
  • F-I curve: The frequency-current curve: a neuron's firing rate as a function of input current. It has a rheobase (the smallest current that makes it fire) and a gain…
  • Fano factor: Count variance divided by count mean across repeated equal-duration trials. A positive-mean Poisson distribution has Fano factor 1; finite-sample estimates var…
  • Firing rate: Spikes per second (Hz), the most common neural code. Estimated by counting spikes in a window or smoothing the spike train with a kernel.
  • FitzHugh-Nagumo model: A two-variable reduction of the action potential, a fast voltage-like variable with a cubic nonlinearity and a slow recovery variable. Simple enough to study i…
  • Fixed point: A state where every time derivative, or every discrete update difference, is zero. Stability is a separate question: nearby states may approach or leave a fixe…
  • Gating variable: A number between 0 and 1 giving the fraction of a channel's gates that are open. It moves toward a voltage-dependent steady state x_inf with time constant…
  • Hebbian learning: Neurons that fire together wire together: a synapse strengthens in proportion to correlated pre- and post-synaptic activity, dw = eta * pre * post . Powerful b…
  • Hodgkin-Huxley model: Four coupled differential equations for membrane voltage and sodium activation m, sodium inactivation h, and potassium activation n. The classical parameters d…
  • Hopfield network: A recurrent binary-state memory with symmetric weights, often constructed from pattern outer products. Asynchronous single-unit updates with zero diagonal do n…
  • Integrate-and-fire: The workhorse spiking model: a leaky membrane that integrates its input until it reaches a threshold, then fires a spike and resets. Simple enough to analyze,…
  • Inter-spike interval: The time gap between consecutive spikes. Its distribution and variability characterize how regularly a neuron fires.
  • Leak conductance: The always-open channels that pull the membrane toward its leak reversal potential, modeled as I = g * (V - E) . They set the resting potential together with t…
  • Maximum-likelihood decoding: Choose the candidate stimulus with greatest probability for the observed data under a specified model. The lessons use independent Poisson counts; correctness…
  • Membrane potential: Voltage inside a cell relative to outside. These simplified models often start near -65 mV; some later models instead represent firing rates or dimensionless d…
  • Mutual information: How much knowing the neural response reduces uncertainty about the stimulus, in bits. Zero when response and stimulus are independent.
  • Nullcline: A curve in the phase plane where one variable stops changing. Where two nullclines cross is a fixed point of the system.
  • Oja's rule: A Hebbian update with activity-dependent weight decay. With suitable input statistics and small learning steps, it can approach a principal direction. A finite…
  • Phase plane: The plane of a two-variable system's state. Trajectories, nullclines, and fixed points in it reveal whether the system rests, spikes, or oscillates.
  • Poisson process: A continuous-time counting model with independent increments. At constant rate, counts have a Poisson distribution and waiting times are exponential. One-event…
  • Population code: Representing a stimulus in the joint activity of many tuned neurons. The stimulus is decoded from the bump of activity by center of mass, population vector, or…
  • Population vector: Sum preferred-direction unit vectors weighted by activity, then read the resulting angle. Zero total activity or exactly opposing vectors can leave the directi…
  • Refractory period: An absolute refractory interval holds a spiking model below threshold after a spike. With t_ref in milliseconds, 1000/t_ref Hz is an upper bound; recharging ad…
  • Resting potential: The steady membrane voltage with no input, where all the channel currents balance, near -65 mV in these models.
  • Reversal potential: Voltage E where a channel carries no net current. Outward-positive current is g*(V-E). Inhibition depends on spike threshold and shunting as well as whether th…
  • Short-term plasticity: Fast, reversible changes in synaptic strength with use: depression spends resources with each spike, facilitation raises release. Modeled with the Tsodyks-Mark…
  • Spike raster: A record of neuron events over time. This track stores rasters as a time-by-neuron matrix: rows are simulation steps, columns are neurons, and entries indicate…
  • STDP: Spike-timing-dependent plasticity: a synapse potentiates when the presynaptic spike comes shortly before the postsynaptic one, and depresses when the order is…
  • Summation: How a neuron adds its inputs: temporal summation combines inputs close in time, spatial summation combines inputs from different synapses arriving together.
  • Synapse: The connection between neurons: a presynaptic spike opens a conductance in the postsynaptic cell, pulling its voltage toward the synaptic reversal potential.
  • Synaptic plasticity: Lasting change in synaptic strength that underlies learning. Includes Hebbian learning, Oja's rule, and spike-timing-dependent plasticity.
  • Threshold: The voltage a neuron must reach to fire a spike, around -50 mV . In integrate-and-fire models, crossing it triggers a spike and a reset.
  • Time constant: tau = R * C , how fast the membrane responds. After one time constant a passive membrane has moved about 63% of the way to its steady state.
  • Tuning curve: A neuron's firing rate as a function of the stimulus, often a Gaussian or cosine bump peaked at its preferred stimulus.
  • Wilson-Cowan model: Coupled equations for the activity of an excitatory and an inhibitory population. Their feedback can settle to a steady state or break into oscillations.