Course Intro and Linear Algebra

A neuron in your eye does not report light. It reports a difference, centre minus surround, as a rate of spikes. Move both lights and count the spikes.

Learn why the brain counts as a computer, how a cell turns light into spikes, how the brain guesses what it cannot see, and the vectors and matrices that describe a whole population of cells.

Pick a light pattern, or drag the centre light and the surround light. Watch the five spike trains. Then we build, piece by piece, the ideas and the algebra that the rest of the course stands on.

You need a little calculus and a feel for what a probability is (a number from 0 to 1 that says how likely something is). We build the rest from zero.

Based on Lecture 1 of Princeton NEU 560: Statistical Modeling and Analysis of Neural Data, taught by Jonathan Pillow, and its linear algebra review (Lecture 1b). Slides: course intro and linear algebra review. Suggested reading: the introduction to Spikes by Rieke, Warland, de Ruyter van Steveninck and Bialek.

Shine light on one neuron

0.70
0.70

Toy cell: it fires 20 spikes per second in the dark, plus 110 spikes per second for every unit by which the centre light beats the surround light, held between 0 and 100. The five 1 s trials are random but fixed, so they match on every visit. The idea (a centre minus surround difference sent as spikes) is the lecture’s.

Chapter 0

Why Study Neural Data

See what a neuroscientist actually records, and meet the two families of method that the whole course uses to explain it

Picture a lab bench. A thin tungsten wire sits next to one neuron in the brain of a fly. The wire measures a voltage, and the voltage wobbles. Every so often it jumps in a sharp, same-shaped blip.

Each blip is a spike, also called an action potential: a brief electrical pulse that a neuron sends down its fibre. Spikes are all the brain has to talk with. The recording is a list of times, and nothing else.

So here is the question for the whole course. Given a list of spike times, what can we say about the world, the animal, or the cell itself? Answering it takes statistics, and the statistics need linear algebra. This lesson covers both ends: why the question matters, and the algebra you need before you start.

The course in one paragraph

NEU 560 is a Princeton course taught by Jonathan Pillow, with Victor Geadah as the assistant instructor. It meets twice a week and has no final exam. Homework comes about every two weeks as a Google Colab notebook, mostly Python code with some pencil maths, and counts for 50% of the grade.

A short quiz opens class each week (15%). Participation counts 10%. A final project, alone or in pairs, counts 25%: 10% for the talk and 15% for the write up. There is no official textbook. The slides list Bishop’s Pattern Recognition and Machine Learning, Dayan and Abbott’s Theoretical Neuroscience, and Kass, Eden and Brown’s Analysis of Neural Data.

Two rules show the spirit. You may talk with others, but you submit code you could rebuild from scratch. AI tools may help find bugs, but the slides say you must understand every line you hand in. The prerequisites are calculus, linear algebra and basic probability. No neuroscience is assumed.

Two families of method

The syllabus says the course leans on two kinds of model. The first is regression, also called supervised learning. You know an input and you predict an output. The input is the picture on a screen. The output is the cell’s spikes.

The second is the latent factor model, also called unsupervised learning. A latent variable is a hidden cause that you never measured. A hundred neurons may all rise and fall together because one hidden dial moves them. You see the neurons. You infer the dial.

A third group of topics are tools that both families borrow. Poisson processes describe how random spike counts scatter. Regularization keeps a fit honest. Information theory counts bits. Try sorting the syllabus yourself.

Sort the syllabus

Each card is a topic from the course description, with what it does for spikes. Decide: does it predict spikes from a known input, find a hidden cause, or serve as a tool?

The 14 topics are the bullet list in the course description. The three groups and the one-line spike examples are our own sorting, not the course’s. A few topics (Gaussian processes, for one) can play more than one role.

Notice what the two families share. Both treat spikes as data that arrive with randomness. Neither expects a clean answer from one trial. That is why the course puts so much weight on programming: you learn a method by running it on noisy data and seeing it fail.

Why now

The lecture ends on a hopeful note, and the slides give three reasons. We now get incredible data. Computers are getting extremely fast. And advances in statistical methods let us understand that data deeply. Chapter 7 puts numbers on the first reason.

The slides suggest one reading for today: the introduction to Spikes, by Rieke, Warland, de Ruyter van Steveninck and Bialek. Chapter 1 weaves it in. The lecture also comes with a linear algebra review, which fills the last three chapters.

The road

  1. The brain as a computer: spikes, rates and the question of what a code means.
  2. One neuron computes a difference: centre, surround and the retina.
  3. Illusions as evidence: Mach bands, the Hermann grid and lightness.
  4. Context and colour: why the brain never reports the raw image.
  5. Perception as Bayes: likelihood, prior and posterior.
  6. Replacing neurons: cochlear implants and moving a cursor by thought.
  7. Recording at scale: electrodes, arrays and the data matrix.
  8. Vectors: a population as one arrow, with length, angle and projection.
  9. Matrices: two ways to multiply, and the outer product.
  10. Spaces: basis, rank, column space and null space.
  11. Field guide: the numbers, the checklist and the code.
A hundred neurons all rise and fall together, and you never measured why. Which kind of model looks for the hidden cause?

Chapter 1

The Brain as a Computer

Learn what “the brain computes” means, and read the three facts about spikes that Adrian found in 1926

In the 1920s, E. D. Adrian hung a small weight from a frog muscle. Inside the muscle sat a stretch receptor, a sensor cell. He placed the cell’s nerve fibre across two electrodes and recorded the voltage between them.

Light weight, few blips. Heavy weight, many blips. That plain result opened a whole field. It says the brain’s input is a pattern of blips, and the pattern changes with the world.

What “computing” means here

The lecture defines computational neuroscience in two parts. First, use mathematical and computational tools to study the brain. Second, study how the brain behaves as a computer: a machine that processes information and computes useful outputs. The big question is which algorithms it uses.

The slides quote Christof Koch. The brain takes in sensory data and encodes it into variables, such as membrane voltage or firing rates. It then performs a large number of operations on those variables to pull out features. Some results get stored. Others drive the muscles.

That is a claim you can test. A variable is a number the cell carries. An operation is a rule that turns some variables into others. If you can write the rule down and it predicts the spikes, you have found part of the algorithm.

The lecture also lists the metaphors people used for the brain. Descartes saw a hydraulic device. Leibniz saw a mill. Sherrington saw a telegraph, and later people saw a telephone switchboard, a digital computer, and a quantum computer (Penrose, 1989). The last entry on the slide asks, with a question mark, whether it is a convolutional network. Each age borrows its newest machine. The course asks for something stricter: a model that data can contradict.

Three facts about the code

The suggested reading, Spikes, opens with Adrian’s results. Every sense reaches the brain in the same form: sequences of identical voltage pulses. The book asks for a dictionary of that language. Adrian found three things.

Fact one: the all-or-none law. A spike either happens or it does not. Every spike has nearly the same shape, so a single neuron can pass information only through the times at which its spikes arrive. Spikes are active: the cell spends energy to send one, so the pulse does not fade over a long fibre.

Fact two: rate coding. When a steady stimulus gets stronger, the neuron fires faster. The firing rate is the number of spikes per second. To be precise, the count in a fixed window after the stimulus starts tells you its strength. Figure 1.4 of the book shows this for stretch receptors.

Fact three: adaptation. If the same stimulus stays on, the rate slowly falls. Adrian linked this to a common experience: you stop noticing a constant touch. Try all three facts in one place.

Hang a weight on the muscle

The top strip shows the spikes in one counting window. The left curve is rate against weight. The right curve is rate against time under a steady load. Move all three sliders.

2.0 g
0 s
100 ms

Toy cell shaped after Figures 1.3 and 1.4 of Spikes: the rate at onset is 30 plus 40 spikes per second for each gram, and it decays with a 6 s time constant to 30% of that. The numbers are illustrative, not Adrian’s data. The spikes are random but fixed, so they match on every visit.

