A curve says how much you believe each possible bias of a coin. Watch it reshape as the flips land, one by one.
Learning from evidence
Belief about a coin's chance of heads, flip by flip: 30 flips of a coin with chance 0.7 (seed 7100).
Before any flips the curve is flat: every chance of heads p from 0 to 1 is equally believable.
Predict first. After three heads in a row, what will the belief curve look like?
Describe this picture
One panel: a curve over the unknown chance of heads , from 0 to 1, whose height says how strongly each value is believed; the area under it, lightly filled, is always 1. It starts flat: every value equally believable. Before the clip a question asks what the curve will look like after three heads in a row, with three small drawings: a narrow spike at , a hump centred on 0.5, or a curve rising towards 1 but still spread wide. A tap picks one and starts the clip. In the clip 30 seeded flips of a coin with true (seed 7100) land one at a time as H and T marks in a row above the curve, and each one reshapes the curve. The first three are heads and land slowly: the curve becomes , then , then , and holds there while your guess is drawn as a dotted curve beside it. Then the other 27 flips land quickly, a dashed line marks the true chance 0.7, and the curve narrows and moves towards it. After 30 flips, 20 of them heads, it is , with mean 0.6563. Readouts give the number of flips, the number of heads, the mean of the curve and its standard deviation. After the clip a slider, “Flips seen”, scrubs the number of flips from 0 to 30.
Belief as a curve
The coin’s chance of heads, , is unknown. Instead of one guess, the picture keeps a whole curve: a belief about every possible value. Before any flips that belief is the prior. After the data it is the posterior. The rule that turns one into the other is Bayes’ theorem, used again and again.
Before the clip you guessed what three heads would do. After three heads the curve is : it rises all the way to , but it is spread wide. Its mean is , not 1, and could easily be as low as 0.6: the curve still puts 13 % of its area below 0.6. Three flips are not much evidence.
How sure the curve is that the coin favours heads, , is its area above 0.5: .
The clip’s coin then landed 17 more heads in 27 flips: 20 heads in 30 in all. The curve ends narrow, with mean , near the true chance 0.7.
Three coins in a bag
Start with a case small enough to do by hand. A bag holds three coins. One lands heads with chance 0.3, one with 0.5, one with 0.8. You draw a coin without looking, so each is equally likely: a prior of each. You flip it once, and it lands heads. Which coin is it now likely to be?
Multiply each prior by the chance that coin gives heads, its likelihood from Maximum likelihood, and rescale so the three add to 1:
| Coin | Prior | Chance of heads | Product | Posterior |
|---|---|---|---|---|
| 0.3 | 1/3 | 0.3 | 0.1000 | 0.1875 |
| 0.5 | 1/3 | 0.5 | 0.1667 | 0.3125 |
| 0.8 | 1/3 | 0.8 | 0.2667 | 0.5000 |
That is the whole method:
In words: posterior is prior times likelihood, rescaled. The bottom line is only the rescaling.
Three coins in a bag
Belief in each coin, updated by one heads and one tails.
A bag of three coins with heads chances 0.3, 0.5 and 0.8. One is picked at random: each is believed equally, one third.
Describe this picture
Three bars, one for each coin in the bag, labelled “coin 0.3”, “coin 0.5” and “coin 0.8” with their chances of heads, and heights equal to the belief in each coin, each printed above its bar; they start equal at one third. In the clip a heads lands and the bars move to 0.1875, 0.3125 and 0.5; then a tails lands and they move to 0.3387, 0.4032 and 0.2581, while dashed ticks keep the heights after the first flip. A list beside the bars names the flips as they land. Readouts give the three beliefs and the chance that the next flip is heads: 0.5333 at the start, 0.6125 after the heads, 0.5097 after both. After the clip a switch, “Order of the two flips”, sets tails first, then heads: the dashed ticks move to the heights after a tails, 0.5, 0.3571 and 0.1429, and the bars end at the same three values.
Now a tails. Use the posterior as the new prior, and the chances of tails, , and , as the likelihoods. The products are , and , adding to , so the beliefs become , and .
After the clip, swap the order. Tails first and then heads gives the same three beliefs: either way each coin’s product is its chance of one heads times its chance of one tails, , and (times ). Order does not matter, only what was seen.
Watch out
A prior is not a bias that rules for ever, and the posterior is not the likelihood. The prior is where the belief starts; each piece of evidence multiplies it, and enough evidence outweighs any reasonable start. Only with a flat prior does the posterior have the same shape as the likelihood.
Many coins: a curve
Now let the bag hold coins of every bias from 0 to 1, all equally likely: a flat prior over . After heads in flips, the likelihood of a coin with bias is , and with a flat prior the posterior is that curve, rescaled to area 1.
A curve of the shape on , rescaled to area 1, is called the beta law, written . Here and are two positive shape numbers, not filter coefficients. So the posterior after heads in flips, from a flat prior, is
The flat prior is , and three heads give , the above. A curve has mean and, for , its peak at . For the posterior that means
The peak is the maximum likelihood estimate; the mean is pulled slightly towards .
Predicting the next flip
What is the chance the next flip lands heads? Average each coin’s chance of heads, weighted by the belief in it. For the bag after one heads:
For the curve, the same average is the curve’s mean, . After 7 heads in 10 flips it is . It is called the rule of succession: after no flips at all it gives .
Today’s posterior is tomorrow’s prior
Updating one piece of evidence at a time gives the same answer as updating on all of it at once, as the swap showed. That is why the method suits data that arrive in a stream: keep one belief, and fold in each new observation as it comes.
The repeated medical test of Bayes’ theorem was exactly this. A prior of 1 % became after one positive test, after two and after three, each posterior serving as the next prior.
Worked example
1. The bag, heads then tails. Priors each. After heads: , , , and the next flip is heads with chance . After tails as well: , , , and the next flip is heads with chance .
2. Seven heads in ten, from a flat prior. The posterior is . Its peak is at , the estimate of Maximum likelihood; its mean is , and its standard deviation .
This curve is the likelihood divided by its area, . So its peak height is .
The curve’s mean sits left of its peak because the curve leans: it has a longer tail towards small than towards 1.
3. Two tails from a flat prior. No heads in two flips gives , with mean : not 0, because two flips cannot rule heads out.
Where you’ll meet this
Spam filters. A filter keeps a belief that a message is spam and updates it word by word, as the bag updated flip by flip.
Experiments with history. An A/B test can start from a prior built from earlier tests, so that a small new test is read in the light of the old ones.
Monitoring. A hospital monitor or a fault detector updates a belief about a patient’s or a machine’s state with every new reading.
In signal processing · the Kalman filter
The Kalman filter keeps a belief about a moving object’s position and updates it with each measurement, weighing the new datum against the old belief by how uncertain each is. It is Bayesian updating for bell-shaped beliefs; RLS and the Kalman filter in the signal processing course builds it.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Update | posterior ∝ prior × likelihood | rescale to add (or integrate) to 1 |
| Discrete | rescaled over every ; Bayes’ theorem | |
| Order | same posterior in any order | today’s posterior is tomorrow’s prior |
| Beta law | mean | |
| Coin, flat prior | peak , mean | |
| Next flip | mean of the posterior | rule of succession |