Two neurons fire together, so their activity has one joint shape. Squash it to forget a neuron, slice it to learn from one, and flip the slice with Bayes’ rule.
Learn the whole probability toolkit that the rest of the course leans on, using spike counts and tuning curves instead of coins and dice.
Press Marginal, then Slice, then drag the slice across the joint and watch the blue bell move. Drag the correlation and see what changes and what does not. Then we build every idea, piece by piece.
You need to know what a probability is (a number from 0 to 1 that says how likely something is) and to read a simple integral as an area. We build the rest from zero.
Based on Lecture 6 of Princeton NEU 560: Statistical Modeling and Analysis of Neural Data (Spring 2024), taught by Jonathan Pillow. Lecture slides. Every idea is re-taught here in our own words and devices.
Toy picture: two neurons with firing rates z-scored (centred at 0, spread 1), jointly Gaussian with the correlation you choose. The formulas are exact for that case: each marginal is a bell of spread 1, and the slice at x is a bell centred at ρx with spread √(1 − ρ2).
Chapter 0
See that choosing a distance to a line is already a claim about where the randomness lives
You record one neuron in visual cortex. You show it a pattern at eight contrast levels and count its spikes in half a second after each showing. Plot spike count against contrast and you get a scatter of dots that drifts upward. Your job is to draw one line through them.
Which line? To pick one, you need a rule for how bad a line is. The natural rule is to measure how far each dot sits from the line, square each distance, and add them up. The best line is the one with the smallest total. But “how far a dot sits from a line” has two honest meanings, and the lecture opens by putting both on the same dots.
The first gap runs straight up or down, from the dot to the line, at the same x. The lecture draws it in red; we draw it in yellow. The second gap runs the shortest way, at a right angle to the line. The lecture draws it in blue, and so do we. The lecture then asks two questions. Which method minimizes which gap? And what is the special name of the red lines?
The answers: least squares minimizes the sum of the squared vertical gaps, and PCA (principal component analysis) minimizes the sum of the squared perpendicular gaps. The vertical gaps have a name: residuals. A residual is what the line failed to predict: the actual value minus the value on the line, at the same x.
Why does least squares measure straight up and down? Because it assumes x is something you set, such as the contrast you chose, with no error at all. All the noise lives in y, the spike count. The only question it asks is: given this x, how far off was y?
PCA asks a different question. Suppose you record two neurons at once, A and B. Neither one is the input. Both are noisy readings of the same underlying activity. Now the line you want is the long axis of the cloud, the direction in which the pair varies most. Distance to that axis is the shortest way across, so the gaps are perpendicular. Our PCA lesson builds this from zero, and the course covers it in Lecture 3 and Lecture 4.
Twelve dots, one line through their centre. Yellow segments are vertical gaps, blue segments are perpendicular gaps. Pick a method, or choose My line and drag the angle to beat it.
Illustrative: twelve made-up dots, seeded so they are the same on every visit, centred so that every candidate line passes through their centre. The sums are exact for these dots; the two best angles are the closed-form answers (slope Sxy/Sxx for least squares, the top eigenvector of the 2 × 2 covariance for PCA).
Slide the angle by hand and you will find two different best angles. The least squares line is flatter. It never tries to chase the dots sideways, because sideways error does not count. The PCA line is steeper, because it cuts through the cloud along its long axis. Both are right, for different questions.
Here is the point of the warmup. “Vertical gaps” is a hidden sentence: y equals the line plus random noise, and x is exact. “Perpendicular gaps” is a different sentence: both coordinates are random readings of something underneath. Each sentence is a statement about probability. To say it clearly, we need the words of probability.
That is what this lecture supplies. It is a review of 48 slides, and the course lists no reading for it. Pillow walks through seven ideas, and the last slide lists them: continuous and discrete distributions, marginalization, conditionalization, Bayes’ rule, expectations and moments, Monte Carlo integration, and independence versus correlation. Every later lecture on spikes, tuning and decoding uses them.
A probability is a number from 0 to 1 that says how likely something is. 0 means never and 1 means always. A distribution is a list of every possible outcome with its probability, and the list must add up to 1, because something always happens.
For a neuron in a 100 ms window, the outcomes could be 0 spikes, 1 spike, 2 spikes, and so on. A distribution says, say, 40% for zero, 35% for one, 25% for two or more. Everything else in this lesson is a way to build, combine and read such lists.
Chapter 1
Turn a model into samples, then turn samples back into a guess about the model
A neuron sits in a dish, and each 10 ms it either fires or stays quiet. You do not know how eager it is. You record 40 bins and see 14 spikes. What can you say about the neuron? And if a colleague tells you its eagerness, what can you say about the next 40 bins?
These are two different questions, and the lecture draws them with one picture: three boxes in a row. On the left is the parameter, written θ, the dial that sets how the neuron behaves. In the middle is the model, written P(x | θ), a rule that says how likely each outcome is when the dial reads θ. On the right are the samples, written X, the data that come out.
Take the dial first. For a spike in a 10 ms bin, θ is the chance of a spike, say 0.3. The model is a weighted coin: spike with chance 0.3, quiet with chance 0.7. Hand someone θ and the model, and they can predict what a recording will look like. Most bins quiet, about three in ten with a spike.
The lecture names the words that belong to the right-hand box. The model is a probability distribution. A single outcome set, such as “at least 3 spikes in this window”, is an event. A quantity whose value is set by chance, such as the spike count in the window, is a random variable. We write it as a capital letter, X, and its observed value as a small letter, x.
The lecture also draws two ovals: the parameter space, every dial setting that is allowed, and the sample space, every outcome that could come out. For the weighted coin, the parameter space is the numbers from 0 to 1. The sample space is every possible string of spikes and quiet bins. Probability is the study of the arrow from a point in the first oval to a distribution over the second.
Now flip the arrow. You hold the data and want the dial. The lecture shows a sequence of 17 coin flips: T, T, H, T, H, T, T, T, T, H, T, H, T, H, H, T, T. Read H as a spike. That is 6 spikes in 17 bins, a rate of 6/17, or 0.35. What was θ?
You cannot know for sure. But you can ask how well each candidate dial explains what you saw. Compute P(data | θ) for θ = 0.3. Each spike contributes a factor of 0.3, each quiet bin a factor of 0.7, so the answer is 0.36 × 0.711 = 1.44 × 10−5. Do the same at θ = 6/17 and you get 1.61 × 10−5. The second dial makes this particular recording a little more likely, about 1.12 times as likely.
Read P(x | θ) with x held fixed and θ free, and it has a new name: the likelihood of θ. It is the same formula as the model, read from the other side. The lecture attributes the idea to Fisher, who called this direction “inverse probability”. We now call it statistics: infer the parameter from the samples.
One warning. The likelihood is not a probability of θ. Add it up over all dials and the total is not 1. It only ranks dials against each other. Chapter 5 shows how Bayes’ rule turns it into a real probability of θ.
Try both directions below. The slider sets the true θ and writes a spike train. The lower curve then throws the dial away and asks which θ the train supports.
Top: spikes (blue ticks) drawn forward from the true dial. Bottom: the likelihood of every candidate dial, working backward from those spikes. Change the dial, the length, or draw a fresh train.
Illustrative: each bin fires when a stored random number falls below θ, so moving the slider changes the same noise into a different train. The curve is the binomial likelihood θk(1 − θ)n−k, scaled so its peak is 1. The 6 of 17 example and its two likelihoods come from the lecture’s flip sequence.
With 10 bins the curve is a wide hill: many dials explain the train about equally well. With 160 bins it is a narrow spike around the observed rate, and the true dial sits close to the top. More data narrow the backward question. The forward question never needed data, only the dial.
A last shape to remember. Forward, one dial leads to many possible samples. Backward, one set of samples leads to many possible dials, ranked by likelihood. The rest of the course is mostly about doing the backward step well.
Chapter 2
Separate counting outcomes from measuring them, and meet the six distributions neural data keeps using
A neuron fires 0, 1, 2 or 3 spikes in a window. You can list those outcomes and give each one a probability. Now measure the time between two spikes. It could be 12.0 ms, or 12.01 ms, or 12.0001 ms. You cannot list the outcomes, because there is always another one between any two. These two situations need two tools.
A discrete random variable takes a finite or countable set of values: 0, 1, 2, and so on. Its probability mass function (pmf), written f(x), gives the probability of each value directly. The lecture states two facts. The probability that x equals a is f(a). And the pmf adds up to 1: f(x1) + f(x2) + … = 1.
Picture a bar chart. Each bar is a probability. The bar heights add to 1. Nothing else is needed.
A continuous random variable lives on a smooth range, such as all real numbers. Here the lecture states a fact that surprises everyone once: the probability that x equals exactly a is zero. Pick any single number and the chance of hitting it exactly is nil.
So a continuous distribution does not give probabilities at points. It gives a probability density function (pdf), also written f(x), and probabilities are areas under it. The chance that x falls between a and b is the area under f from a to b. The total area is 1.
A worked case. Take the standard bell curve (mean 0, spread 1). Its height at x = 0 is 0.399. That does not mean a 39.9% chance of exactly 0; that chance is zero. The chance of landing between 0.5 and 1.5 is the area over that stretch: 0.2417. Density says how crowded the probability is near a point. Area says how much probability there is.
The lecture then lists “some friendly neighbourhood distributions”. Three are continuous. Three are discrete. We give each a neural job.
That last line deserves a pause, because it says where the Poisson comes from. Cut a second into n bins so small that each holds at most one spike. Give each bin a spike chance of λ/n, so that the expected count stays λ. Add up the spikes: a binomial. Now cut the bins smaller and smaller. The binomial settles into one fixed shape, the Poisson, with pmf λk e−λ / k!.
Take λ = 4 expected spikes. The Poisson gives the chance of no spikes as e−4 = 0.0183, and the chance of exactly 4 spikes as 44 e−4 / 4! = 0.1954. Watch the binomial grow into it.
Blue bars: the count of spikes among n bins, each with chance 4/n. Warm dots: the Poisson with the same average of 4. Drag n up and watch the bars settle onto the dots.
Exact, not simulated: the bars are the binomial pmf with n bins and spike chance 4/n; the dots are the Poisson pmf with mean 4. The gap is the total variation distance, half the sum of the absolute differences over every count.
At n = 5 the two shapes differ a lot, and the binomial cannot count above 5. At n = 100 they are almost the same. The Poisson has one parameter, the rate, and its variance equals its mean. A real neuron whose count varies more than its mean breaks that rule, and that gap is a useful clue about the neuron.
Chapter 3
Describe two neurons at once, then forget one of them by adding across its values
Two electrodes sit in the same patch of cortex. Neuron A and neuron B each fire some number of spikes in every 100 ms window. After a thousand windows you build a tally: how many windows had A at 0 and B at 0, how many had A at 0 and B at 1, and so on. Divide each tally by a thousand and you have a table of probabilities.
That table is a joint distribution, written P(x, y). Each cell is the probability that A shows x spikes and B shows y spikes in the same window. The lecture states two rules for it. Every cell is positive, and all the cells together add up to 1.
For continuous variables, the table becomes a picture. The lecture draws a joint density as a grey-scale image: x across, y up, and brightness for density. A bright diagonal ridge means the two variables rise together. The sum of cells turns into a double integral, ∫∫ P(x, y) dx dy = 1: the total volume under the surface is 1.
Now suppose you never recorded B. You still want to know how A behaves. The answer is hiding inside the table. For each value of A, add up the cells over every possible value of B. The result is the probability of A alone.
A tiny table makes the arithmetic plain. Call each neuron quiet or active in a window. The illustrative joint is: both quiet 0.40, A quiet and B active 0.10, A active and B quiet 0.15, both active 0.35. These four add to 1.
The chance that A is quiet is the first row added across: 0.40 + 0.10 = 0.50. The chance that A is active is 0.15 + 0.35 = 0.50. For B, add down the columns: quiet 0.40 + 0.15 = 0.55, active 0.10 + 0.35 = 0.45. Each result is a smaller table of its own, and each adds to 1.
This is marginalization. The formula for continuous variables replaces the sum with an integral:
The lecture also calls this “splatting” (on its last slide) and “integration”. Picture the bright ridge being pushed flat onto the x axis, like paint squeezed against a wall. The pile that results is P(x). Push it onto the y axis instead and you get P(y). The lecture draws the pile in purple, and so do we.
Marginalization is the move that lets you ignore what you did not measure, or what you do not care about. In the tools later in this course it also removes hidden quantities, such as a neuron’s unobserved internal state. The device below has two neurons whose counts share a common input, a slow rise and fall of excitability, so the table has a ridge.
Each square is the probability that neuron A fired x spikes and neuron B fired y spikes. Choose a variable to sum out, then slide along the kept variable. Purple bars are the marginal.
Illustrative model: a shared gain picks one of three levels (low 40%, middle 35%, high 25%); given the level, A and B fire Poisson counts with means (0.8, 1.2), (2.5, 2.0) and (5.0, 3.5), independently. Counts above 11 are dropped and the table is rescaled to add to 1. The sums are exact.
Slide the kept value and watch one purple bar earn its height from a whole column of squares. The joint holds more than the marginals do. Two different joints can share identical marginals, so squashing loses information about how the variables move together. Chapter 8 returns to this.
Compare with the hero. The continuous joint there had a ridge as steep as you liked, and its marginals were identical bells every time. Squashing forgets the ridge.
Chapter 4
Use what you know about one neuron to sharpen what you expect from another
You watch neuron A and see 3 spikes in a window. Neuron B is hidden. What should you expect from B? Before you saw A, your best guess was B’s overall pattern. Now you know something, so the guess should change. The tool that makes the change exact is the conditional distribution.
The idea is simple. You know A = 3. So every window with A at some other value is irrelevant to you. You throw those away and look only at the column of the joint table where A = 3. That column is a slice. The lecture draws it as a vertical line through the density image.
There is a catch. The cells in that column add up to P(A = 3), the marginal from Chapter 3, which might be 0.15. A distribution must add up to 1. The slice has the right shape and the wrong size.
The fix is to rescale. Divide every cell in the column by the column total. The lecture writes it as a fraction and says it in four words: joint divided by marginal.
The lecture shows two slices of one ridge, at x = −1 in blue and x = 1 in red. Each gives a bell curve for y. The blue bell sits low, the red one sits high, because on a ridge that rises, a larger x goes with a larger y. Both are narrower than the purple marginal of y. Knowing x shrinks your uncertainty about y.
Use the small table from Chapter 3: both quiet 0.40, A quiet and B active 0.10, A active and B quiet 0.15, both active 0.35. Suppose A is active. The slice is 0.15 for B quiet and 0.35 for B active. It adds to 0.50, the marginal chance that A is active.
Divide each by 0.50. B quiet becomes 0.30 and B active becomes 0.70. That is P(B | A active). Before you saw A, B was active with chance 0.45. After seeing A active, it is 0.70. After seeing A quiet, the slice is 0.40 and 0.10, which divides by 0.50 to 0.80 and 0.20, so B is active with chance only 0.20.
Now flip the question. Given that B is active, how likely is A active? The slice is 0.10 and 0.35, which adds to 0.45. Divide: 0.35 / 0.45 = 0.78. That is not 0.70. So P(A | B) and P(B | A) are different numbers. The lecture shows both images side by side: P(y | x) normalises every column, and P(x | y) normalises every row.
For the continuous case, the same recipe works on a density. Slice the image at a value of x. The curve you cut has area P(x), a number much less than 1 in general. Divide by that area and the curve has area 1. In the hero at the top of this page, the result is a bell centred at ρx with spread √(1 − ρ2).
Try it on the two-neuron counts. First see the raw slice, then divide.
Warm bars: the raw cells of the joint at the A count you pick. Blue bars: the same cells divided by P(A = x), so they add to 1. The purple dots mark the marginal P(y) for comparison.
Same illustrative two-neuron model as Chapter 3 (shared gain, Poisson counts, table rescaled over counts 0 to 11). The conditional mean is the weighted average of y under the blue bars; the exact sums are computed in your browser.
Slide x upward. When A fires a lot, the blue bars shift right and B is expected to fire a lot too. When A is silent, B is expected to be quiet. The shared gain makes the two neurons rise together, and the conditional is how that relationship shows up as a prediction.
Chapter 5
Read a stimulus off a spike count by turning “spikes given stimulus” into “stimulus given spikes”
A neuron in visual cortex fires 6 spikes. You want to know what the eye was looking at. But all you can measure in the lab is the other direction: show a known stimulus, count the spikes, repeat. That gives you P(spikes | stimulus), the chance of the spikes given the stimulus. The brain, and any decoder, needs P(stimulus | spikes). Bayes’ rule makes the swap.
Start from Chapter 4. A conditional is a joint divided by a marginal, so a joint is a conditional times a marginal. There are two ways to build the joint of x and y. Pick x first, then y given x. Or pick y first, then x given y. The lecture writes both and sets them equal.
Divide both ends by P(y) and you have the rule the lecture names. In its words, the pieces are the likelihood, the prior, the posterior and the normalizer.
Two stimuli, left and right. Left is common: prior 0.8, and right 0.2. A neuron gives at least one spike with chance 0.3 for left and 0.9 for right. You see a spike. Which stimulus was it? The likelihood alone says right: 0.9 against 0.3. But right is rare.
Multiply each likelihood by its prior. Left: 0.3 × 0.8 = 0.24. Right: 0.9 × 0.2 = 0.18. The normalizer is the total, 0.24 + 0.18 = 0.42. Divide: left 0.24 / 0.42 = 0.571, right 0.18 / 0.42 = 0.429. A spike moved right from 0.2 up to 0.43, and did not reach 0.5. The prior held the answer back. This is the entire rule, with every number shown.
The device below uses five stimulus orientations and a Poisson neuron whose preferred orientation is 72°. Slide the spike count and the prior, and watch the posterior swing between the evidence and the expectation.
Three panels over five orientations. Purple: your prior. Warm: the likelihood of the spike count under each orientation. Blue: the posterior. Drag the spike count, then the prior strength.
Illustrative neuron: mean spike count 1.4, 5.1, 10.0, 5.1, 1.4 for orientations 0, 36, 72, 108 and 144 degrees, with Poisson counts. The prior mixes a flat prior with one that favours 0 degrees (0.70, 0.15, 0.10, 0.03, 0.02) by the strength you set. All numbers are computed exactly in your browser.
With 6 spikes and a flat prior, the posterior is a near tie between 36° and 72°. Raise the prior strength and mass drains toward 0°, even though that orientation explains 6 spikes poorly. Raise the spike count to 12 and the likelihood overwhelms any prior. Evidence beats belief once it is strong enough.
The lecture then drills the bookkeeping, because every later model chains these moves. Four rules cover it. First, the product rule extends to more variables: P(a, b, c) = P(a | b, c) P(b | c) P(c). Second, marginalizing simply removes a variable: ∫ P(a, b) db = P(a). Third, a variable on the right of the bar “just hangs around”: every rule above still holds if you add the same conditioning variable to every term. For example, P(a, b | d) = P(a | b, d) P(b | d). Fourth, so Bayes’ rule with a hanging variable a reads P(x | y, a) = P(y | x, a) P(x | a) / P(y | a).
Now the lecture’s own test. Try each line before opening the answer.
Chapter 6
Summarise a whole distribution in one number, and see why the mean, the second moment and the variance are one recipe
A neuron fires 1 spike in half of your windows, 2 spikes in 30%, and 3 spikes in 20%. Someone asks: how many spikes does it fire, typically? You cannot say “2” just because 2 is in the middle. Some windows are more common than others, and a fair answer must count them more.
The fair answer is a weighted average. Multiply each value by how probable it is, then add up. For this neuron: 1 × 0.5 + 2 × 0.3 + 3 × 0.2 = 0.5 + 0.6 + 0.6 = 1.7 spikes. That number is not a count the neuron can ever produce. It is the centre of balance of the distribution.
The lecture generalises that recipe. The expectation of a function f of a random variable x is the average of f(x), weighted by how probable each x is under the distribution P. Write it with a double-struck E.
The lecture adds a second view that makes the recipe concrete: it is just a dot product. Stack the probabilities into one vector P and the function values into another vector f, one entry per possible value. Then E[f(x)] = P · f. Multiply entry by entry, then add. For a continuous variable the two vectors are infinitely tall, but nothing else changes.
Choose f(x) = x. The result is the mean, or first moment, E[x]. In the lecture’s example the values are the vector (1, 2, 3) and the probabilities are (0.5, 0.3, 0.2). The dot product is 1.7, as above.
Choose f(x) = x². The result is the second moment, E[x²]. Square the values to get (1, 4, 9) and take the dot product with the same probabilities: 1(0.5) + 4(0.3) + 9(0.2) = 0.5 + 1.2 + 1.8 = 3.5. Large values count for more, because squaring stretches them.
Choose f(x) = (x − E[x])². The result is the variance: the average squared distance between x and its mean. Its square root, the standard deviation, is a typical size of the wobble. Work it out: the distances from 1.7 are −0.7, 0.3 and 1.3. Squared they are 0.49, 0.09 and 1.69. Weighted: 0.49(0.5) + 0.09(0.3) + 1.69(0.2) = 0.245 + 0.027 + 0.338 = 0.61.
There is a shortcut that you can check on these numbers. Variance equals the second moment minus the square of the mean: 3.5 − 1.7² = 3.5 − 2.89 = 0.61. The same answer, with far less arithmetic. For spike counts, the ratio variance divided by mean is called the Fano factor. A Poisson count (Chapter 2) always gives 1.
Play with the weights. The bar at the bottom is the dot product built piece by piece: each segment is one value times its probability.
Pick a function f, then change how often each count occurs. Top: the probabilities (purple) and f at each count (warm). Bottom: three segments, one per count, that add up to the expectation.
The starting weights 5, 3, 2 give the lecture’s probabilities 0.5, 0.3, 0.2 and its answers 1.7 and 3.5. The three counts are illustrative; the weights are rescaled to add to 1. At least one weight must be above 0.
Move all weight onto the count 2. The mean is exactly 2, and the variance falls to 0: nothing wobbles. Spread the weight over 1 and 3 and the variance grows, while the mean may stay near 2. The mean says where the distribution sits. The variance says how wide it is.
Chapter 7
Replace an integral you cannot solve with an average you can run, and learn the one case where the average never settles
Chapter 6 gave you the recipe: multiply by the probability and add up. For a discrete variable with three values, that takes three lines. For a model of a whole neural population, the sum has more terms than there are atoms in a lab, and the integral has no tidy answer. You still want the expectation. What can you do?
You can sample. Ask the model for many random examples, apply f to each, and average. The lecture states the reason in one line: expectation is the average of a function of a random variable. If that is what an expectation means, then an actual average over actual draws should approach it.
The lecture names the method Monte Carlo integration. We want E[f(x)] = ∫ f(x) P(x) dx. The recipe has two steps.
The approximation converges in the limit of N going to infinity. The reason is the law of large numbers: averages of independent draws settle onto the true mean. Our Monte Carlo lesson builds the method in depth, and importance sampling shows what to do when sampling from P itself is hard.
A tiny run by hand. The standard bell curve has E[x²] = 1. Draw five numbers from it, here an illustrative 0.3, −1.2, 0.8, 1.9 and −0.4. Square each: 0.09, 1.44, 0.64, 3.61, 0.16. Add: 5.94. Divide by 5: 1.19. Not exactly 1, but near. With 500 draws the answer would land much closer.
How close? For a function with a finite variance, the typical error shrinks like one over the square root of N. To halve the error, take four times as many samples. For E[x²] of the standard bell, the spread of one draw of x² is about 1.41, so the typical error is about 1.41 / √N: near 0.14 at N = 100 and 0.014 at N = 10,000.
Now the lecture’s warning: expectations do not always exist. Its example is the Cauchy distribution, with density P(x) = 1 / (π(1 + x²)). It looks like a bell, but with heavy tails: far-out values stay much more probable than under a Gaussian. A ratio of two independent zero-mean Gaussian noises is Cauchy, so you meet it any time you divide two noisy numbers.
Try to compute its mean. The integral is ∫ x / (π(1 + x²)) dx over the whole line. The right half grows without bound, because the tail area of x/(1 + x²) grows like the logarithm of how far you go. The left half falls to minus infinity by the same amount. Infinity minus infinity is not a number. The lecture writes it as does not exist.
What does Monte Carlo do here? There is no target for the running average to approach. Watch it.
Five independent runs, each a running average of its draws so far. Choose a distribution and a function, then drag the number of samples. The dashed line is the true value, when there is one.
Real random draws made in your browser (seeded, so each press of the button gives a fresh set). Cauchy draws are tan(π (u − 0.5)) for a uniform u. Curves leaving the plotted range are clipped at its edge. The read-out spread is the largest minus the smallest of the five running averages at N.
With the Gaussian, the five curves start apart and funnel together onto the dashed line. With the Cauchy, they never funnel. One huge draw, from the heavy tail, throws a curve far off, and it takes thousands of ordinary draws to pull it back, until the next huge draw arrives. More samples do not help, because there is nothing to converge to.
The lesson for neural data: Monte Carlo is a tool that needs the expectation to exist. Before you average, ask whether the quantity can have extreme values that are not rare. A ratio of noisy rates can.
Chapter 8
Test whether knowing one neuron tells you anything about another, three equivalent ways
Two neurons sit on electrodes at opposite ends of the brain, with different jobs and different inputs. Seeing how many spikes the first fired tells you nothing about the second. Two other neurons sit next to each other and share a common input. Seeing the first fire a lot makes you expect the second to fire a lot. The first pair is independent. The second pair is not.
The lecture turns this into a definition you can check. It draws a joint density with its two marginals on the axes, in purple, and asks what must be true for the picture to carry no extra information.
First, the product rule. The variables x and y are independent when the joint equals the product of the marginals.
Second, in linear algebra terms. Write the marginals as two vectors. A table whose every cell is a row value times a column value is an outer product: P(x, y) = px pyT. Every row is the same pattern, scaled. Every column is the same pattern, scaled. Such a table has rank 1, which means one pattern repeated in different sizes, the simplest possible shape. You met rank in the SVD lecture. A joint with a ridge cannot be an outer product, because its rows have different shapes.
Third, equal conditionals. Slice the joint at different values of x, as in Chapter 4, and rescale each slice. If every slice is the same curve, the variables are independent. The lecture says it as: all conditionals are the same. This follows from the first definition: P(y | x) = P(x, y) / P(x) = P(x) P(y) / P(x) = P(y). Knowing x leaves your belief about y exactly where it was.
Use the small table from Chapter 3: both quiet 0.40, A quiet and B active 0.10, A active and B quiet 0.15, both active 0.35. The marginals are A: (0.50, 0.50) and B: (0.55, 0.45). If the neurons were independent, the cell “both quiet” would be 0.50 × 0.55 = 0.275. It is 0.40. They are not independent. Check another way: P(B active | A active) is 0.70 but P(B active) is 0.45. The conditionals differ.
Why care? Independence is a huge simplifier. If a population of 100 neurons were independent, you would only need 100 small tables, one per neuron, and the chance of any population response is their product. Without it you need one table over all neurons, which has far more cells than you could ever measure. Many decoders assume independence for that reason. Real neurons often share noise, so it is a claim to test, not to assume.
The device shows a Gaussian joint at the correlation you choose. On the left is the joint. Next to it is the outer product of its own marginals, the joint it would be if the neurons were independent. Below are the conditionals at x = −1 and x = +1.
Left: the joint. Right: the outer product of its marginals. Below: P(y | x = −1) in solid blue, P(y | x = +1) dashed, and P(y) in purple. Drag the correlation to 0 and watch all three tests agree.
Exact formulas for a standard bivariate Gaussian (both marginals centred at 0 with spread 1): P(y | x) is a bell centred at ρx with spread √(1 − ρ2). The product test reports the largest gap between the joint and the product of its marginals over a 40 × 40 grid on −3 to 3. Illustrative, not data.
At correlation 0 the two panels match and the two conditionals lie on top of the purple marginal. All three tests agree. At 0.9 the joint is a thin ridge, the product is a round blob, and the conditionals sit far apart. Any one test failing is enough to prove dependence.
Chapter 9
Separate a straight-line link between two neurons from every other way they can depend on each other
Two neurons get a common signal that sets how variable they are, not how active they are. When the signal is strong, both swing high or low. When it is weak, both stay near their average. Their average activities never move together, so a plot of one against the other has no upward or downward trend. Yet knowing one still tells you something about the other. Are they related?
The answer is yes, and the lecture builds the words to say how. It names two ideas and keeps them apart: correlation and dependence.
The correlation coefficient measures a straight-line link. It multiplies how far x sits above its mean by how far y sits above its mean, averages that, and divides by the two standard deviations so the answer lies between −1 and +1.
The lecture’s plain-words summary is: the mean of y given x changes systematically with x. It draws a positive and a negative correlation as two tilted ridges. Check it on the small table from Chapter 3. With spike or no spike coded as 1 or 0, the covariance is 0.35 − 0.50 × 0.45 = 0.125, and the correlation is 0.125 / √(0.25 × 0.2475) = 0.50.
Dependence is broader. Two variables are dependent whenever P(x, y) ≠ P(x) P(y), the failure of Chapter 8’s test. Correlation sees only one kind of dependence. The lecture also gives a way to count all kinds: the mutual information, the distance between the joint and the product of its marginals.
The lecture states the consequence: MI = 0 means independence. For the small table, add up 0.40 log2(0.40 / 0.275) + 0.10 log2(0.10 / 0.225) + 0.15 log2(0.15 / 0.275) + 0.35 log2(0.35 / 0.225) and you get 0.19 bits. The two neurons share about a fifth of a bit.
The lecture asks exactly that, then shows a grid of shapes from Murphy’s textbook (2012, Fig 2.12): a wave, two diamonds, a parabola, a cross, a ring and four small blobs, each with a correlation coefficient of 0.0. Most are clearly not one round blob. The shape you have just imagined, a swing that grows with the signal, is the bow-tie.
The lecture then shows a joint that looks like a soft round blob and asks: is this distribution independent? It slices the joint into P(y | x), and that image has a bow-tie shape. Its answer: no! Conditionals over y are different for different x. Slice at x = 0 and the curve for y is tall and narrow. Slice at x = −2 and it is short and wide. For every x the mean of y is 0, so the correlation is 0, but the spread depends on x, so the neurons are dependent.
One more fact from the lecture. The independent Gaussian is the only distribution that is both independent and spherically symmetric, meaning P(x) = P(Ux) for any rotation U. The corollary: a circular scatter or contour plot is not sufficient to show independence. The ring below is exactly circular and strongly dependent. The lecture’s advice is to visualise the conditionals instead.
Choose a joint. The left image is the density, with two slices marked. The right plot shows the slice at x = 0 (solid blue), the slice at x = −2 (dashed blue) and the marginal of y (purple).
Illustrative shapes on a 48 × 48 grid over −3 to 3, rescaled to add to 1: independent bells; a bivariate Gaussian with correlation 0.7; a bow-tie where y given x is a bell centred at 0 with spread 0.3 + 0.5|x|; a ring whose radius is a bell around 1.8 with spread 0.3. Correlation and mutual information (in bits) are computed from the grid.
Go through the four. The independent one has correlation 0 and MI 0. The correlated one has both large. The bow-tie and the ring both show correlation near 0 and a clearly positive MI. Correlation says nothing there. Mutual information catches it, and so do the slices.
Chapter 10
Keep the numbers, the checklist and the code, and see where this vocabulary leads next
The lecture ends with seven bullets, and each one was a chapter here. Distributions are masses or densities. Marginalization adds across a variable you want to forget. Conditionalization slices the joint and divides by a marginal. Bayes’ rule flips a conditional, with a prior and a normalizer. Expectations are weighted averages, and Monte Carlo estimates them from samples. Independence means the joint is a product, and correlation is only one way to fall short of it.
| Idea | Rule | Worked number | Chapter |
|---|---|---|---|
| Likelihood | P(data | θ), read as a function of θ | 6 spikes in 17 bins: θ = 6/17 is 1.12 times as likely as θ = 0.3 (lecture’s flips) | 1 |
| Poisson from binomial | n bins, spike chance λ/n, n large | λ = 4: P(0) = 0.0183, P(4) = 0.1954 | 2 |
| Marginal | P(x) = ∫ P(x, y) dy | Table 0.40, 0.10, 0.15, 0.35: P(A quiet) = 0.50, P(B quiet) = 0.55 (illustrative) | 3 |
| Conditional | P(y | x) = P(x, y) / P(x) | P(B active | A active) = 0.70, but P(A active | B active) = 0.78 | 4 |
| Bayes’ rule | posterior = likelihood × prior / normalizer | Prior 0.8 / 0.2, likelihoods 0.3 / 0.9: right = 0.18 / 0.42 = 0.43 | 5 |
| Moments | E[x] = x · P, E[x²] = x² · P, var = E[x²] − E[x]² | Lecture’s pmf: 1.7, 3.5 and 0.61 | 6 |
| Monte Carlo | E[f(x)] ≈ (1/N) ∑ f(x(i)) | Five draws give E[x²] ≈ 1.19; typical error 1.41 / √N | 7 |
| Independence | P(x, y) = P(x) P(y), or P(y | x) = P(y) | 0.50 × 0.55 = 0.275, but the cell is 0.40 | 8 |
| Correlation and MI | corr is a linear link; MI = DKL(P(x, y), P(x) P(y)) | Same table: correlation 0.50, MI 0.19 bits; a bow-tie has correlation 0 and positive MI | 9 |
python import numpy as np rng = np.random.default_rng(0) # 1. A joint table over two spike states (rows: A quiet/active, columns: B quiet/active) P = np.array([[0.40, 0.10], [0.15, 0.35]]) assert np.isclose(P.sum(), 1.0) # a joint adds up to 1 # 2. Marginalize: add across the variable you want to forget Px = P.sum(axis=1) # [0.50, 0.50] P(A) Py = P.sum(axis=0) # [0.55, 0.45] P(B) # 3. Condition: slice a row, divide by its marginal P_y_given_x = P / Px[:, None] # [[0.8, 0.2], [0.3, 0.7]] each row adds to 1 # 4. Bayes' rule: flip the conditional P_x_given_y = P_y_given_x * Px[:, None] / Py[None, :] # same as P / Py; each column adds to 1 # 5. Expectation is a dot product vals = np.array([1, 2, 3]); pmf = np.array([0.5, 0.3, 0.2]) mean = vals @ pmf # 1.7 m2 = vals**2 @ pmf # 3.5 var = m2 - mean**2 # 0.61 # 6. Monte Carlo: average f over samples from P x = rng.normal(size=100_000) mc = np.mean(x**2) # close to 1.0; typical error about 1.41 / sqrt(N) # 7. Independence: compare the joint with the outer product of its marginals gap = np.abs(P - np.outer(Px, Py)).max() # 0.125, so A and B are dependent mi = np.sum(P * np.log2(P / np.outer(Px, Py))) # 0.19 bits
Read it top to bottom and match each block to its chapter. Every line is one idea from this lecture, and none needs more than NumPy. Change the table in step 1 and watch every number below it move together.
This lecture is the vocabulary for the rest of the course. Chapter 0 showed that fitting a line by least squares quietly assumes that all the noise lives in y, and this lecture gave you the words to say so. The next lecture, Statistics and Entropy, builds on the inverse direction of Chapter 1. The rest of the series turns these rules into tools for spikes and populations.
On this site, the ideas have deeper lessons: Bayes estimation carries Bayes’ rule into tracking, and the Kalman filter is conditioning on a Gaussian joint, repeated. The mixture models in EM and Gaussian mixtures marginalize a hidden label. The hidden Markov model chains conditionals across time. For spikes, see spikes to rates.
The course posts its slides and notes on the course site. The course lists no reading for this lecture.
Credit: the structure and the questions follow the lecture slides of Jonathan Pillow, Princeton NEU 560, Spring 2024 (slides), including the shape grid from Murphy, Machine Learning: A Probabilistic Perspective (2012), Fig 2.12. The words, examples and devices on this page are our own.
Now press Teach and explain, from memory, how you would decode a stimulus from a spike count: which table you start with, what you marginalize, what you condition on, and what you divide by. Then go back to the ridge at the top, slice it at x = −1.5 and at 1.5, and say why the two blue bells differ.