Set the weight to 2 g and the time to 0 s. The cell fires at 110 spikes per second. In a 100 ms window you expect 11 spikes. You count, say, 11, and divide by 0.1 s. Your estimate is 110.

But the count is random. Run the same trial twice and you may count 9 spikes, then 13. As a rule of thumb, counts scatter by about the square root of the count. So 11 spikes give a spread of about 3.3, and the rate estimate is 110 plus or minus 33. A longer window fixes that: 500 ms gives 55 spikes, a spread of 7.4, and an estimate of 110 plus or minus 15. Slide the window and watch the error shrink.

The cost is time. A longer window means a slower answer, and the hold-time slider shows why that matters. Under a steady load the true rate falls from 110 to about 48 within 10 s. A very long window averages across that change and blurs it.

The reader inside the head

The book asks what it would mean to understand the code. Its answer is a thought experiment. Imagine a tiny observer, a homunculus (Latin for little man), who watches the spike trains and tells you what happened in the world. If you understand the code, you can do that observer’s job.

Two facts shape the job. The animal does not know the next stimulus in advance, and it cannot wait forever, so averaging for a long time is not an option. It must give a running commentary from a single example of each spike train. That is the same trade you just met: a long window cuts noise but answers late.

This gives us two directions for the course. Encoding asks how a stimulus becomes spikes. Decoding asks what spikes say about the stimulus. The book argues that decoding may be the simpler problem. Chapter 6 shows a machine doing exactly that, and The Spike and Spikes to Rates go deeper on the cell and on rates.

From a voltage trace to a rate

Here is the data flow, so you can build it. The electrode gives a voltage trace: one number per sample, a vector of length T. Say the recorder takes 10,000 samples per second, so 0.2 s gives T = 2,000 numbers. This sampling rate is illustrative.

Step one filters the trace to keep the fast part that spikes live in. Step two applies a threshold. Every upward crossing becomes one spike time. Figure 1.2 of the book shows exactly this: a noisy trace, a filtered trace, and a bottom panel of timing pulses made by a threshold circuit. The output is a short list of spike times, say n = 17 numbers.

Step three cuts time into bins and counts the spikes in each one. With 100 ms bins and 0.2 s of data you get two counts. Step four divides each count by the bin width to get a rate. Eleven spikes in 0.1 s is 110 per second. Each step shrinks the data: 2,000 voltages, then 17 times, then 2 counts, then 2 rates.

The book argues that this shrinking can lose something. It claims that in many senses single neurons give about one spike per characteristic time of the stimulus. A rate is an average, and one spike cannot supply an average. So the authors treat decoding from spike timing as a serious alternative. They also report single neurons sending several bits per spike. We keep both pictures: rate for slow steady stimuli, timing when the world moves fast.

A neuron fires 40 spikes in a 0.5 s window. Roughly what is its rate estimate, and what happens if you shorten the window to 0.1 s?

Chapter 2

One Neuron Computes a Difference

Follow light through the retina, and see why the cell that leaves it reports centre minus surround, not brightness

In 1953, Horace Barlow recorded from one retinal cell in a frog. He shone a small spot of light and made it bigger. The cell fired more and more. Then, at a certain size, it began to fire less.

A bigger spot has more light. So why fewer spikes? The answer is the first real example in this course of a neural computation, and it fits on one line.

The retina in three layers

The lecture opens its evidence with illusions: mathematical models of neural responses can often explain why the world looks the way it does. It starts at the back of the eye, with the retina, the sheet of cells that catches light.

The slide draws three layers. Photoreceptors detect the light. Bipolar cells pass the signal on. Retinal ganglion cells are the output cells. Their fibres send all visual information to the brain, as spikes.

Now the slide asks the key question: which mathematical operation does the ganglion cell perform? The answer: the difference between the light in the “centre” and the light in the “surround”. The slide marks the pattern with minus, plus, minus signs.

The region of the world that can change a cell’s activity is its receptive field. Barlow described this one as centre-surround. Light in a small central region excites the cell. Light just outside, in the surround, inhibits it.

Three pictures, three rates

The lecture then shows three stimuli on the same cell. A light centre with a dark surround gives lots of spikes. A uniform light gives few spikes. An edge, with light on one side and a dimmer grey on the other, gives more spikes again. The hero at the top does exactly this.

Uniform light gives few spikes because the plus and the minus nearly cancel. In many cells they are balanced, so spreading light evenly across the field produces almost no response. The cell stays quiet about overall brightness. It speaks up when light changes from place to place.

Why the big spot loses

Let us build Barlow’s curve. Model the field with two bell shapes, one narrow for the centre and one wide for the surround. The narrow one has a spread of 0.08 mm, the wide one 0.25 mm. Scale the surround by a strength k. This pair is called a difference of Gaussians.

Now grow a disc of radius r. Count how much of each bell the disc covers. For a bell of spread σ, a disc of radius r covers a share of 1 minus exp(−r² / 2σ²). Subtract the covered surround, scaled by k, from the covered centre.

R(r)
The net drive from a spot of radius r, as a fraction of the most the centre alone could give.
1 − e−r²/2σc²
The share of the narrow centre bell covered by the spot. It reaches 1 once the spot passes about 0.2 mm.
k
The strength of the surround. At 0 the cell ignores the surround. At 1 the two bells balance.
1 − e−r²/2σs²
The share of the wide surround bell covered. It grows more slowly, so it starts to bite later.

Grow the spot

Top: what each thin ring of the spot adds (warm) or takes away (purple). Middle: the total response against spot radius. Bottom: spikes from three trials. Drag the radius, then weaken the surround.

0.10 mm
0.60

Toy field: centre spread 0.08 mm, surround spread 0.25 mm, firing rate 10 plus 100 times R(r) spikes per second, held between 0 and 110. With k = 0.6 the peak falls at 0.20 mm, the size where Barlow’s frog cells stopped gaining (Figure 1.6 of Spikes). The numbers are illustrative.

Work one point by hand with k = 0.6. At r = 0.1 mm the centre share is 1 − e−0.78 = 0.54. The surround share is 1 − e−0.08 = 0.077, and 0.6 times that is 0.05. Net drive: 0.50, so the cell fires about 60 spikes per second.

At r = 0.2 mm the centre share is 0.96 and the surround term is 0.16. Net: 0.79, about 89 spikes per second. That is the peak. At r = 0.4 mm the centre is full at 1.00 but the surround term has grown to 0.43. Net: 0.57, about 67 spikes per second. The spot got bigger and the cell got quieter.

Now the failure that is not a failure. Set the surround to 1 and grow the spot to its maximum. Symptom: the spikes fade away. Measurement: the rate sinks toward the 10 spikes per second baseline. Fix: there is none, because nothing is broken. A perfectly balanced cell reports only differences, so a field of uniform light says nothing.

From the retina to the cortex

Hartline found a related effect in the horseshoe crab. Each cell reports the difference between light at its own spot and at its neighbours. So the crab retina responds strongly to edges. Kuffler found the same centre-surround layout in the cat. Lettvin and colleagues called some frog cells “bug detectors”, tuned to a spot about the right size for a bug.

Hubel and Wiesel then found that cells in cat visual cortex prefer bars at a particular orientation. They suggested that such a cell could be built from several centre-surround cells whose centres line up. Simple features feed into bigger ones. We use the language of centre and surround again in the next chapter.

The same cell as a dot product

Now the realization. A computer holds the picture as a grid of light values. Take a tiny 3 × 3 patch around the cell and flatten it into a list of 9 numbers, a vector x of shape (9). The receptive field is a second list w of 9 weights. The cell’s drive is the dot product w · x, a single number. Chapter 8 defines the dot product.

