Record a few dozen neurons during a reach and every trace looks different. Treat the whole population as one point, and that point turns in a clean loop.
Learn what a population state space is, how PCA finds the flat sheet the activity lives on, and how jPCA finds the rotation that motor cortex uses to run a reach.
Press Play, then slide through the eight reach directions. The traces on the left disagree with each other. The point on the right turns the same way every time. Then we build, piece by piece, the state space, the PCA that finds the plane, and the jPCA that finds the rotation.
You need what a firing rate is (spikes per second) and what an average is. We build the rest from zero: axes, variance, eigenvalues and rotations.
Lesson 5 of the series Brain-Computer Interfaces, from the spike to the foundation model. Built from the primary papers: Churchland et al., Neural population dynamics during reaching (Nature, 2012), and Shenoy, Sahani and Churchland, Cortical control of arm movements: a dynamical systems perspective (Annual Review of Neuroscience, 2013). Follow-along reading: Princeton NEU 560, taught by Jonathan Pillow. Every idea is re-taught here in our own words and devices.
Illustrative: a made-up population of 24 neurons, built so that most of its activity is one rotation at 2 Hz that fades with a time constant of 0.6 s (the start angle depends on the reach), plus a slower 0.8 Hz wheel, a shared bump and no noise. The plane is the real first two principal components of this data after the average across reaches is removed, computed live. Real recordings are noisier and, in Churchland et al., the rotation lasted about 1 to 1.5 cycles at up to about 2.5 Hz.
Chapter 0
See why single neurons in motor cortex look like noise, and why the crowd they belong to does not
A monkey reaches for a dot on a screen. Under its skull, a small grid of 96 electrodes listens to motor cortex, the strip of brain that sends the commands that move the arm. Each electrode hears one or more neurons: cells that talk by sending brief electrical pulses called spikes (our spike lesson builds one from zero).
A neuron's firing rate is how many spikes it sends each second. A rate of 40 spikes per second means a spike about every 25 ms. A researcher counts spikes in short windows, say 10 ms, and plots the rate against time. That plot is one neuron's story of one reach.
A quick example makes the unit concrete. Say the electrode counts 4 spikes from one neuron in a 100 ms window. That is 4 spikes in a tenth of a second, so the rate is 40 spikes per second. Slide the window along the recording in 10 ms steps and you get a rate for every step. Our devices use 65 such steps, which cover 0.64 s of one reach.
Now ask the obvious question. What does this neuron do when the monkey reaches? If the answer were simple, a brain-computer interface would be simple. You would find the neuron that means "left", read it, and move the cursor left.
For decades the standard answer was tuning. A motor cortex neuron fires most for one reach direction, its preferred direction, and less as the reach turns away. A crowd of such neurons can then vote on the direction, and a decoder can read the vote. Shenoy, Sahani and Churchland describe this as the two classic approaches: explain each neuron by what it is tuned to, then decode movement from many tuned neurons.
That story has real successes. It also strains when you look closely at one neuron over time. Churchland and colleagues recorded from motor and premotor cortex of four monkeys: 469 single-neuron recordings, plus 364 neurons recorded together on two 96-electrode arrays. Their summary of what single neurons did is blunt: responses were typically "complex, multiphasic and heterogeneous".
Three words, three problems. Complex: the rate does not just rise and fall once. Multiphasic: it rises, drops, then rises again. Heterogeneous: its neighbour does something else entirely. Try it on the made-up population below. It is built to behave this way, so you can see the trouble without a lab.
Each blue line is one neuron's firing rate during one of eight reaches. Pick a neuron. Look for a pattern that tells you the reach, or the time, from this neuron alone.
Illustrative: 24 made-up neurons (not recorded data), 8 reaches, 65 time bins of 10 ms, no noise. The peak times are computed live from the lines you see. Real neurons add spike noise on top of this.
No neuron gives you a clean rule. The same neuron peaks early in one reach and late in another. A neighbour does the opposite. If you read one neuron at a time, you must explain each of them separately, and the explanations do not add up to a theory.
Here is the idea of this lesson. Stop asking what one neuron means. Ask what the whole population is doing. List the firing rate of every neuron at one instant. That list is one object: a single point, with one coordinate per neuron. A moment later you have a new list, so a new point. Joining the points gives a path.
It turns out that this path is often simple even when every neuron on its own is not. That is the claim behind the hero at the top of this page. The eight traces disagree, but the point they make together draws a loop.
Shenoy and colleagues call this the dynamical systems perspective. A dynamical system is anything whose next state follows from its current state by a rule, like a pendulum or a rolling ball. The perspective says: motor cortex is not a bank of dials, one dial per direction. It is a machine whose state moves by a rule, and a reach is a path of that state.
Three tools get us there. First, the state space, where one point stands for the whole population. Second, dimensionality reduction, a way to find the few directions that matter among hundreds. Third, jPCA, a method that finds a rotation in that space. We build each from zero, and each chapter ends with a toy you can break.
A decoder maps neural activity to a cursor or a limb. If the activity lives on a small, smooth sheet, a decoder only has to learn that sheet. It can ignore noise that lies off the sheet. It can also adapt when electrodes drift: the sheet stays, only your view of it moves (Chapter 8). Recent decoder papers, such as NoMAD and MINT (Chapter 10), build on exactly this idea.
Chapter 9 puts all the pieces in one pipeline you can run, and Chapter 10 is a field guide with the numbers and the code.
Chapter 1
Turn a list of firing rates into a single point, and a reach into a path through space
Take a sheet of graph paper. Label the horizontal axis "neuron A" and the vertical axis "neuron B". At one moment, neuron A fires at 22 spikes per second and neuron B at 23. Put a dot at (22, 23). Ten milliseconds later the rates have moved a little, so put a second dot. After 65 time bins you have 65 dots, and joined in order they form a path.
You just built a state space: a space with one axis for each neuron. Any point in it is a population state, the firing rate of every recorded neuron at one instant. It is a state in the everyday sense: it describes how the system is right now.
Two neurons give a flat page. Three neurons give a box you can hold in your head. Twenty-four neurons give a space with 24 axes, which nobody can draw. The idea does not change. A point is still a list of numbers, and in code that list is a vector: an array of length N, one slot per neuron.
A recording session produces more than one vector. You get one for each time bin, and one set for each reach. In this lesson the made-up data has a shape you can read off directly.
X[c][t][i]: 8 reaches × 65 time bins × 24 neurons = 12,480 numbers, each one a firing rate in spikes per second.
Real experiments average over repeats of the same reach first, so each reach becomes one smooth path. These averages are called condition averages, where a condition is one kind of reach. The Churchland datasets had 27 to 108 conditions each. Averaging removes spike noise that would hide the path.
Why is a point more useful than a list? Because points have distances. Two population states that are close together mean that the whole crowd is doing nearly the same thing. Two that are far apart mean the crowd differs. The ordinary straight-line distance works, and it is Pythagoras extended to many axes.
Work it through with three neurons from the device below. At 0.10 s the state is (22.3, 23.3, 20.4). At 0.20 s it is (17.9, 19.3, 30.2). The gaps are −4.4, −4.0 and +9.8. Squared they are 19.4, 16.0 and 96.0, which add to 131.4. The square root is 11.5. So in 100 ms the population moved 11.5 spikes per second through the space.
Divide by the time and you get a speed: the distance the state moves each second. A path has a speed at every moment. We will see that the speed of a reach path is far from random.
One more picture before the device. Each of the eight reaches gives its own path through the same space. If reach 1 and reach 5 start at nearby points and then curve away from each other, the crowd has "decided" to do different things. The space is shared. The paths are the stories. Everything in this lesson is a question about the shape of those paths: are they flat, do they curve, do they turn?
Left: three neurons over one reach. Right: the same three numbers as a point in a box. Drag the clock and watch the point trace out a path. Turn the box with the second slider.
Illustrative: neurons 1 to 3 of the made-up population, reach 1, no noise. The louder-units switch multiplies neuron 3's swing around its average by 4, as if it were measured in different units. The scaled version maps each neuron's own minimum and maximum to 0 and 1, a simple version of the normalisation used before PCA in Churchland et al.
Distance treats every axis alike. That is a hidden assumption, and it can fail. Suppose neuron 3 fires in a range four times wider than the others, maybe because its electrode sits closer to the cell. In the device, switch on the louder units. The path stretches along the third axis, and almost all of the distance now comes from one neuron.
The symptom is a path that looks like a single neuron in disguise. The measurement is the read-out: the share of the squared step length that comes from neuron 3 jumps from 53% to 95%. The fix is to normalise each neuron before you compare, so each one gets a fair vote. Switch on the scaling and the share falls to 25%, whatever the original units were.
Churchland et al. did this too. In the main analysis they scaled neurons to a similar firing-rate range, but only softly: strongly responding neurons came down to roughly unit range while weak neurons stayed below it, so noise in a weak neuron was not blown up.
Chapter 2
See why 24 neurons can be the shadow of two hidden signals, and what that does to the shape of the path
Picture a small room with two singers and 24 microphones. Every microphone hears both singers, but each one hears them in a different mix. Mic 7 is close to singer A and far from singer B. Mic 19 is the other way round. Record all 24 tracks and look at them: they all look different. Yet there are only two voices in the room.
That is the picture behind this whole chapter. Each neuron is a microphone. The singers are the hidden signals that the population shares. The recording has 24 tracks, but the cause of those tracks has only two.
A signal we cannot record directly, but that drives what we do record, is a latent variable ("latent" means hidden). Call the latent signals at one moment z: a short list of D numbers. Each neuron mixes them with its own weights, called loadings. Then it adds a baseline rate and some noise. That sentence is the whole model, and we can write it in one line.
Stack all T time bins side by side and the same line becomes a matrix product. Then X has shape N × T, W has shape N × D, and Z has shape D × T. For our made-up data, N is 24, T is 65 and D is 2. The recording holds 24 × 65 = 1,560 numbers. The two latent rows and the loadings hold only 2 × (24 + 65) = 178 numbers. Everything else is bookkeeping.
The big grid X is neurons (rows) against time (columns). It is W (left) times Z (below), plus noise. Change how many latent signals drive the neurons, how many neurons you record, and how noisy they are.
Illustrative: loadings and signals come from the same made-up population as the hero (reach 1). Signal 1 and 2 are a fading rotation (a cosine and a sine of 2 Hz); signal 3 is a bump at 0.25 s. Warm cells are above a neuron's own average, teal cells below. Noise is a fresh Gaussian draw per cell, fixed by a seed so the picture is the same on every visit.
Why would real neurons share a few hidden causes? One reason is wiring. Neurons in a circuit receive overlapping input and push on each other, so they cannot all do their own thing. Gallego and colleagues put it this way: each neural mode draws on many neurons, and one neuron can contribute to several modes. The shared patterns are the modes, and the circuit's connections are what hold them together. We do not claim this is the whole story, but it shows why a thin sheet is plausible.
Now return to the state space of Chapter 1. Each time bin gives a point xt = W zt + b. If D is 2, then xt is the baseline b plus a mix of just two fixed directions: the two columns of W. Moving along the first column or the second column are the only ways the point can go.
So all 65 points lie on a flat sheet: a plane through b, spanned by the two columns of W. The sheet sits inside the 24-axis space the way a sheet of paper sits inside a room. The room has three directions. The paper has two. A point on the paper needs only two numbers to say where it is.
This flat sheet is the simplest manifold. A manifold is a shape that is smooth and looks flat if you zoom in close enough, like the surface of the Earth. Its dimension is the number of numbers you need to say where you are on it. The Earth's surface is 2D even though it sits in 3D space. Gallego, Perich, Miller and Solla used the name neural manifold for the surface that population activity occupies, and neural modes for the patterns that span it.
Real manifolds can curve, and the model above draws only a flat one. Flat is still a very good first guess, and PCA (the next chapter) finds it. Chapter 10 lists what to use when the sheet curves.
Noise is not on the sheet. It pushes each point off in 24 random directions at once. Raise the noise slider and the signal fraction in the read-out falls. The symptom is a path that looks fuzzy and a heat map with no stripes. The measurement is the fraction of total variance that the hidden signals explain. The fix has two parts: record more trials and average them (the noise falls roughly as one over the square root of the number of trials), and record more neurons, so the sheet is pinned down by more points of view.
Chapter 3
Turn one axis through a cloud of points until its shadow is as long as possible, and watch the covariance matrix do the same job in one step
Hold a long stick in front of a lamp. Its shadow on the wall depends on how you hold it. Point the stick at the lamp and the shadow is a dot. Hold it across the beam and the shadow is as long as the stick. If you wanted to learn the most about the stick from its shadow, you would pick the second view.
That is principal component analysis, or PCA, in one picture. A cloud of points is the stick. A line through the cloud is the wall. We pick the line where the shadows spread out the most. Our PCA lesson derives it in full. Here we build only what this topic needs, with neurons.
Take two neurons, A and B, and plot one dot per time bin: A on the horizontal, B on the vertical. Say the dots form a slanted oval, because when A fires more, B tends to fire more. First centre the data: subtract each neuron's average rate, so the cloud sits around the origin. Now draw a line through the origin at angle θ. Drop every dot straight onto the line. The positions along the line are the "shadows", and the amount they spread out is their variance: the average squared distance from the middle.
You can compute that spread from three numbers: the variance of A, the variance of B, and their covariance, which measures how much they rise and fall together. The three numbers fit in a small table called the covariance matrix.
Work it with the numbers in the device below. With the first setting, neuron A has variance 14.8, neuron B has 7.3, and the covariance is 8.3. The total variance, which is the sum of the two variances, is 22.0. If you keep only neuron A (θ = 0), you keep 14.8 of 22.0, which is 67%. Now tilt the line to 33°. The shadow variance rises to 20.1, which is 91%. The tilted line beats both neuron axes, because the oval is slanted.
You can find the best angle without turning anything. The covariance matrix has special directions called eigenvectors: directions that the matrix only stretches and never turns. Each comes with a stretch factor, the eigenvalue. For a covariance matrix the eigenvalue is exactly the variance along its eigenvector. So the biggest eigenvalue names the longest shadow, and its eigenvector is the axis.
For two neurons the tilt has a closed form: tan 2θ = 2σAB / (σAA − σBB). Put in 8.3, 14.8 and 7.3 and you get tan 2θ = 2.22, so 2θ = 65.7° and θ = 32.9°. The two eigenvalues are 20.1 and 1.9, which add up to the same 22.0. PCA splits the total variance between perpendicular axes, never creating or losing any.
Each dot is one time bin of two neurons. The purple line is your axis; the small ticks on it are the shadows. Turn it until the bar shows the most variance kept, or press Snap to see what the eigenvector says.
Illustrative: 60 made-up dots from seeded random numbers, neuron A with standard deviation 4 and neuron B with 3 spikes per second before mixing. The slider sets how strongly B follows A. Variances, covariance and the best angle are computed live from the dots you see, using the same formula as the equation above.
With N neurons the covariance matrix is N × N, and the idea is the same. Here is the whole recipe, in the order a program runs it.
The output is a matrix of shape T × K. Each row is where a time bin lands in the new, smaller space. The first axis is the longest shadow, the second is the longest shadow left over, and so on.
PCA ranks axes by variance. That is a fact about spread, not about meaning. A loud neuron has a large variance and takes over the first component (the Chapter 1 problem again). A signal shared by every reach, such as a bump that starts the movement, adds large variance too. Then PC1 describes "the same thing in every reach", and the interesting differences between reaches hide behind it.
The symptom is a first component that looks the same for every reach. The measurement is the share of variance it takes. The fix is the one Churchland et al. used: normalise the neurons, and subtract the average over all reaches at each time before running PCA. Chapter 7 shows the subtraction in action.
Chapter 4
Decide how many axes to keep by comparing each eigenvalue with what pure noise would produce
You have run PCA on 40 neurons. It hands back 40 axes, sorted from the longest shadow to the shortest. Your next job sounds simple: how many of them do you keep? Keep too few and you throw away real signal. Keep too many and you keep noise, and every later step, like a decoder, learns that noise.
A plot of the eigenvalues, largest first, is called a scree plot. The name comes from the loose rocks that pile at the foot of a cliff: a steep drop, then a flat slope of rubble. In data the steep part is signal, and the rubble is noise.
Suppose there were no hidden signals at all, only independent noise on each of N neurons, each with variance σ2. You might guess that every eigenvalue would equal σ2. It does not. With a finite number of time bins T, the sample covariance wobbles, and the eigenvalues spread out. The largest one rises above σ2 by a predictable amount.
This is a classical result from random-matrix theory (the Marchenko-Pastur law), stated here for equal noise on every neuron. Real noise differs between neurons, so treat the floor as a guide, not a law. Work an example. Take N = 40 neurons, T = 200 time bins and noise variance σ2 = 9 (a standard deviation of 3 spikes per second). N/T = 0.2, and √0.2 = 0.447. So λ+ = 9 × 1.4472 = 9 × 2.094 = 18.9. Any eigenvalue under about 19 could be noise.
Notice what the formula says about your recording. Collect twice as many time bins (400) and N/T halves to 0.1, so the floor drops to 9 × 1.3162 = 15.6. Record more neurons without more time and the floor climbs. Both are design choices an experiment makes.
Top: the eigenvalues of 40 neurons, with the dashed noise floor. Bottom: how badly the first k axes rebuild the true hidden signal. Add hidden signals, raise the noise, and move k. Where is the bottom curve lowest?
Illustrative: 40 neurons, random loadings (standard normal), hidden signals with standard deviations 3, 2.5, 2, 1.6 and 1.3 (in that order), seeded random draws. The noise floor is the formula above, using the noise you set; real recordings do not tell you the noise, so it has to be estimated, for example by cross-validation. The error is the squared distance between the noiseless signal and its rebuild from k axes, divided by the signal's own size.
The formula also hints at a design rule. The ratio N/T is what widens the noise. A recording with 100 neurons and only 50 time bins has N/T = 2, and a noise floor of 9 × (1 + 1.414)2 = 52.4 even though every neuron has the same noise variance of 9. Before you trust a small eigenvalue, check how much data stands behind it.
Play with the device. Set three hidden signals and low noise. The bars show three tall eigenvalues and then a flat run of small ones below the dashed floor. With k = 3, the rebuild error is 4%, and it is lowest there. This is the happy case: the elbow of the scree plot sits at the true dimension.
Now set five hidden signals and raise the noise to 10. The floor climbs to 209. Only four eigenvalues stand above it, and the scree plot has no clear elbow. That is the symptom. The measurement is in the read-out: fewer axes stand above the floor than there are hidden signals. The honest conclusion is that this recording cannot resolve all five. More bins or less noise would.
Look at the lower curve too. With noise this high, the error is lowest at k = 2 (55%), not at 5. Axes that carry little signal and plenty of noise hurt more than they help. In a noisy recording, the best number of axes is smaller than the true number of signals.
The other mistake is keeping too many. Set k to 12 with three hidden signals. The variance kept rises toward 100%, which looks good, but the rebuild error rises again, because the extra nine axes carry nothing except noise. So "variance explained" always goes up with k and is a poor judge on its own. The error against a known truth, or against held-out data, is the honest judge.
Real labs rarely have a known truth, so they use held-out time bins or trials to decide. Churchland and colleagues reduced their data to six dimensions before jPCA and called that choice conservative: a few more than the rotations needed, so the plane they were looking for would not be cut off.
Chapter 5
See how one rule and a different starting point give a whole family of paths, and why that matters for a reach
Roll a marble into a bowl. Where does it go? The answer has two parts. The bowl is a rule: the slope at each spot decides which way the marble speeds up. Your hand is a starting point: where you let go. Change the rule and every path changes. Change only the start and you get a different path under the same rule.
Now ask the same about a reach. The monkey is told which way to reach, but must wait before it moves. During the wait, motor cortex activity settles into a state. At the go signal it sets off along a path. Shenoy, Sahani and Churchland ask a neat question about this: how does the current population activity determine the future activity? If there is a rule, the answer is the rule. If the rule is simple, the path should be easy to predict from the start.
Under the tuning story from Chapter 0, a neuron's rate is a function of the reach itself: its direction, its speed. Then rate depends on what you are doing, not on where the state came from. That story has a quiet problem. Churchland and colleagues point out two puzzles in real data: preferred directions that often flip sign over a single reach, and only a weak correlation between a neuron's tuning during preparation and its tuning during the movement.
The symptom is a neuron that is "tuned to the left" before the reach and "tuned to the right" during it. The measurement is the correlation of tuning between the two epochs, which is low. A pure tuning model has no way to explain this. A dynamics model does: preparation sets the start, the rule then carries the state somewhere else, and single neurons, being different views of that state, change their tuning as it moves.
The simplest rule is a linear dynamical system. Call the population state x (here two numbers, like the two principal components of Chapter 3). Its velocity ẋ, the rate of change of x, is a fixed matrix A times the current state.
Because the rule does not change with time, the whole path comes from two things: A and the start x(0). In neuroscience the start is the preparatory state, the state reached just before the movement begins. Churchland et al. found that in their generator model, the preparatory state sets the amplitude and phase of each reach's rotation, while the frequency stays the same across reaches.
A's eigenvalues (the stretch factors from Chapter 3, but now allowed to be complex) summarise the rule. Write one as a + bi, where i is the square root of −1. The real part a is a growth or decay rate. The imaginary part b is a rotation rate. Positive a grows. Negative a shrinks toward the middle. A non-zero b makes the state turn, b radians each second.
Work the simplest rotation. Let A = [[0, −ω], [ω, 0]] with ω = 2π × 2 = 12.57 radians per second, which is 2 turns each second. Start at (1, 0). The velocity is A x = (0, 12.57). In one 10 ms step, x moves by about (0, 0.126), a small hop upward, which is a turn of about 7.2°. In 0.5 s there are 50 such hops and the state is back where it began. The eigenvalues are 0 ± 12.57i: no decay, 2 Hz rotation.
Add decay and you get a spiral. Churchland et al. fit the frequency of real rotations. For one monkey the largest eigenvalue magnitudes were 8.8 rad/s for fast reaches and 9.8 rad/s for slow ones; for another monkey, 12.2 and 13.5 rad/s. That is 1.4 to 2.1 turns per second, and it hardly changed with reach speed.
The small arrows are the rule A: at each spot, which way the state moves. Click anywhere to set a preparatory state and watch its path. Switch the rule to see how decay, rotation and growth look.
Illustrative: a 2-D linear system with A = [[−a, −ω], [ω, −a]]. The four rules use (a, turns per second) = (2.5, 0), (1.2, 1.5), (0, 2) and (−0.8, 1). Paths are the exact solution x(t) = e−at R(ωt) x(0), drawn for 1 s. The first start you set is called the preparatory state. Your clicks keep the last three.
Try it. In the rotation rule, set two starts at the same distance from the middle but at different angles. The two paths are the same circle, but each runs ahead of or behind the other by a fixed amount. That is the preparatory state doing its job: it picks where on the circle the reach begins. In the spiral-in rule the same starts also decay toward the middle, so a reach would fade after a turn or two, as the real rotations do.
Chapter 6
Split any rule into a part that stretches and a part that spins, and see why the spinning part alone is a pure rotation
Spin a wheel by pushing its rim. Where you push, the rim moves sideways, not toward the hub and not away from it. The motion at every point is at right angles to the line from the hub to that point. A wheel can turn forever at the same size because nothing ever pushes it in or out.
That right-angle rule is the whole secret of rotation, and it has a short test. Let x be the position of a point and ẋ its velocity. Two vectors are at right angles when their dot product is zero: multiply matching entries and add. So a pure rotation obeys x · ẋ = 0 at every moment.
Take the rule ẋ = M x from Chapter 5. The dot product of position and velocity is x · (M x), which we can write xᵀ M x. The little T means transpose: flip a matrix over its diagonal, so entry (row 1, column 2) swaps with entry (row 2, column 1). A matrix is symmetric if flipping changes nothing. It is skew-symmetric if flipping changes only the sign: Mᵀ = −M.
Here is the trick. The number xᵀ M x is a single number, and a single number equals its own transpose. Transposing gives xᵀ Mᵀ x. If M is skew, Mᵀ = −M, so the number equals minus itself. The only number that equals its own negative is zero. So for any skew-symmetric M, x · ẋ = 0 at every position. The velocity is always sideways. The size of the state never changes, and the motion can only be a rotation.
A general rule M is not skew. But any square matrix splits in exactly one way into a symmetric part and a skew part: S = (M + Mᵀ)/2 and K = (M − Mᵀ)/2, with M = S + K. Think of it as two hands pushing the same wheel. One hand pushes the rim sideways (K). The other squeezes or stretches it (S).
Work a number. Let M = [[−1, −5], [7, −3]]. The transpose swaps −5 and 7. So S has off-diagonal entries (−5 + 7)/2 = 1, and K has off-diagonal entries −(7 + 5)/2 = −6 and +6:
S = [[−1, 1], [1, −3]] K = [[0, −6], [6, 0]] so ω = 6 rad/s, or 0.95 turns per second.
The eigenvalues of the whole rule M tell a slightly different story. Its trace (sum of the diagonal) is −4 and its determinant is (−1)(−3) − (−5)(7) = 38, which gives eigenvalues −2 ± 5.83i. So the full rule turns at 5.83 rad/s, not 6. The stretching part slightly interferes with the turning. This is why a skew fit and a plain eigenvalue read can disagree, and why you should know which one you are reporting.
The left panel is the whole rule M with four paths. The middle panel is its stretching part S, the right panel its rotating part K. Turn the three knobs and see which panel changes.
Illustrative: S = diag(stretch − decay, −stretch − decay) and K = [[0, −ω], [ω, 0]] with ω = 2π × the frequency you set. Paths are computed by integrating ẋ = M x for 0.8 s with small steps. The rotation frequency of the whole rule is the imaginary part of its eigenvalues, from the trace and determinant of M.
Now you can see the design of the method in Chapter 7. Neural data is full of decay (activity fades), growth (activity ramps up) and stretching. None of that is what Churchland and colleagues wanted to test. They wanted one question answered: is there rotation? So they fit the rule with the skew-symmetric constraint, Mskew = −Mskewᵀ, which forces the fit to explain the data with rotation alone. They also fit a free M. If the skew fit were far worse, rotation would be a poor story. It was not: for the neural data and for their model, the skew fit was nearly as good as the best unconstrained fit.
The failure to watch for is an unconstrained fit whose eigenvalues look like rotation because of something else, like a stretch plus noise. The skew constraint blocks that: only the rotating part is allowed to explain the data, so any rotation it reports was actually there.
Chapter 7
Turn eight noisy paths into one rotation rate by least squares, and learn the control that shows the rotation is real
You have eight paths in a plane. They look like loops. But your eyes are easy to fool: any path that goes out and comes back looks like a loop. You want a number that says how strongly the paths obey the rule "turn at a fixed rate", and a test that says what the number would be if nothing turned at all.
That is jPCA, the method of Churchland, Cunningham, Kaufman, Foster, Nuyujukian, Ryu and Shenoy (Nature, 2012). The name says what it does: it looks for the plane where the paths rotate most, the way PCA looks for the plane with most variance. The "j" is for the imaginary part of the eigenvalues, which carry the rotation.
Here are the steps from the paper, in order, with the shape of the data at each one. We use our made-up numbers: 8 reaches, 65 bins of 10 ms, 24 neurons.
For k = 6 a free M has 36 numbers and a skew M has only 6 × 5 / 2 = 15. In the paper the unconstrained fit uses linear regression. The skew fit uses a longer but still linear calculation, given in their supplement. The paper also reports that every step is trimmed to a short window: 200 ms in 10 ms steps, starting just before activity changes quickly at movement onset.
In two dimensions the skew fit has one unknown, ω, and we can solve it by hand. We want ẋ1 = −ω x2 and ẋ2 = ω x1. Choose ω to make the total squared error smallest, summed over every state:
Work a tiny case. Two states: x = (1, 0) with next state (0.99, 0.12), and x = (0, 1) with next state (−0.12, 0.99). With 10 ms between bins the velocities are (−1, 12) and (−12, −1). The numerator is (1 × 12 − 0 × −1) + (0 × −1 − 1 × −12) = 12 + 12 = 24. The denominator is 1 + 1 = 2. So ω̂ = 12 rad/s, which is 1.91 turns per second.
The plane shows the eight reaches after PCA. The warm arrows are the fitted rotation. The bars compare how much of the change in the state a rotation-only rule explains (teal) against a free rule (grey). Turn smoothing off to see noise ruin the fit. Press shuffle to see what no rotation looks like.
Illustrative: the hero's 24 made-up neurons with Gaussian noise (in spikes per second) added to every bin. Smoothing is a 7-bin weighted average before PCA. Shuffle puts the time bins of each neuron in a random order, separately for each reach, a simple control of our own in the spirit of the paper's shuffle control, which found no rotation in shuffled data. The plane is oriented so the turn is counterclockwise, as in the paper. The velocity is the difference of neighbouring 10 ms bins, as in the paper.
At noise 4 with smoothing on, the fit finds 1.83 turns per second, near the 2 Hz that built the data, and the rotation-only rule explains 79% of the change in the state. A free rule explains 84%. That small gap matches the paper's finding that a skew-symmetric fit nearly matches the best unconstrained fit.
Now turn smoothing off. The fitted rate still reads about 1.8 turns per second, but the share explained drops to 9%. The symptom is a good-looking rate with a poor fit. The cause: a velocity from neighbouring bins is a difference, and a difference of noisy numbers is very noisy. The measurement is the explained share. The fix is to average first, either over more trials or with a smoothing filter. Churchland et al. used trial-averaged data for exactly this reason.
Finally, press shuffle. With smoothing on, the fitted rate falls to 0.07 turns per second and both rules explain about 0 to 2%. With smoothing off, the fitted rate is 0.87 turns per second, yet the rotation-only rule explains 0%, while a free matrix explains 42%, because shuffled states jump back toward the middle and a shrinking rule can mimic that. A rate of 0.87 with an explained share of 0% is not a rotation. That is the control: apply the method to data where you destroyed the structure, and check that it finds nothing.
For real neurons the paper reports that, over nine datasets with 27 to 108 reach conditions each, the first jPCA plane captured on average 28% of the total data variance, about as much as the second and third principal components together (29%), and that two or three rotation planes together captured 50 to 70%. It also reports that rotations were absent in a walking monkey while it stood still, and that simple tuning models did not produce robust rotations. Those are the controls that make the claim a finding, not an artefact.
Chapter 8
Watch a fixed decoder break when the neurons change, then repair it by lining up the two days' planes
On Monday, a researcher spends twenty minutes calibrating a decoder. The person (or monkey) moves a cursor with their motor cortex, and the decoder learns which population states mean "up", "left" and so on. On Tuesday the cursor drifts. Nothing is wrong with the software. Overnight, some electrodes stopped hearing a cell and others started hearing a new one.
The linear decoder and the Kalman decoder from other lessons read specific neurons. If the neurons change, their weights point at the wrong things. The usual fix is to calibrate again each day. That costs time and effort, and for a person who relies on the device it is a daily tax.
Chapter 2 gave a model: x = W z + b + noise. The latent signals z are the manifold coordinates. Overnight, W changes, because the set of neurons changed. But if the same movement still runs the same latent dynamics, then z is the same up to a change of coordinates. The hope is to find that change, and apply it before the decoder.
Karpowicz and colleagues (Nature Communications, 2025) built a method called NoMAD, for Nonlinear Manifold Alignment with Dynamics, on this hope. It uses a recurrent network that models the neural dynamics. It then lines up new, shifted data with the old dynamics without any labels, so the original decoder still works. Earlier unsupervised methods ignored the dynamics, and the authors say that was a weakness. A related earlier paper, by Degenhart and colleagues (Nature Biomedical Engineering, 2020), also stabilised a BCI by aligning low-dimensional spaces of neural activity.
Here are the paper's reported numbers, so you can feel the scale. NoMAD was tested on 20 datasets from an isometric force task spanning 95 days, and 12 sessions from a reaching task spanning 38 days. In the force task the median decoding R2 was 0.91, against 0.65 for a method called ADAN and 0.59 for aligned factor analysis. The decoder's "half-life", the number of days until accuracy halves, was 208.7 days for NoMAD against 76.7 and 45.1. These are the paper's claims for its own data; your own data may differ.
NoMAD is a neural network, but the geometry underneath is old and small. Suppose the drift is just a rotation of the plane by an unknown angle θ. Collect a few paired points: the same moment seen on day 1 (point a) and day 2 (point b). Each pair gives one clue about θ. The best single angle uses all of them at once, by adding the sideways part and the straight part, as in Chapter 7.
Work two pairs. Let a1 = (1, 0) and a2 = (0, 1). After a drift of 40°, b1 = (0.766, 0.643) and b2 = (−0.643, 0.766). The sideways sum is 0.643 + 0.643 = 1.286. The straight sum is 0.766 + 0.766 = 1.532. Then θ̂ = atan2(1.286, 1.532) = 40.0°. This is the two-dimensional case of the orthogonal Procrustes method.
The decoder reads the reach direction from the angle of each start point, and it was trained on day 1 (left). On day 2 the plane has rotated (right). Raise the drift. Then give the aligner a few paired samples and watch the corrected points (teal) return to the targets.
Illustrative: eight start points on a ring (the eight reaches, 45° apart); the day 2 plane is the day 1 plane rotated by the drift. The decoder is correct when a point lands within 23° of its target (a target window of 0.4 ring radii). Paired samples are random points of the plane with noise of 0.2 ring radii added, from fixed seeded draws; the angle is estimated with the formula above. Real aligners such as NoMAD also work without pairs, by matching dynamics, and handle changes that are not pure rotations.
Keep the drift at 80° with no paired samples. The fixed decoder is off by 80° on every reach, so all eight targets are missed (the window is 23°). The symptom is a cursor that points a constant angle away from where the person aims. Give the aligner one pair. It estimates 52°, which still leaves 28° of error. With two pairs it estimates 66°, leaving 14°, and the decoder works. With 10 pairs the estimate is 75° and with 20 pairs it is 77°. The measurement is the gap between the estimated and the true drift. The fix is more pairs, or a method that finds structure in the dynamics so it needs no pairs at all.
There is a second failure that the device cannot show: the alignment assumes the underlying manifold and its dynamics did not change. If the person adopts a new strategy, or the task changes, the problem is no longer a change of view. Then an aligned decoder is confidently wrong. Hold-out checks on fresh data, and a short recalibration when a check fails, remain part of a careful system.
Chapter 9
Run neurons through every step of the lesson at once, then break each step on purpose to see what it was protecting
You now own five tools: a state space, a latent model, PCA, a scree plot and a rotation fit. In practice they run as one chain, and a mistake at one link shows up as a strange number at the end. This chapter is a workbench. It builds a population from your settings, runs the chain, and tells you what comes out.
Each link guards against one failure you have already met. Subtracting the shared part keeps a big movement-onset bump from becoming PC1 (Chapter 3). Smoothing keeps the derivative from being noise (Chapter 7). Reading the scree plot keeps you from keeping noise (Chapter 4). The explained share keeps you from trusting a rate with no fit behind it.
Pick a population, then read the three outputs: the share of variance in each axis (bars), the plane with the eight reaches, and the fitted rotation. Then switch off the two safeguards and make the shared bump large.
Illustrative: a made-up population (the hero's, grown to N neurons) with a 0.8 Hz second wheel and a bump that every reach shares, scaled by the slider. The pipeline is the real computation, run in your browser: Jacobi eigen-decomposition for PCA, 10 ms differences, closed-form least squares for ω. The true rotation is the number you set; the fitted number can differ because the slower wheel, the fade and the noise all leak into the plane.
Read the three outputs in order. The bars on the left say how much of the variance sits in each axis; two tall bars and then a drop mean a plane. The picture on the right shows whether the eight paths form loops. The line under the picture gives the fitted rotation and the explained share. If the bars show a plane but the share is low, the plane is probably not a rotation plane. If the share is high but the bars show no plane, check your noise setting first.
Experiment 1: more neurons. Set noise 3, true rotation 2 Hz, bump 6, both safeguards on. With 8 neurons the fit reads 1.64 turns per second and explains 60% of the change. With 24 neurons it reads 1.84 and explains 85%. With 60 neurons it reads 1.87 and explains 91%. More neurons average away independent noise, exactly as Chapter 2 said.
Experiment 2: remove the safeguard. With 24 neurons and the bump at 6, switch off "Remove shared part". The fitted rotation falls from 1.84 to 0.36 turns per second, and the explained share from 85% to 4%. The symptom is a plane that no longer looks like a loop. The measurement is the explained share. The cause: PC1 now describes the shared bump, so the plane holds one rotation axis and one bump axis. The fix is the subtraction. This is the reason the Churchland pipeline removes the cross-condition mean.
Experiment 3: too much noise. Raise the noise to 10 with everything else back at default. The top two axes now hold only 51% of the variance, and the fit explains 43% of the change. The rate still reads 1.74, which is the trap from Chapter 7: a fine-looking number on top of a weak fit.
Look at step 1 again. The input is a condition average, the mean of many repeats of each reach. Averaging is what made the paths clean. A BCI decoder does not get to average: the person makes one reach, and the cursor must move now. So jPCA is a tool for understanding the population, not a real-time decoder.
What carries over is the lesson about structure. Single-trial methods try to recover the latent state from one noisy trial. Gaussian-process factor analysis (Yu et al., 2009) does it with smooth latent curves. LFADS (Pandarinath et al., 2018) does it with a recurrent network that models the dynamics. The Kalman decoder from another lesson does it with a linear rule much like the one in Chapter 5. Chapter 10 lists these. All of them assume the activity has structure of the kind this lesson found.
Chapter 10
Keep the numbers, the terms, the checklist and the code, and find the papers that go further
Here is the lesson in one paragraph. A population of neurons is one point in a space with one axis per neuron. Because neurons share a few hidden causes, the points fill a thin sheet, the manifold, and PCA finds it. The scree plot and the noise floor say how many axes are real. In motor cortex during a reach, the point on that sheet turns, and the turn follows a simple rule set by the preparatory state. jPCA fits that rule with a skew-symmetric matrix, and a shuffle control shows the rotation is real. Because the sheet and its rule stay put while the recorded neurons change, a decoder that reads the sheet can survive the drift that breaks one that reads neurons.
Every number below comes from a paper or a formula, with its source. Numbers marked "paper" are the authors' claims for their own data.
| Quantity | Value | Source |
|---|---|---|
| Churchland recordings | 4 monkeys; 469 single-neuron recordings, plus 364 neurons recorded together on two 96-electrode arrays | Churchland et al. 2012 (full text) |
| Datasets | 9 datasets, each with 27 to 108 reach conditions | Churchland et al. 2012 |
| Analysis window | 200 ms in 10 ms steps; PCA to k = 6 dimensions before jPCA; cross-condition mean subtracted | Churchland et al. 2012 |
| First jPCA plane | 28% of total data variance on average; the 2nd and 3rd PCs together held 29%; two or three planes held 50 to 70% | Churchland et al. 2012 |
| Rotation | about 1 to 1.5 cycles, up to about 2.5 Hz; largest eigenvalue magnitudes 8.8 and 9.8 rad/s (monkey A, fast and slow reaches), 12.2 and 13.5 rad/s (monkey B) | Churchland et al. 2012 |
| Skew fit vs free fit | the skew-symmetric fit was nearly as good as the best unconstrained fit, for neural data and for the generator model | Churchland et al. 2012 |
| Noise floor | λ+ = σ2(1 + √(N/T))2; for N = 40, T = 200, σ2 = 9 it is 18.9 | Marchenko-Pastur law (classical result); worked in Chapter 4 |
| Realignment (NoMAD) | 20 force-task datasets over 95 days, 12 reaching sessions over 38 days; median force-decoding R2 0.91 against 0.65 (ADAN) and 0.59 (aligned FA); half-life 208.7 days against 76.7 and 45.1 | Karpowicz et al. 2025 (paper) |
| Geometry decoder (MINT) | beats expressive machine-learning decoders in 37 of 42 comparisons and other interpretable methods in all, as the abstract states | Perkins et al. 2025, eLife (abstract only; paper claim) |
| Every device in this lesson | made-up populations with fixed seeds, labelled illustrative at each device | this lesson |
| Term | Plain meaning | Chapter |
|---|---|---|
| Population state | The firing rate of every recorded neuron at one instant, as one point | 1 |
| Condition average | The mean over repeats of one kind of reach, which removes spike noise | 1 |
| Latent variable, loading | A hidden signal that drives many neurons; the weights that mix it into each neuron | 2 |
| Neural mode | One column of the loading matrix: a pattern of co-firing across the population | 2 |
| Manifold | A smooth shape that looks flat when you zoom in; here, the sheet the states fill | 2 |
| Eigenvalue, eigenvector | The variance along an axis, and the axis; PCA's output | 3 |
| Scree plot, noise floor | Eigenvalues in order; the level that noise alone would reach | 4 |
| Preparatory state | The population state just before movement; it sets the start of the path | 5 |
| Skew-symmetric matrix | A matrix with MT = −M; its rule only rotates | 6 |
| jPCA | Fit a skew-symmetric rule to the paths and take the plane that rotates fastest | 7 |
| Cross-condition mean | The average over reaches at each time; subtract it to remove what all reaches share | 3, 7, 9 |
| Alignment | Finding the change of view between two days so a fixed decoder still works | 8 |
The whole of jPCA fits in a short function. This version follows the steps in Chapter 7. It was run on a made-up rotating population and recovered 1.78 turns per second for a 2 Hz truth (with the fade and noise leaking in).
pythonimport numpy as np def jpca(X, dt=0.01, k=6): """X: (C, T, N) condition-averaged rates. Returns jPC axes (N, 2) and rotation rate in Hz.""" C, T, N = X.shape X = X - X.mean(axis=0, keepdims=True) # remove the cross-condition mean (C, T, N) Z = X.reshape(C * T, N) _, _, Vt = np.linalg.svd(Z, full_matrices=False) # PCA: rows of Vt are the axes (N, N) P = Vt[:k].T # (N, k) Y = (Z @ P).reshape(C, T, k) # states in the k-D plane space (C, T, k) A = Y[:, :-1].reshape(-1, k) # states (C*(T-1), k) B = (np.diff(Y, axis=1) / dt).reshape(-1, k) # velocities (C*(T-1), k) # skew-symmetric M = sum_p m_p (e_ij - e_ji); fit the k(k-1)/2 numbers m_p by least squares basis = [] for i in range(k): for j in range(i + 1, k): E = np.zeros((k, k)); E[i, j], E[j, i] = 1.0, -1.0 basis.append(E) D = np.stack([(A @ E.T).ravel() for E in basis], axis=1) m = np.linalg.lstsq(D, B.ravel(), rcond=None)[0] M = sum(mp * E for mp, E in zip(m, basis)) # (k, k), M = -M.T w, V = np.linalg.eig(M) # eigenvalues are +/- i*omega i = np.argmax(w.imag) # fastest rotation plane j1, j2 = V[:, i].real, V[:, i].imag jpcs = np.stack([j1 / np.linalg.norm(j1), j2 / np.linalg.norm(j2)], axis=1) R2 = 1 - ((B - A @ M.T) ** 2).sum() / (B ** 2).sum() return P @ jpcs, w.imag[i] / (2 * np.pi), R2 # (N, 2) axes in neuron space, Hz, explained share
Condition-averaged methods like jPCA need many repeats, which a real-time interface does not have. Later work estimates the latent state from single trials. The papers below are the ones this lesson leans on or points to. The first three were opened for this lesson (full text, or abstract through the publisher or PubMed); the rest come from our curated reading list, which verified their titles and DOIs but which we did not read in full here.
| Paper | Why read it | Link |
|---|---|---|
| Churchland, Cunningham, Kaufman, Foster, Nuyujukian, Ryu, Shenoy. Neural population dynamics during reaching. Nature, 2012 | The rotations and jPCA of Chapters 5 to 7 | doi |
| Shenoy, Sahani, Churchland. Cortical control of arm movements: a dynamical systems perspective. Annual Review of Neuroscience, 2013 | The dynamical systems view that replaces tuning | doi |
| Gallego, Perich, Miller, Solla. Neural manifolds for the control of movement. Neuron, 2017 | Neural modes and manifolds as a framework | doi |
| Yu, Cunningham, Santhanam, Ryu, Shenoy, Sahani. Gaussian-process factor analysis for low-dimensional single-trial analysis of neural population activity. J Neurophysiol, 2009 | Smooth latent paths from single trials | doi |
| Pandarinath et al. Inferring single-trial neural population dynamics using sequential auto-encoders (LFADS). Nature Methods, 2018 | A recurrent network that infers dynamics from single trials | doi |
| Kao et al. Single-trial dynamics of motor cortex and their applications to brain-machine interfaces. Nature Communications, 2015 | Dynamics used inside a decoder | doi |
| Degenhart et al. Stabilization of a brain-computer interface via the alignment of low-dimensional spaces of neural activity. Nature Biomedical Engineering, 2020 | Chapter 8's idea in a closed-loop interface | doi |
| Karpowicz et al. Stabilizing brain-computer interfaces through alignment of latent dynamics (NoMAD). Nature Communications, 2025 | Label-free alignment with dynamics (opened for this lesson) | PMC |
| Perkins, Amematsro, Cunningham, Wang, Churchland. An emerging view of neural geometry in motor cortex supports high-performance decoding (MINT). eLife, 2025 | A simple geometric decoder that rivals deep networks | eLife |
| Abbaspourazad, Erturk, Pesaran, Shanechi. Dynamical flexible inference of nonlinear latent factors and structures in neural population activity (DFINE). Nature Biomedical Engineering, 2024 | A nonlinear manifold with linear dynamics, inferred causally | doi |
| Schneider, Lee, Mathis. Learnable latent embeddings for joint behavioural and neural analysis (CEBRA). Nature, 2023 | Contrastive latent spaces for neural data | doi |
For the PCA derivation in full, read PCA; for unmixing sources, ICA. Latent models like the one in Chapter 2 are usually fitted with EM, which EM and Gaussian mixtures builds from zero. The linear rule of Chapter 5 is the heart of the Kalman filter, and its smoother is in RTS smoothing. Spike counts as Poisson draws are in generalised linear models. In this series, the decoders that sit on top of the population are in linear decoders and the Kalman decoder, and the step before this lesson is spike detection.
Now press Teach and explain one thing out loud from memory: why 24 messy neurons can draw one clean loop, how PCA finds the plane, how to pick the number of axes, and what the shuffle control proves. Then go back to the population at the top, press Play and watch the point turn again, this time naming each step of the pipeline that drew it.
This lesson was written from primary sources, with no slides. We opened the full text of Churchland et al. (2012) in PubMed Central and took every number about their data from it. We read the abstracts of Shenoy, Sahani and Churchland (2013) and of Gallego et al. (2017), and the full text of Karpowicz et al. (2025). The reading list items marked above are cited from our curated list. The Princeton course NEU 560, Statistical Modeling and Analysis of Neural Data, taught by Jonathan Pillow, is the follow-along course for this part of the series; we credit it for the order of ideas (PCA, then latent-variable models) and did not copy its slides. All devices and all made-up numbers are ours.