Choose the weights to match the minus, plus, minus layout: +8 for the centre pixel and −1 for each of its eight neighbours. They add up to zero, which is what “balanced” means. Now test three patches. A uniform patch of any brightness gives 8 − 8 = 0 times that brightness, so the drive is 0. A spot, centre 1 and all neighbours 0, gives 8. An edge with the left two columns bright gives 8 − 5 = 3, because five of the eight neighbours are bright.

That is the whole ranking of the lecture’s three pictures in three lines: spot 8, edge 3, uniform 0. The rate comes next: add a baseline, clip below zero, and draw spikes. The result is the simplest encoding model: a dot product, then a nonlinearity, then random spikes. The generalized linear model in its own lesson is this recipe with the statistics done properly.

A balanced centre-surround cell sees a spot of light that grows far beyond its receptive field. What does its firing rate do, and why?

Chapter 3

Illusions as Evidence

Use one stripe pattern to see how a cell that reports differences makes the brain see bands that are not there

Look at a row of seven grey stripes, each one a single flat shade, each a little darker than the one before. Every stripe has constant luminance. Yet near each boundary you see a thin light band on the bright side and a thin dark band on the dark side. The stripes look as if they have gradients.

These are Mach bands. The lecture asks the question directly: each stripe has constant luminance, so why does it look like there is a gradient? The answer sits in the cell from Chapter 2.

Two cells at one edge

The lecture puts two retinal cells at the same boundary: a cell on the left edge and a cell on the right edge. Each has the minus, plus, minus layout. Let us do their arithmetic with toy numbers.

Say the bright stripe has luminance 0.8 and the dark stripe 0.4. A cell has a centre and eight surround neighbours, and the surround is scaled by a strength k of 0.8. First, a cell deep inside the bright stripe. Its centre sees 0.8. Its surround averages 0.8. Response: 0.8 − 0.8 × 0.8 = 0.16.

Now move that cell to the bright side of the edge. Its centre still sees 0.8. But three of its eight neighbours sit on the dark stripe, so the surround averages (5 × 0.8 + 3 × 0.4) / 8 = 0.65. Response: 0.8 − 0.8 × 0.65 = 0.28. The cell fires more than its deep neighbour, because its surround is dimmer.

Take the cell on the dark side. Its centre sees 0.4. Three neighbours sit on the bright stripe, so the surround averages (3 × 0.8 + 5 × 0.4) / 8 = 0.55. Response: 0.4 − 0.8 × 0.55 = −0.04, which a real cell shows as silence. A deep dark cell would give 0.08. It fires less than its deep neighbour.

Put the three numbers side by side. Bright side: 0.16 deep, 0.28 at the edge. Dark side: 0.08 deep, below zero at the edge. The neural picture overshoots at the boundary. That is the light band and the dark band.

Run a row of cells over the stripes

Top: the stimulus. Bottom: the firing rate of a row of 140 cells, one per column. The dashed line is what a plain brightness meter would report. Choose a pattern, then weaken the surround.

0.80

Toy row: each cell has a centre spread of 1.5 columns and a surround spread of 5 columns, and fires at 15 plus 250 times its net drive, held between 0 and 100 spikes per second. Cell A and cell B flank the middle edge. Stripe luminances run from 0.95 down to 0.11. The pattern is the lecture’s; the numbers are illustrative.

Use the stripes with the surround at 0.8. Each flat step now shows a small hump at the bright side of the boundary and a dip on the dark side. Set the surround to 0 and the humps vanish: the response simply copies the stimulus. That is the symptom, the measurement and the fix in one slider.

The book credits Hartline and Ratliff with this link. Figure 1.5 of Spikes plots the physical light curve at the edge of a shadow beside the sensation curve people report. The sensation curve has a bump and a dip that the light does not have. They matched it to the difference mechanism in the visual system.

Two more illusions

The lecture shows two more patterns without explanation. In the lightness illusion, three identical grey discs sit on a background that fades from white to black. The disc on the white side looks darkest. A centre-surround cell explains it the same way: a disc ringed by bright light gets more inhibition and fewer spikes.

The Hermann grid is a black grid with white lines. Grey smudges appear at the crossings, but only where you are not looking. The long standing explanation is again centre and surround. A cell at a crossing has more white in its surround than a cell on a street, so it gets more inhibition and looks darker. We flag two limits: the slides give no explanation for these two, so this is our reading, and vision scientists still debate the details of the Hermann grid.

The lesson for a modeller is practical. An illusion is a case where the percept disagrees with the stimulus. If a model predicts the disagreement from cell responses, that is evidence that the model has captured something real.

The same row as a filter

A row of cells is a filter: one small pattern of weights slid along the stimulus, with a dot product at each position. Use the simplest centre-surround pattern in one dimension, (−1, 2, −1). Place it on a flat stretch of 0.8s. The dot product is −0.8 + 1.6 − 0.8 = 0. A flat region gives nothing.

Slide it to the last bright cell of the edge, where the three values are 0.8, 0.8, 0.4. The product is −0.8 + 1.6 − 0.4 = 0.4. At the first dark cell the values are 0.8, 0.4, 0.4, giving −0.8 + 0.8 − 0.4 = −0.4. So the filter answers 0 on flats, +0.4 just before the edge and −0.4 just after. It marks the edge and ignores everything else. The bright and dark bands are those two numbers.

Now slide it along a smooth ramp, 0.9, 0.8, 0.7. The product is −0.9 + 1.6 − 0.7 = 0. A steady gradient gives zero too. That is why the ramp setting in the device has no bands, and why a smooth gradient is hard to see against a flat background: the cells barely respond to it.

One more link. Sliding a filter along a row is a matrix product. Put the filter’s weights on the diagonals of a 140 × 140 matrix and multiply it by the 140 stimulus values. Chapter 9 gives that product two views. In the device, every cell used the same weights, so the whole row is one filter at 140 positions.

At the edge between a bright and a dark stripe, why does the cell on the bright side fire more than a cell deep inside the bright stripe?

Chapter 4

Context and Colour

See why the brain never reports the raw image, and how one photograph can fool two people in two different ways

Three cars sit on a road that runs away from you. In the photograph the near car, the middle car and the far car take up exactly the same patch of the image. The lecture says so: all three cars take up the same space in the image, and on your retina. Yet the far car looks like a giant.

If the eye only reported the image, the three cars would look equal. They do not. So something between the eye and your experience has done a calculation.

Size is a calculation

The slide says it plainly. Your brain is not simply reporting how big things are on the retina. It is doing a complex calculation to tell you how big things are in the world. The lecture shows two lines and a road scene to make the point: context is important.

Here is the arithmetic of that calculation. An object of width w at distance d makes an image whose angle is about w divided by d. The eye only gets the angle. To recover w, the brain multiplies the angle by a guess of the distance.

Take three cars with the same image angle of 0.14 radians, which is about 8 degrees. Context says they stand 10 m, 20 m and 30 m away. The widths come out as 1.4 m, 2.8 m and 4.2 m. The numbers are illustrative. The far car is not drawn bigger. It is inferred to be bigger, because the same image from farther away needs a bigger object.

Colour is a division

The lecture next turns to colour and credits Beau Lotto. It shows an image that fools about two thirds of people, and sparks arguments across the globe. You may know it as the photograph of a striped dress that some people see as white and gold and others as blue and black.

The slide gives the diagnosis in one line. The percept depends on statistical inferences the brain makes about the light source. To see why, follow the light. A surface has a reflectance: the share of each colour that it bounces back. The light that falls on it has its own colour balance, the illuminant. The eye receives their product, one number each for red, green and blue.

The brain wants the reflectance, which is the surface itself. But the eye gives only the product. To recover the surface, the brain divides by a guess of the illuminant. A wrong guess gives a wrong surface. Two different guesses give two different dresses from the same pixels.

Guess the light

Left: two fixed pixel colours that reach the eye. Middle: the light you assume. Right: the surface colours you infer, by dividing each pixel by the light. Slide the assumed light from bluish shade to warm lamp.

bluish shade

Illustrative: the two pixels are made up (stripe A is 140, 150, 185 and stripe B is 110, 95, 70 in red, green, blue), and the assumed light runs from 0.85, 1.00, 1.20 (bluish) to 1.15, 1.00, 0.80 (warm). The colour names are a rough rule on the numbers. The idea, a percept set by an inference about the light, is the lecture’s.

Work stripe A at the bluish end. The assumed light is 0.85, 1.00, 1.20. Divide the pixel: 140 / 0.85 = 165, 150 / 1.00 = 150, 185 / 1.20 = 154. The result is a near-neutral light grey, so the stripe reads as white. Stripe B gives 110 / 0.85 = 129, 95, 70 / 1.20 = 58. That is a brown-gold.

Now take the warm end, 1.15, 1.00, 0.80. Stripe A gives 140 / 1.15 = 122, 150, 185 / 0.80 = 231: a clear blue. Stripe B gives 96, 95, 88: a dark grey, close to black. Same pixels, opposite verdict. If you assumed you were in shadow with bluish light, you subtract the blue and see white and gold. If you assumed a warm lamp, you subtract the warmth and see blue and black.

Notice what the brain did not do. It never measured the light directly. It guessed, using what it knows about scenes: daylight tends to look like this, rooms like that. That guess is a belief, and beliefs have a formal home. The next chapter gives it the name prior.

The symptom here is disagreement between two honest observers. The measurement is the slider: the verdict flips somewhere near the middle of its range. There is no fix on the image itself. The only fix is more context, such as seeing the room, which narrows the guess.

How a brain could guess the light

Where does the guess come from? The lecture only says the brain makes a statistical inference. A simple rule shows how one could work. Suppose that, on average, the surfaces in a scene reflect all colours equally. Then the average pixel colour tells you the light. This rule is called the grey world assumption. It is one example, not the lecture’s claim, and we do not know that the brain uses it.

Try it. A scene averages (150, 130, 100) in red, green, blue. Divide by the green value: (1.15, 1.00, 0.77). That is a warm light, close to the warm end of the device. A scene that averages (115, 130, 155) gives (0.88, 1.00, 1.19), a bluish shade. The same rule puts the dress photograph in one camp or the other depending on what else is in view, which is why context matters.

The size calculation needs the same care. The small angle formula is angle = width / distance, with the angle in radians. To convert, multiply degrees by 0.01745. A car that fills 8 degrees is 0.14 radians. If the brain thinks the car is 10 m away, the width is 1.4 m. Take away the distance cue, as in a photo of a blank wall, and the brain has nothing to multiply by. Then it falls back on a default, and sizes look wrong.

Both examples share a shape. The eye gives a product of two unknowns, a surface and a condition of viewing. The brain needs one number from one product, so it must bring something extra. Chapter 5 shows what: a prior.

The eye receives a product of surface reflectance and illuminant. What must the brain do to estimate the surface colour?

Chapter 5

Perception as Bayes

Turn “the brain makes a best guess” into one rule, and see why a strong belief can beat the picture in front of you

You look into a small room through a peephole. Three people stand along the back wall, and the one on the right looks like a giant beside the one on the left. You know people do not vary that much. So what is going on?

This is the Ames room. The lecture states its core fact in one line: many different 3D scenes can give rise to the same 2D retinal image. The eye gets a flat picture. Several worlds could have made it.

The brain wants a posterior

The slide names what the brain wants to know: what is in the world, given my sensory data? In symbols, P(world | sense data). The bar reads “given”. That is a probability: a number from 0 to 1 for each possible world.

The tool is Bayes’ rule, which flips a conditional probability. The lecture writes it with a proportionality sign, meaning “equal up to a constant”.

P(world | sense data)
The posterior: the brain’s resulting beliefs about the world, after seeing the data.
P(sense data | world)
The likelihood: how probable this image is if the world were a given way. The laws of physics set it. It is ambiguous, because many worlds give the same image.
P(world)
The prior: how probable each world is before looking, from past experience.

The lecture ties this to Helmholtz, who called perception “optimal inference”: our best guess of what is in the world, given our current sensory evidence and our prior experience. The slide credits the picture to Alan Stocker. So perception is not a camera. It is a verdict.

Two worlds, one image

Now apply the rule to the Ames room. Call the two worlds A and B. In A, the room is an ordinary box and the people differ in size. In B, the room is slanted and the people are equal. The lecture notes that P(image | A) and P(image | B) are equal, because both worlds could produce this exact image.

Then the rule is short. P(A | image) = P(image | A) P(A) / Z, and P(B | image) = P(image | B) P(B) / Z. The constant Z is just the two products added up. Dividing by it makes the two posteriors sum to 1. When the likelihoods match, they cancel, and the prior alone decides.

The second example is the hollow face illusion, from Richard Gregory. A video shows the hollow back of a mask as it turns. You see a normal, bulging face. The slide writes the two verdicts as P(convex | video) = P(video | convex) P(convex face), and the same for concave. Its note: a very strong prior for convex, outward faces.

Multiply the belief by the evidence

Three bar pairs: prior, likelihood, posterior. Pick a scene, then move the prior and the strength of the image evidence. Find the evidence that flips the verdict.

95%
equal

Illustrative numbers: the priors are our own picks, not measured. Likelihood of B is fixed at 0.20 and of A is 0.20 times the evidence ratio. The rule and the two scenes are the lecture’s.

Run the numbers for the hollow face with a prior of 97% for convex. The images are equally likely, 0.20 each. Products: 0.20 × 0.97 = 0.194 for convex, and 0.20 × 0.03 = 0.006 for concave. Z = 0.200. Posteriors: 97% and 3%. The prior wins outright.

Now let the video lean toward concave, ten to one: likelihoods 0.02 and 0.20. Products: 0.0194 and 0.0060. Z = 0.0254. Posterior for convex: 0.0194 / 0.0254 = 76%. Still convex. Evidence of 10 to 1 does not beat a prior of 32 to 1. To tie, the evidence must favour concave by 32 to 1.

That is the failure mode, read as a measurement. Symptom: you see a bulging face on a hollow mask. Measurement: the ratio of posteriors equals the ratio of priors times the ratio of likelihoods. Fix: add evidence that points the other way, such as a second view, because independent evidence multiplies in. Take a look at Bayes’ rule and Bayes estimation for more depth.

Evidence stacks by multiplication

Independent pieces of evidence multiply. Say the video of the hollow mask gives a second, different view, and each view favours concave by 10 to 1. The likelihood ratio for the pair is 10 × 10 = 100 to 1. Now convex gets 0.97 / (0.97 + 0.03 × 100) = 0.97 / 3.97, which is 24%. One view left the prior in charge at 76%. Two views flip the verdict.

This is the practical meaning of the 32 to 1 threshold. You do not need one miracle of evidence. You need a handful of ordinary pieces. A moving head gives a fresh view every moment, and the prior loses its grip.

A computer adds logarithms instead of multiplying, for the reason you may know from other lessons: products of many small numbers fall to zero. In log form, log posterior = log prior + sum of log likelihoods. For spikes the likelihood of a whole spike train is a product over bins, so a decoder sums one log term per bin. Twenty bins of mild evidence add up like a single strong clue.

Two honest limits. The priors in the device are made up, so the 97% is a teaching number, not a measurement. And the lecture draws only two worlds. Real scenes have endless possible worlds, and the posterior must be spread over all of them. That is the reason the course later needs approximate inference.

Two worlds make exactly the same image, so their likelihoods are equal. The prior for A is 80% and for B is 20%. What is the posterior for A?

Chapter 6

Replacing Neurons

Watch a chip split sound into frequencies the way the inner ear does, and see why that counts as evidence that the brain computes

A child who was born deaf receives a small device. A microphone behind the ear picks up speech. Minutes later, a row of electrodes inside the inner ear begins to send tiny pulses to the auditory nerve. The child hears.

No one copied the inner ear’s cells. The device is made of silicon and wire. Yet it works. That is the last piece of evidence in the lecture that the brain is a computer, and it is the one with the strongest practical result.

Same maths, different parts

The slide on neural prostheses says it directly. Neurons can be replaced by other entities, such as silicon chips, that have a different physical structure but carry out the same, or similar, mathematical operations. The organism then produces the same behaviour.

The cochlear implant is the lecture’s example. A microphone sends sound to a transmitter outside the head. A receiver under the skin passes it to an electrode array, a row of tiny contacts threaded into the cochlea, the coiled hearing organ. The slide gives the key line: the chip performs a Fourier transform and stimulates the right location in the cochlea for each frequency.

The slide adds two facts. The FDA approved the implant in 1984. There were 737,000 recipients in total through 2019.

What the chip computes

A Fourier transform splits a sound into pure tones. Any sound is a sum of sine waves of different frequencies. The transform answers one question for each frequency: how much of this sine wave is in the signal?

The answer is a dot product, which Chapter 8 defines. Take N samples of the sound. For each frequency number k, multiply the samples by a sine wave and a cosine wave of that frequency, and add up the products. A big sum means that frequency is present.

Xk
How much of frequency number k the sound contains. Its size is the strength of that tone.
∑n=0N−1
Add up over all N samples, from the first (n = 0) to the last.
xn
Sample number n of the sound: the microphone’s voltage at that moment.
e−2πi·kn/N
A cosine and a sine wave of k cycles across the window, packed into one complex number. It is the probe that the samples are compared with.

Here are the real numbers. The toy device below samples 8,000 times per second and takes N = 512 samples, which is 64 ms of sound. Each frequency step is 8,000 / 512 = 15.6 Hz. A 600 Hz tone sits near step 38. The transform gives a large value there and near zero elsewhere.

The chip then groups the steps into bands, one for each electrode, spaced evenly in pitch. Low pitches go to electrodes near the far tip of the cochlea, the apex. High pitches go near the entrance, the base. That is the hearing organ’s own map, with frequency laid out along its length.

Turn a sound into electrode currents

Top: 32 ms of the sound wave. Middle: the strength in each of 16 bands. Bottom: the 16 electrodes, apex (low pitch) to base (high pitch). Switch tones on and off, then add noise.

0.00

The transform is computed live in your browser on 512 samples with a Hann window, and the bands run from 100 Hz to 4,000 Hz in 16 equal steps of pitch. Sixteen electrodes is a toy choice, not a device specification. The Fourier-transform design is the lecture’s.

Switch on the hum and the whistle. Two bars rise, one near electrode 2 and one near electrode 14. Switch on the voice tone and a third bar appears near electrode 8. Now raise the noise. Each bar gets a small floor, but the tones still stand out. Symptom: a hissy signal. Measurement: the bars show tones against the floor. Fix: the chip reads the peaks, not the whole waveform.

The other direction

The implant writes into the brain. The lecture’s next two slides show the opposite direction: direct neural control of movement, from the Schwartz lab at Pittsburgh. The pictures show a monkey and a robotic arm. Spikes are recorded, a program turns them into a movement command, and the arm moves.

Put the two together and you get the lecture’s picture of interchangeability: sensory input, the brain, motor output. If we understand the mathematical operations that parts of the brain carry out, we could in theory replace them with new parts that perform the same computations. Chapter 7 shows how we record, and Linear Decoders shows the simplest movement decoder.

That also explains the slide that says our goal: figure out how the brain works. Replacement is the strictest test. A model that only describes cannot replace anything.

The window trade-off again

The transform has a cost that echoes Chapter 1. The device takes N = 512 samples at 8,000 per second, so each frequency step is 8,000 / 512 = 15.6 Hz wide. Two tones closer than about one step blur together. A 150 Hz hum and a 170 Hz hum are 20 Hz apart, so they just separate. Halve the window to N = 256 and the step doubles to 31.3 Hz, and they merge.

So a long window gives sharp pitch and a late answer. A short window gives a fast answer and blurry pitch. Speech changes in tens of milliseconds, so a device must choose a window to match. This is the same bargain as the counting window of Chapter 1, with frequency in place of rate.

One more fact explains the top band. Sampling 8,000 times per second can only represent tones up to half that rate, 4,000 Hz. Anything higher folds back as a false lower tone. That is why the toy stops at 4,000 Hz. A real device filters the sound before sampling to avoid the fold.

Look at the data flow end to end. The microphone gives a stream of samples, shape (512) per window. The transform gives 256 strengths. Grouping gives 16 band levels. The electrode stage turns each level into a current, shape (16). Each step shrinks the data, and each keeps the one thing the nerve needs: which places should fire, and how hard.

In the toy implant, a 600 Hz tone and a 2,400 Hz tone play together. What do the electrodes do?

Chapter 7

Recording at Scale

Count how many cells each tool can hear, and see why every recording becomes a matrix of numbers

Picture a thin dark needle pressed into orange-stained brain tissue. A single cell hangs next to its tip. That needle is a tungsten electrode, the tool behind the recording in Chapter 0. It listens to one neuron at a time.

The lecture sets that needle against a huge number. It shows a piece of brain tissue with a scale bar of 10 microns and says: there are about 10 billion cubes of this size in your brain. The needle hears one spot.

Three tools, three scales

The lecture then climbs up in three steps. A tungsten electrode is one wire, and it hears one neuron at a time. A Utah array is a small bed of needles with 96 channels. The slide credits Kelly, Smith, Samonds, Kohn, Bonds and Movshon (2007). A Neuropixel probe is a long thin shank with about 1,000 electrodes.

A channel is one wire that carries one voltage. A channel can pick up spikes from more than one nearby cell, so channels and neurons are not the same count. Separating them is its own job, called spike sorting, and Spike Sorting covers it.

Now put the numbers side by side. One electrode against 10 billion cubes: one in 10 billion. A Utah array: about one in 100 million. A Neuropixel probe: one in 10 million. Each step is a leap of tens or hundreds, and still we see a sliver.

Why this is a good time

The lecture closes its pitch with three reasons. We are now getting incredible data. Computers are getting extremely fast. And advances in statistical and mathematical techniques are allowing us to gain a deep understanding of neural data and neural information processing. That sentence is the course in short.

A recording is a matrix

Here is what a probe hands you. Cut the recording into short time bins, say 1 ms each. For each channel and each bin, count the spikes. Write the counts in a table: one row per channel, one column per bin. That table is a matrix.

Take a tiny example. Three channels, one 10 ms bin: channel 1 fired twice, channel 2 not at all, channel 3 five times. The column is (2, 0, 5). That is a vector: a list of numbers read as one object. Each time bin gives one such vector, a snapshot of the whole population.

Stack 1,000 such snapshots side by side and you get a 3 × 1,000 matrix. Real recordings have the same shape with a bigger first number. This is why the lecture ends with linear algebra. The rest of the course speaks about neural data in rows, columns and dot products.

Pick a probe, fill a matrix

Top: one second of spikes from every channel, one row each. Middle: a ruler from 1 to 10 billion cubes. Choose a tool, then lengthen the recording.

10 s

Channel counts and the 10 billion cubes are the slides’ numbers. The slide counts about 1,000 electrodes on a Neuropixel probe, and how many record at once depends on the probe, so the toy uses 1,000. Spikes are random and seeded. Only the first 100 channels are drawn.

Choose the Neuropixel probe and set 60 s. At 1 ms bins the matrix has 1,000 rows and 60,000 columns. That is 60,000,000 numbers from one minute. A tungsten electrode over the same minute gives 1 × 60,000 = 60,000 numbers. The jump in size is why the course insists on code.

The failure mode is subtle. Symptom: even with 1,000 channels you have seen one cell in 10 million. Measurement: the ruler. Fix: models that infer what you did not record. A latent factor model, from Chapter 0, bets that hidden dials drive many cells together, so a sliver can reveal the dials.

The last two slides of the lecture say what to do next: review the linear algebra from notes, a review video and handouts. They list the topics that fill the next three chapters: vectors, norms, dot products, projection, matrices, rank and null space.

How big is the raw stream?

Count the data at each stage. Say each of 1,000 channels is sampled 30,000 times per second with 2 bytes per sample. That is 1,000 × 30,000 × 2 = 60 million bytes per second, 60 MB. These numbers are illustrative. An hour is 216 GB.

Now detect spikes and count them in 1 ms bins, one byte each. That is 1,000 × 1,000 = 1 million bytes per second, 1 MB. The reduction is 60 to 1, and it keeps what the models in this course use. Detecting and sorting spikes is a field of its own, and the bins hide a choice: finer bins keep timing and cost size.

Why does the shape matter beyond storage? The matrix is wide: 1,000 rows and many thousands of columns. But the cells are not independent. If 5 hidden dials drive all 1,000 cells, the matrix looks like a thing with only 5 independent directions, plus noise. In Chapter 10 that count is the rank. Methods such as PCA find the directions from the data.

So the question for a modeller is not only “how many cells?” but “how many dials?” A thousand cells with five dials hold less news than their count suggests. That is good news: a sliver of the brain may be enough to read the dials, and bad news if the dials are the thing you did not record.

You record 96 channels for 5 s in 1 ms bins. What shape is the spike count matrix, with one row per channel?

Chapter 8

Vectors: A Population as One Arrow

Read a snapshot of many neurons as a single arrow, then measure its length, its angle to another arrow and its shadow

Three neurons are recorded for 10 ms. The first fires twice, the second not at all, the third five times. Write that as (2, 0, 5). You have just made a vector: a list of N numbers, called its components, that you treat as one object.

The review slides start the same way. A vector is N numbers. In two or three dimensions you can draw it as an arrow. In higher dimensions, the slide draws it as a row of N bars, a “spike” picture. For neural data the bar picture is natural: each bar is one cell’s count.

Writing and combining vectors

A column vector stands the numbers in a column. Its transpose lays them in a row. The slide shows the Python: v = np.array([[3], [1], [-7]]) makes a column, and v.T flips it. A plain np.array([3, 1, -7]) makes a one dimensional vector that is neither.

To add two vectors, add matching components. Geometrically, you slide one arrow so its tail sits on the other’s tip, and the sum runs from start to end. To scale a vector, multiply every component by a number. Doubling the vector doubles its length and keeps its direction.

Length, direction and the unit vector

The norm is the length of the arrow. The review calls it the L2 norm. In 2D it is the Pythagoras formula, the square root of v12 + v22. In N dimensions you add all the squares. The slide’s example is v = (1, 7, 3, 0, 1). The squares add to 1 + 49 + 9 + 0 + 1 = 60, so the norm is about 7.75. Python has five ways to write it: np.linalg.norm(v), np.sqrt(v @ v), and more.

A unit vector has norm 1. In 2D, every unit vector is (cos θ, sin θ) for some angle θ, because cos2 θ + sin2 θ = 1. In N dimensions, the unit vectors sit on the surface of a hypersphere. To make any vector into a unit vector, divide it by its norm. The result keeps the direction and drops the size.

The dot product

The inner product, or dot product, turns two vectors into one number. Multiply matching components and add. There is an equal definition with geometry in it.

v · w
The dot product: one number from two vectors.
∑n vn wn
The recipe: multiply each pair of matching components, then add. The slide also writes it as vTw.
‖v‖ ‖w‖
The two lengths multiplied.
cos φ
The cosine of the angle between the arrows: 1 if they point the same way, 0 at a right angle, −1 if opposite.

Three facts follow. Perpendicular vectors have dot product 0. Parallel vectors give the product of their norms. A vector dotted with itself gives its norm squared.

The slide adds a habit of mind: think of one vector as an operator and the other as an input. Dot any v with w = (1/N, ..., 1/N) and you get the mean of v’s components. Dot with (1, 0, ..., 0) and you get v1. Any weighted sum of cell counts is a dot product with a weight vector. That is a decoder.

Projection and orthogonality

The linear projection of v onto a direction is its shadow, dropped down at a right angle. If û is a unit vector, the shadow has length v · û, and the shadow vector is (v · û) û. What is left over, v minus the shadow, is perpendicular to û. For a vector u that is not unit length, the shadow length is v · u divided by the norm of u.

Two vectors are orthogonal, the slide’s word for perpendicular, when their dot product is zero. In neural terms, two activity patterns that are orthogonal share nothing: one cell can only be big where the other is zero.

Drop a shadow

The pink arrow v is a two-cell population vector. The teal line is the direction û. The shadow lies on the line. The dashed leftover meets the line at a right angle.

6.0
3.0
30°

Toy numbers: negative components stand for a change in a cell’s count from its average, since a raw count cannot be below zero. The geometry (shadow length v · û, leftover at a right angle) is the review’s.

Work the starting setting by hand. v = (6, 3), so the norm is the square root of 36 + 9, which is 6.71. The direction is 30°, so û = (0.866, 0.500). Dot product: 6 × 0.866 + 3 × 0.500 = 5.20 + 1.50 = 6.70. The shadow vector is 6.70 × (0.866, 0.500) = (5.80, 3.35). The leftover is (0.20, −0.35), with length 0.40. Check: 6.702 + 0.402 = 45.0, which is 6.712.

Press Make v perpendicular. The shadow shrinks to zero and the dot product reads 0. Press Make v parallel and the leftover vanishes. Press Scale v to length 1 and the arrow lands on the dashed unit circle.

Linear combinations and independence

A linear combination scales some vectors and adds them. The review defines a set of vectors as linearly dependent if one of them can be written as a combination of the others. It is linearly independent if the only way to combine them into the zero vector is to scale every one of them by zero. Two arrows on one line are dependent. Two arrows off a line are independent.

Now the failure mode. Symptom: two population patterns have a large dot product just because the cells fire a lot. Measurement: the dot product equals the two norms times the cosine, so lengths inflate it. Fix: divide each vector by its norm first. The dot product of the unit vectors is the cosine itself, which measures only the angle. PCA uses exactly this projection to find the direction of greatest spread, and neural manifolds applies it to populations. The linear algebra workbook has more drills.

Similar, or just loud?

Work a small case on population patterns. Let p = (4, 2, 0), q = (8, 4, 0), r = (0, 2, 4) and s = (40, 20, 0). The norms are 4.47, 8.94, 4.47 and 44.7. The dot products with p are p · q = 40, p · r = 4 and p · s = 200.

By raw dot product, s looks 50 times closer to p than r does, and 5 times closer than q. But q and s are the same pattern as p, only louder: each is a scaled copy. The cosine fixes this. cos(p, q) = 40 / (4.47 × 8.94) = 1.00. cos(p, s) = 200 / (4.47 × 44.7) = 1.00. And cos(p, r) = 4 / (4.47 × 4.47) = 0.20. Now the numbers say what we mean: q and s match p, and r mostly does not.

In code the same fix is two lines: divide each vector by its norm, then take the dot. The shapes stay simple. A population with N = 100 cells is a vector of shape (100). Its norm is one number. A weight vector w has the same shape, and w · v is a scalar, the decoder’s answer for that time bin. With w = (1/100, ..., 1/100) the answer is the mean count. With all the weight on one cell, it is that cell alone.

This is why the slides call a vector an operator when it sits on the left of a dot product. A decoder is nothing more than a weight vector, and a good one is a direction in the space of population patterns along which the stimulus changes the most.

v = (3, 4) and û = (1, 0). What is the length of the shadow of v on û, and what is the leftover?

Chapter 9

Matrices: Two Ways to Multiply

Learn to read a matrix as a table of cells and time bins, and see why one product can be computed as dots or as a mixture

You have 3 cells and 1,000 time bins. Write the spike counts in a table: three rows, 1,000 columns. Read down a column and you see the whole population at one moment. Read along a row and you see one cell over time.

That table is an n × m matrix, with n rows and m columns. The review says to think of it two ways: as m column vectors side by side, or as n row vectors stacked. Both pictures are true at once, and the next idea depends on switching between them.

A matrix times a vector, two ways

Suppose a weight matrix A says how three input signals drive three output cells. Row i holds the weights into cell i. Feed in x, the three input values. The output y = Ax is another vector, one number per cell. The review gives two ways to compute it.

View one: dot with each row. Output i is the dot product of row i of A with x. Each output is one weighted sum, a decoder. View two: mix the columns. Scale column j of A by xj and add up the scaled columns. The input values are the mixing amounts.

A x
The matrix times the vector. The result has one entry for each row of A.
x1 c1 + …
View two: a linear combination of the columns cj of A, with the entries of x as the amounts.
( ri · x )i
View one: the list of dot products of each row ri with x.

Try it with real numbers. Step through the product, then switch views. The answer never changes. Only the route does.

Multiply it step by step

Pick a view, set the three input values, then press Step. The warm numbers are the answer as it builds. The outer product view builds a matrix from two vectors.

2
1
3

Toy numbers: A has rows (1, 2, 0), (0, 1, 1), (2, 0, 1). In the outer product view, u = (1, 2, 3) is a made-up tuning of three cells, and the three inputs are a time course over three bins. The two views of A x are the review’s.

With the starting inputs x = (2, 1, 3): row 1 gives 1×2 + 2×1 + 0×3 = 4. Row 2 gives 0 + 1 + 3 = 4. Row 3 gives 4 + 0 + 3 = 7. By columns: 2 × (1, 0, 2) + 1 × (2, 1, 0) + 3 × (0, 1, 1) = (2, 0, 4) + (2, 1, 0) + (0, 3, 3) = (4, 4, 7). The same vector, as promised.

A matrix times a matrix

Matrix times matrix is the same idea repeated. The product AB applies A to each column of B. Equally, entry (i, j) of AB is the dot product of row i of A with column j of B. This only works when the inner sizes match: an m × n matrix times an n × k matrix gives an m × k matrix.

The review drills the shapes with questions. A 1 × n row times an n × 1 column gives a 1 × 1 number: the inner product again. A 1 × n row times an n × k matrix gives a 1 × k row. And an m × 1 column times a 1 × k row gives an m × k matrix, called the outer product.

Try the outer product with u = (1, 2, 3) for three cells and v = (1, 0, 2, 1) for four time bins. Row i of the result is ui times v. You get rows (1, 0, 2, 1), (2, 0, 4, 2) and (3, 0, 6, 3). Every cell has the same time course, just louder. A raster built that way is the simplest neural model, and the next chapter calls it rank one.

Rules, transpose, inverse and trace

Two rules matter. Multiplication is associative: A(BC) = (AB)C. It is not commutative: AB is usually not BA. With A = [[1, 2], [0, 1]] and B = [[1, 0], [3, 1]], AB is [[7, 2], [3, 1]] but BA is [[1, 2], [3, 7]]. Symptom: a shape error or a different answer. Measurement: write the shapes. Fix: keep the order.

The transpose flips a matrix about its diagonal, so rows become columns. A symmetric matrix equals its transpose and must be square. The inverse of a square matrix A, when it exists, is the matrix A−1 with A−1A = I, where I is the identity, which leaves every vector unchanged. Two facts about products: (AB)T = BTAT, and (AB)−1 = B−1A−1. Order flips in both.

The trace adds the diagonal entries. Two facts: Tr(ABC) = Tr(CAB) = Tr(BCA), a circular shift that you may not scramble, and the trace equals the sum of the eigenvalues. See eigenvalues for those.

Unmixing and the inverse

Here is a use of the inverse that you will meet in the course. Two electrodes each hear a blend of two cells. Let the blend be A = [[2, 1], [1, 1]], so electrode 1 hears twice cell 1 plus cell 2. The cells’ true rates are x. The electrodes report y = Ax.

Suppose the electrodes read y = (5, 3). To recover x you need A−1. For this A the determinant is 2 × 1 − 1 × 1 = 1, and the inverse is [[1, −1], [−1, 2]]. Check by multiplying: the top row of A times the first column of the inverse is 2 × 1 + 1 × (−1) = 1, the top row times the second column is 2 × (−1) + 1 × 2 = 0, and the bottom row gives 0 and 1. That is the identity. Now x = A−1y = (5 − 3, −5 + 6) = (2, 1). Test: A(2, 1) = (5, 3). It works.

The trace gives a quick sanity check here: Tr(A) = 2 + 1 = 3, and the two eigenvalues of A, (3 + √5)/2 and (3 − √5)/2, add to 3. The next chapter explains when the inverse does not exist.

Now the realization for neural data. A decoder over time is a matrix product. Take the data X with shape (N, T) and a weight vector w with shape (N). Then wTX has shape (1 × N)(N × T) = (1 × T), one decoded number per bin. Swap the order and the shapes do not match, so the code fails loudly. That is the shape rule doing its job as a bug catcher. Before you debug anything else, write the shapes on paper.

A is 4 × 3 and B is 3 × 5. What is the shape of AB, and is BA defined?

Chapter 10

Spaces: Rank and the Null Space

Find out which stimuli a pair of cells can see, which they cannot, and how many separate numbers they can report

Two neurons look at the same two features of a scene, say brightness and contrast. Neuron 1 adds brightness to twice the contrast. Neuron 2 does the same thing, only louder. The two cells have different spikes, but they carry the same message.

Is there a stimulus that neither cell notices? Yes: one where the brightness and the contrast cancel. Finding such directions is the work of this chapter, and the review slides give the tools.

Span, basis and subspace

The review defines a vector space as the set of all points you can reach by linear combinations of some set of vectors. Span is the verb for that: the vectors span the space. A basis is a set of linearly independent vectors that span the space. It is the smallest set that still reaches everywhere.

The slide draws two examples. One vector alone spans a line, which is a one dimensional subspace of the plane: a vector space that sits inside a bigger one. Two independent vectors span the whole plane, and the same plane has many different bases. A basis is a choice of axes, not a fact about the plane.

An orthonormal basis is a basis of orthogonal unit vectors: arrows at right angles, each of length 1. The ordinary x and y axes are one. Rotate them and you get another. An orthogonal matrix B is a square matrix whose columns are an orthonormal basis. The slide lists its properties.

BTB = B BT = I
The columns are orthonormal, so every dot product between different columns is 0 and every column dotted with itself is 1.
B−1 = BT
To undo B you only need to flip it. No hard inversion is needed.
‖B v‖ = ‖v‖
B preserves length. It rotates or reflects a vector and never stretches it.

Rank and the three spaces

The rank of a matrix is the number of linearly independent columns. Remarkably, it also equals the number of independent rows. Put another way, it is the dimension of the space spanned by the columns or by the rows. For an m × n matrix, rank ≤ min(m, n).

Three spaces come with every matrix W. The column space is everything W can output: all combinations of its columns. The row space is everything spanned by its rows. The null space is every input x that W sends to zero: Wx = 0. Because Wx = 0 means every row dotted with x is zero, the null space is orthogonal to the row space. Together they fill the input space.

For a neural reading, let y = Wx. The input x is a stimulus, and row i of W is cell i’s tuning. The null space is the set of stimuli the whole population is blind to. The column space is the set of response patterns the population can ever produce. The rank is how many independent numbers the population can report.

Find what two cells cannot see

Left: stimulus space, with the stimulus x on the unit circle. Right: response space, with y = Wx. Press a preset, then turn the stimulus angle until the response is zero.

1.0
0.5
−0.4
1.0
40°

Toy matrices: the entries are made-up tuning weights, held between −2 and 2. A matrix counts as rank 1 here when its determinant is within 0.03 of zero. The definitions of rank and the three spaces are the review’s.

Press Copy cell. The rows are (1, 2) and (0.5, 1), and the second is half the first. Rank 1. The null space is the line of x with x1 + 2x2 = 0, which has direction (2, −1). Test x = (2, −1): the first row gives 2 − 2 = 0 and the second gives 1 − 1 = 0. The response is zero, even though the stimulus is not.

The column space is now a line, the multiples of (1, 0.5). Every response lies on that line. The two cells report one number, not two. Press Rotation and the opposite happens. The rank is 2, the null space is only the zero vector, and the response arrow always has length 1, since an orthogonal matrix preserves length.

This is the failure mode with a name. Symptom: two cells look different, but a decoder cannot tell some stimuli apart. Measurement: the rank is 1, and the null space is a line of stimuli with identical zero response. Fix: add a cell with different tuning, or measure another feature. Remember the inverse from Chapter 9: a matrix with a null space has no inverse, so you cannot recover x from y.

Counting dimensions, and a new basis

The three spaces obey a count. The row space and the null space together fill the input space, so their dimensions add to the number of inputs. For a 2 × 2 matrix of rank 2, that is 2 + 0. For rank 1, it is 1 + 1: a line of seen stimuli and a line of unseen ones. For a 100 cell, 3 feature matrix, the rank is at most 3, so 100 cells can report at most 3 independent numbers, and the null space has dimension 3 minus the rank.

On real data the rank is never exactly smaller, because noise fills every direction a little. The practical tool looks at how much each direction matters and calls the small ones zero. Python’s np.linalg.matrix_rank does this with a tolerance. The next lecture explains the numbers it uses.

Finally, a basis is a choice of axes, and an orthonormal basis makes the new coordinates easy: each coordinate is a dot product. Take v = (3, 4) and the rotated basis b1 = (0.6, 0.8), b2 = (−0.8, 0.6). The coordinates are v · b1 = 1.8 + 3.2 = 5 and v · b2 = −2.4 + 2.4 = 0. In the new axes the vector is (5, 0): all of it lies along b1, and its length 5 matches the old length, because rotating preserves length.

That is the idea behind PCA. If the cloud of population patterns lies along one direction, rotate to a basis where that direction is an axis, and the other coordinates are small. You have not changed the data. You have changed the question you ask of it.

A 3 × 3 matrix has rank 2. What does that say about its null space and about inverting it?

Chapter 11

Field Guide: The Lecture on One Page

Keep the numbers, the checklist and the core code, and see where this lecture leads in the rest of the course

The lecture makes one argument and then gives you the algebra to use it. The argument: neurons speak in spikes, spikes are the outputs of computations such as centre minus surround, and the brain combines them with beliefs about the world. Prostheses and probes show we can read and write that language. The algebra turns a recording into vectors and matrices, and gives you rank and null space to say what a population can and cannot report.

The numbers and terms

ItemWhat to rememberWhere
SpikeAll or none. A neuron passes information only through spike times (Adrian).Chapter 1
Rate codeStronger steady stimulus, faster firing. A count in a window estimates the rate with error about the square root of the count.Chapter 1
Centre-surroundThe cell reports centre minus surround. The toy peak is at 0.20 mm, the size where Barlow’s frog cells stopped gaining.Chapter 2
Mach bandsFlat stripes look banded, because cells exaggerate differences at an edge.Chapter 3
PerceptSurface colour is the pixel divided by a guess of the light. Size is image angle times a guess of distance.Chapter 4
BayesPosterior is proportional to likelihood times prior. Equal likelihoods leave the prior in charge.Chapter 5
Cochlear implantA chip does a Fourier transform. FDA approval in 1984. 737,000 recipients through 2019.Chapter 6
ProbesTungsten: 1 neuron. Utah array: 96 channels. Neuropixel: about 1,000 electrodes. Brain: about 10 billion cubes.Chapter 7
Dot productv · w = sum of vnwn = ‖v‖‖w‖cos φ. Zero means orthogonal.Chapter 8
ProjectionShadow of v on unit û is (v · û)û. The leftover is orthogonal to û.Chapter 8
Shapes(m × n)(n × k) = m × k. AB is not BA. (AB)T = BTAT.Chapter 9
RankIndependent columns equals independent rows, at most min(m, n). Null space is orthogonal to the row space.Chapter 10

Checklist

The core as code

pythonimport numpy as np
rng = np.random.default_rng(0)

# a recording: 3 cells x 1000 bins, rows are cells. tuning (3,) outer time course (1000,) is rank one
rates  = np.outer([1, 2, 3], np.ones(1000)) * 0.02     # (3, 1000)
counts = rng.poisson(rates)                                        # (3, 1000) spike counts

v = counts[:, 0]                          # one population vector, shape (3,)
u = np.array([1., 2., 3.]); u_hat = u / np.linalg.norm(u)
dot      = v @ u_hat                     # length of the shadow, a scalar
shadow   = dot * u_hat                   # projection, shape (3,)
leftover = v - shadow                    # leftover @ u_hat is ~0
cosine   = (v @ u) / (np.linalg.norm(v) * np.linalg.norm(u))   # angle only, size removed

W = np.array([[1., 2.], [0.5, 1.]])         # two cells, two features
np.linalg.matrix_rank(W)                 # 1: the second cell copies the first
_, s, Vt = np.linalg.svd(W)              # SVD is the next lecture
null = Vt[-1]                         # the stimulus direction W cannot see
W @ null                                 # ~ [0, 0]

prior = np.array([0.97, 0.03]); lik = np.array([0.20, 0.20])
post = prior * lik; post /= post.sum()   # Bayes: [0.97, 0.03], equal likelihoods cancel

Read it line by line. The first block makes the matrix of Chapter 7 and shows that an outer product (Chapter 9) gives a rank one raster. The second block is Chapter 8 in five lines. The third is Chapter 10: the rank, and the direction in the null space. The last is Chapter 5.

Where this sits

This lecture is the first of NEU 560, Statistical Modeling and Analysis of Neural Data, taught by Jonathan Pillow at Princeton. Everything later leans on the two ideas you met: spikes are noisy data from a computation, and populations are vectors. The next lectures cover the singular value decomposition and PCA, built for this series as Lecture 2, SVD and Lecture 3, PCA.

Later in the course the two families from Chapter 0 take over. Regression becomes generalized linear models, with regularization and Gaussian processes. The latent factor family becomes mixture models and EM, PCA, the hidden Markov model, the Kalman filter with smoothing, and variational auto-encoders. Approximate inference draws on Monte Carlo and importance sampling.

Keep going

The takeaway. A neuron reports a computed difference as spikes, the brain turns spikes into beliefs by Bayes, and a population is a vector in a space whose rank tells you what it can say. Learn the algebra once and the rest of the course reads as variations on it.

Credit. This lesson re-teaches Lecture 1 and the linear algebra review (Lecture 1b) of NEU 560 by Jonathan Pillow at Princeton, with its suggested reading, the introduction to Spikes by Rieke, Warland, de Ruyter van Steveninck and Bialek. We wrote the explanations and built every device ourselves, and we did not copy the course’s slide images. All toy numbers are marked illustrative. Please use the original materials: the course site, the course intro slides and the linear algebra slides.

A recording has 200 channels and 3,000 bins. A decoder takes a weight vector w with one weight per channel. What are the shapes of the data and of the decoder output across time?

Now press Present or Teach and explain one idea out loud, from memory: why a bigger spot can quiet a cell, how a belief beats a picture, or what a null space is. Then go back to the neuron at the top and predict its spikes before you move the lights.

NEU 560 Lecture 1: Course Intro and Linear Algebra
The course site · Course intro slides · Linear algebra slides · Back to Gleams