IE437 · Data-Driven Decision Making and Control — Lecture 2
Fundamentals on Bayesian Statistics
From coin tossing to Bayesian regression
Jinkyoo Park · KAIST Model → update → predict, one example at a time
01 · FOUNDATIONS
1 · Introduction and Bayes’ rule
Start with the original coin question: what is its probability of heads? Compare statistical viewpoints, then learn the update rule.
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Where we are — the coefficients must be learned
Previous step
This chapter's question
Lecture 1 optimized a specified model.
Now represent an unknown parameter using a distribution.
Keep the likelihood, posterior and prediction target separate. The temperature example will distinguish an unknown mean from measurement noise.
Update a temperature mean and distinguish parameter uncertainty from a new noisy reading.
Lecture 2 · Fundamentals on Bayesian Statistics3 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Statistics works backwards from data to a model
Modelθ: probability of heads
DataD=(H,H,T): observed tosses
Given θ, the model tells us which data are plausible. Given data, inference asks which values of θ remain plausible. This alone is not a claim of causal identification.
Observation uncertainty
Yi∣θ∼Bernoulli(θ).
Even if θ were known, the next toss would remain random.
Parameter uncertainty
We do not know θ. A Bayesian distribution over θ represents our uncertainty about it; it does not require the physical coin to change on every toss.
Source alignment: original Lecture 2 PDF 3.
Lecture 2 · Fundamentals on Bayesian Statistics4 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Two approaches, both able to quantify uncertainty
Frequentist
θ is fixed; the data is what is random. So a probability describes the datasets you might have drawn — the long run of repeated, identical experiments.
Estimate by relative frequency, θ^=S/n. Running the experiment with more and more tosses:
The difficulty. Small n swings wildly — that is high variance, not bias; S/n is centred on θ at every n. And "identical flip" is an idealisation no real experiment quite meets.
Bayesian
The data is fixed — you observed it. θ is what is uncertain, so a probability describes θ itself: a degree of belief.
Specify a prior p(θ), condition on the observed D, and read off the posterior:
p(θ)⟶p(θ∣D)
The difficulty. The prior is a modelling choice, and choosing it honestly is real work. Check what it implies and compare reasonable alternatives.
The distinction is what the probability statement describes, not whether uncertainty matters.
Source alignment: original Lecture 2 PDF 4–7. The estimate sequence is the
source's own (PDF 6), as is the pairing of one difficulty against the other.
Two deliberate departures: the source says small n makes the estimate
biased, which is wrong — S/n is unbiased for every n, and what small n
buys is variance; and the sampling-variance formula an earlier draft used to
make that point has been dropped, since the binomial is not introduced until
"One toss, a sequence, and a count". Experiment 1 demonstrates the scatter
instead, and the two 95% statements are contrasted later on their own slide.
Lecture 2 · Fundamentals on Bayesian Statistics5 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
The lecture route — keep each example together
Bring: Conditional probability, sums and a Gaussian distribution.
First pass
What to do
Follow the idea
Specify → update → predict → check; repeat for coins, counts and regression
Work without the solution
Update a temperature mean and distinguish parameter uncertainty from a new noisy reading.
Return later
Complete-square derivations and additional conjugate calculations are in the appendix.
For the temperature thread: predict → calculate → reveal and check → change one condition. Complete the core calculation before reading the research extensions.
Lecture 2 · Fundamentals on Bayesian Statistics6 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Bayes' rule — name each part before using it
Q1 Why a distribution?Q2 What does the coin teach us?Q3 How does the model change?Q4 How do we learn a regression?
The evidencep(data)=∫p(data∣θ)p(θ)dθ is the probability of the data over every candidate at once. It does not depend on θ, so it only rescales the curve — which is why posterior ∝ likelihood × prior is usually all you write.
Prior in, posterior out. The likelihood tells us how to reweight the candidates.
Source alignment: original Lecture 2 PDF 8–9.
Lecture 2 · Fundamentals on Bayesian Statistics7 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Why Bayes' rule works
The same joint probability can be factored in two orders:
p(θ,D)=p(D∣θ)p(θ)=p(θ∣D)p(D).
Divide by the evidence p(D)>0:
p(θ∣D)=p(D)p(D∣θ)p(θ).
Multiply prior by likelihood, then normalise so the posterior sums or integrates to 1.
Source alignment: original Lecture 2 PDF 8.
Lecture 2 · Fundamentals on Bayesian Statistics8 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Two candidate coins — Bayes' rule with numbersan illustrative calculation before the continuous case
A coin is either fair (θ=0.5) or head-biased (θ=0.8), with equal prior probabilities. We observe two heads, conditionally independently.
Candidate
Prior
Likelihood of HH
Product
Posterior
θ=0.5
0.5
0.52=0.25
0.125
0.125/0.445=0.281
θ=0.8
0.5
0.82=0.64
0.320
0.320/0.445=0.719
The evidence is p(HH)=0.125+0.320=0.445. Dividing by it makes the posterior probabilities add to 1.
Two heads favour the biased coin, but do not prove which coin we have.
Source alignment: original Lecture 2 PDF 8–10.
Lecture 2 · Fundamentals on Bayesian Statistics9 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
One formula, two readings — probability and likelihoodthe same expression, according to which argument you hold fixed
For the observed sequence D=(H,H,T), conditional independence gives
p(D∣θ)=θ⋅θ⋅(1−θ)=θ2(1−θ).
That one expression has two free arguments, and which of them you hold fixed decides what kind of object you are looking at. Both readings below are of the formula above — they are not two different formulas.
Fix the parameter, vary the data — a probability
Then it is p(D∣θ), an ordinary probability over the 23=8 sequences three tosses could produce. Those eight numbers sum to 1, for every θ.
Fix the data, vary the parameter — a likelihood
Then it is L(θ;D), a score on each candidate θ. Nothing normalises it: ∫01θ2(1−θ)dθ=121, not 1.
Summing to 1 along one axis says nothing about the other. That missing normalisation is exactly what p(D) supplies in Bayes' rule — which is why a likelihood is not yet a posterior.
For continuous θ, p(θ) is a density: interval areas are probabilities and P(θ=θ0)=0. A density may exceed 1. This differs from the two discrete candidates on the previous slide.
Source alignment: original Lecture 2 PDF 10–11.
Lecture 2 · Fundamentals on Bayesian Statistics10 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
One toss, a sequence, and a count
Q1 Why a distribution?Q2 What does the coin teach us?Q3 How does the model change?Q4 How do we learn a regression?
Assume Yi∣θ are independent Bernoulli variables. Let S=∑i=1nYi.
What is observed?
Probability given θ
For two heads in three tosses
One toss Yi
θYi(1−θ)1−Yi
Head: θ
One particular sequence
θS(1−θ)n−S
HHT: θ2(1−θ)
Only the total S
(Sn)θS(1−θ)n−S
HHT, HTH, THH: 3θ2(1−θ)
The factor (Sn) counts the sequences. It is constant in θ, so it changes the data probability but not the MLE or posterior shape.
Source alignment: original Lecture 2 PDF 11.
Lecture 2 · Fundamentals on Bayesian Statistics11 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
The coin MLE — maximise the log likelihood
For 0<S<n, taking logs turns the product into a sum:
ℓ(θ)=Slogθ+(n−S)log(1−θ)+constant.
ℓ′(θ)=θS−1−θn−S=0⟹S(1−θ)=(n−S)θ⟹θ^ML=nS.
The second derivative is negative on (0,1), so this is the maximum. For HHT, θ^ML=2/3.
If S=0 or S=n, the maximum is at the boundary, 0 or 1; there is no interior derivative-zero solution. Here S is sufficient for θ: the order adds no information under this model.
Source alignment: original Lecture 2 PDF 12.
Lecture 2 · Fundamentals on Bayesian Statistics12 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Experiment 1 — repeat the coin experiment
Predict: will 100 tosses vary less than 5? Try: change tosses per experiment, then repeat the 200 experiments. Explain: the coin stays fixed; the datasets and their estimates change.
Source alignment: original Lecture 2 PDF 4–7, 11–12.
Lecture 2 · Fundamentals on Bayesian Statistics13 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
The Bayesian move — carry a distribution
Object
Question it answers
Coin example
Priorp(θ)
What is plausible before these data?
How biased might the coin be?
Likelihoodp(D∣θ)
How compatible is each candidate with the data?
How likely is HHT for this bias?
Posteriorp(θ∣D)
What is plausible after these data?
Which biases still have support?
Predictivep(Y~∣D)
What might happen next?
How many heads in future tosses?
The parameter and the next observation are different unknowns. A distribution over one is not a distribution over the other.
Source alignment: original Lecture 2 PDF 13.
Lecture 2 · Fundamentals on Bayesian Statistics14 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Prior, posterior, predictive — keep the target clear
Q1 Why a distribution?Q2 What does the coin teach us?Q3 How does the model change?Q4 How do we learn a regression?
Distribution
Random quantity
Information used
Prior p(θ)
parameter
before observing D
Prior predictive p(y~)
possible data
prior + sampling model
Posterior p(θ∣D)
parameter
prior + observed data
Posterior predictive p(y~∣D)
future observation
posterior + sampling model
Posterior: what might the parameter be? Predictive: what might we observe?
Source alignment: original Lecture 2 PDF 14.
Lecture 2 · Fundamentals on Bayesian Statistics15 / 96
01 · FOUNDATIONS1 · Introduction and Bayes’ ruleLecture 2
Check — what the distribution is over
A Bayesian writes p(θ) for a physical constant with one true, fixed value. What does the distribution describe?
The distribution represents epistemic uncertainty. Data can reduce it when informative. Aleatoric uncertainty is variation in future observations conditional on the model's parameters; learning the parameter alone does not remove that variation.
Source alignment: original Lecture 2 PDF 13–14.
Lecture 2 · Fundamentals on Bayesian Statistics16 / 96
02 · BAYESIAN COIN
2 · Bayesian estimation for coin flipping
Keep the same coin: choose a Beta prior, observe heads and tails, quantify uncertainty, and predict the next tosses.
Use a density supported on the possible coin biases, 0<θ<1:
p(θ)=B(α,β)1θα−1(1−θ)β−1,α,β>0.
Where is the belief centred?
E[θ]=α+βα.
Beta(2,2) centres at 1/2; Beta(2,8) centres at 1/5.
How strong is that belief?
Var[θ]=(α+β)2(α+β+1)αβ.
Write μ=E[θ] and ν=α+β: this is μ(1−μ)/(ν+1). At a fixed centre the numerator is fixed, so spread falls like 1/ν.
Both priors below centre at 1/2, so only ν separates them: Beta(2,2) has variance 1/20, Beta(20,20) has 1/164 — 8.2 times smaller, and the standard deviation falls from 0.22 to 0.08. That is what “α+β is the strength of the prior” means, and in the next slide it is why they cost ν pseudo-counts to overturn.
B(α,β) makes the density integrate to 1. The parameters act like pseudo-counts in the update; they need not represent actual past flips. Uniform Beta(1,1) is still a choice of prior.
Source alignment: original Lecture 2 PDF 15–17.
Lecture 2 · Fundamentals on Bayesian Statistics18 / 96
Integrating the polynomial gives the CDF in closed form,
F(θ)=∫0θ60t3(1−t)2dt=15θ4−24θ5+10θ6,
and the interval is the pair of roots of F(a)=0.025 and F(b)=0.975, solved numerically: [0.223,0.882].
The next toss — average θ over the posterior
P(H∣D)=∫01P(H∣θ)θp(θ∣D)dθ=E[θ∣D]=74
For a single toss the predictive integral collapses to the posterior mean. It is the m=1 case of the Beta-Binomial to come.
Three tosses leave substantial uncertainty — the interval spans two thirds of [0,1]. The mean, mode and interval answer different questions, and none of them is the whole posterior.
Source alignment: original Lecture 2 PDF 19–21. Every number recomputed: the CDF
polynomial agrees with direct integration at all three checkpoints, and the roots
give 0.2228 and 0.8819.
Lecture 2 · Fundamentals on Bayesian Statistics24 / 96
Predict: must all 26 intervals cover the true value? Try: run the repeated experiments. Explain: compare the long-run coverage statement on the left with posterior probability for the observed dataset on the right.
Source alignment: original Lecture 2 PDF 20–21.
Lecture 2 · Fundamentals on Bayesian Statistics25 / 96
Before drawing data, the random interval C(D) covers a fixed parameter in 95% of repeated experiments:
Pθ{θ∈C(D)}=0.95.
Once D is observed, the interval is fixed. Coverage alone does not assign 95% probability to that particular interval containing θ.
Credible interval
After observing D, an interval C contains 95% of the posterior probability:
P(θ∈C∣D)=0.95.
This is conditional on the prior, likelihood and data. Its repeated-sampling coverage need not be 95%.
The previous picture uses Normal observations with known noise and a flat prior on the mean. The endpoints coincide in that special case; the interpretations still differ.
Source alignment: original Lecture 2 PDF 20–21.
Lecture 2 · Fundamentals on Bayesian Statistics26 / 96
Predict: which prior resists HHT most? Try: load HHT, switch the prior, then simulate more tosses. Explain: compare the displayed prior/data weights. H and T record hypothetical outcomes; simulated tosses use a fixed bias of 0.62.
Source alignment: original Lecture 2 PDF 18–23.
Lecture 2 · Fundamentals on Bayesian Statistics28 / 96
From estimating the coin to predicting its next toss
The posterior answers which coin biases are plausible. A prediction asks what might happen next.
p(y~∣D)=∫p(y~∣θ)p(θ∣D)dθ.
For the Beta(4,3) posterior after HHT,
P(Y~=1∣D)=∫01θp(θ∣D)dθ=74.
Average the next-toss prediction over the plausible biases. For one Bernoulli outcome, plugging in the posterior mean gives exactly the same distribution.
Source alignment: original Lecture 2 PDF 14, 24.
Lecture 2 · Fundamentals on Bayesian Statistics30 / 96
This is Act 4's integral with a batch in place of a single y∗. Two things make it worth doing rather than plugging in θ^: the answer is available in closed form, and it is a different distribution, not merely a wider one.
The next slide evaluates that integral. The answer has a name — the Beta-Binomial.
Source alignment: original Lecture 2 PDF 24, 29–31.
Lecture 2 · Fundamentals on Bayesian Statistics31 / 96
Nothing here used which Beta it was. Feed it the prior and you get the prior predictive; feed it the posterior Beta(α+S,β+n−S) and the same formula returns the posterior predictive.
This is the derivation on the original Lecture 2 PDF (prior predictive), reused for the posterior predictive two slides later. The trick — multiply and divide by the normaliser so the integrand becomes a density — is the same one used for the Gaussian in Lecture 4.
Lecture 2 · Fundamentals on Bayesian Statistics32 / 96
For our coin the posterior was Beta(4,3), so the batch of m future tosses is BetaBinomial(m,4,3) — while plugging in the posterior mean θ^=4/7 would give Binomial(m,4/7).
Two future tosses
P(K=0)
P(K=1)
P(K=2)
mean
variance
Plug in θ=4/7
9/49=0.184
24/49=0.490
16/49=0.327
8/7
24/49
Average over θ
3/14=0.214
6/14=0.429
5/14=0.357
8/7
27/49
Identical means, and mass moved out of the middle onto both ends. Averaging did not shift the prediction — it widened it, by exactly the 3/49 the plug-in threw away when it pretended to know θ.
Both rows computed by integration and by the closed form; they agree. Try one toss, then a batch, on the next slide.
Lecture 2 · Fundamentals on Bayesian Statistics33 / 96
Predict: do the two predictions agree for one toss? Try: set future tosses to 1, then 10, then 30. Explain: the posterior stays Beta(4,3); more future tosses share the same uncertain bias.
Source alignment: original Lecture 2 PDF 24, 31.
Lecture 2 · Fundamentals on Bayesian Statistics34 / 96
With a fixed Beta(α,β) prior and independent Bernoulli observations, what happens to the prior weight in the posterior mean as n grows?
This is exact for the specified Beta–Binomial model. At n=α+β, prior and data weights are equal. At finite n the prior still has positive weight. General claims about posterior concentration require additional assumptions.
Source alignment: original Lecture 2 PDF 22–25.
Lecture 2 · Fundamentals on Bayesian Statistics36 / 96
03 · CONJUGATE MODELS
3 · Conjugate pairs
Repeat the coin workflow in the original order: counts with Poisson–Gamma, measurements with Normal–Normal, and categories with Multinomial–Dirichlet.
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Conjugacy — recognise the same family after updating
A prior is conjugate to a likelihood when the posterior stays in the prior's family. We can recognise and normalise the result analytically.
Data model and unknown quantity
Prior
Posterior
Binomial success probability
Beta
Beta
Poisson rate
Gamma (shape, rate)
Gamma
Normal mean, variance known
Normal
Normal
Normal variance, mean known
Inverse Gamma
Inverse Gamma
Normal mean and precision both unknown
Normal–Gamma
Normal–Gamma
Multinomial category probabilities
Dirichlet
Dirichlet
Conjugacy is algebraic convenience. It does not establish model fit or make every posterior mean a simple average of prior and sample means. Unknown Normal mean and variance require an appropriate joint prior.
Source alignment: original Lecture 2 PDF 26–28.
Lecture 2 · Fundamentals on Bayesian Statistics38 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Binomial–Beta recap — our template for the next models
Step
Coin calculation
Sampling model
S∣θ∼Binomial(n,θ)
Prior
θ∼Beta(α,β)
Posterior
θ∣D∼Beta(α+S,β+n−S)
Prediction
One toss: posterior mean; a batch: Beta–Binomial
Choose a model for the observations, update its parameters, then predict observations again. The next model counts events rather than successes out of a fixed number of trials.
Source alignment: original Lecture 2 PDF 29–32.
Lecture 2 · Fundamentals on Bayesian Statistics39 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Counting events — why Poisson and Gamma?
Let Yi count events in equal observation windows, with a common unknown rate λ:
Poisson likelihood
p(Yi=yi∣λ)=yi!λyie−λ.
Yi is a non-negative integer. Its conditional mean and variance both equal λ.
Gamma prior
p(λ)=Γ(a)baλa−1e−bλ.
λ>0. Here a is shape and b is rate, with mean a/b and variance a/b2.
We use a,b for Gamma to distinguish them from the coin's Beta parameters. A Gamma scale would be 1/b, not b.
Source alignment: original Lecture 2 PDF 33.
Lecture 2 · Fundamentals on Bayesian Statistics40 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Poisson–Gamma updating — counts and exposure add
For conditionally independent, equal-exposure counts,
Twenty districts:n=20, total ∑iyi=211, average yˉ=10.55.
The source specifies prior mean 20 and standard deviation 10. In shape–rate notation,
ba=20,b2a=100⟹b=0.2,a=4.
The model treats districts as comparable units with one common rate. Unequal areas, search effort or spatial dependence require a richer model or exposure adjustment.
Source alignment: original Lecture 2 PDF 36.
Lecture 2 · Fundamentals on Bayesian Statistics42 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
The count estimate — calculateevery number on this slide comes from a formula two slides back
Prior Gamma(a,b)=Gamma(4,0.2); data n=20 districts with ∑iyi=211, so yˉ=10.55.
Quantity
Formula
Put the numbers in
Value
Posterior
Gamma(a+∑iyi,b+n)
Gamma(4+211,0.2+20)
Gamma(215,20.2)
Posterior mean
b+na+∑iyi
20.2215
10.644
Posterior variance
(b+n)2a+∑iyi
20.22215=408.04215
0.527
Standard deviation
Var
0.527
0.726
95% credible interval
2.5% and 97.5% quantiles of Gamma(215,20.2)
by software, or the normal approximation 10.644±1.96×0.726
[9.27, 12.11] exact; [9.22,12.07] approx.
The interval needs a quantile function — qgamma in R, scipy.stats.gamma.ppf in Python. The normal approximation lands within 0.05 of it here because the shape 215 is large; a Gamma is right-skewed, so the exact interval sits slightly to the right.
Lecture 2 · Fundamentals on Bayesian Statistics43 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
The count estimate — interpretthe same numbers, read as statements about the rate
Why the mean is 10.644
Two slides back the posterior mean was written as a weighted average of the prior mean and the sample mean:
The prior rate b=0.2 is worth 0.2 of a district. Twenty real districts outweigh it a hundred to one, so the estimate lands next to yˉ.
What the interval says
With 95% probability the common rateλ lies in [9.27,12.11]: about nine to twelve sightings per district, on average.
It is a statement about λ, a parameter. It is not a range for the count in one new district — that count also carries Poisson noise, and its interval is wider. The next slides make that distinction exact.
This interval describes the common rate λ. It is not a prediction interval for the count in one new district.
Source alignment: original Lecture 2 PDF 35–37.
Lecture 2 · Fundamentals on Bayesian Statistics44 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Experiment 5 — observe the districts one by one
Predict: will 20 districts outweigh the original prior? Try: move from 0 to 1 to 20 districts; then increase prior exposure while keeping its mean fixed. Explain: distinguish uncertainty in the rate from variability in a new district.
Source alignment: original Lecture 2 PDF 35–37.
Lecture 2 · Fundamentals on Bayesian Statistics45 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Predict one new district — rate uncertainty is not count noise
Return to λ∣D∼Gamma(215,20.2). For one comparable new district, Y~∣λ∼Poisson(λ).
The rate's posterior standard deviation is 0.726; a new count's predictive standard deviation is 3.342. Knowing the rate well does not make every district identical.
The predictive distribution is Negative Binomial, a Poisson–Gamma mixture. Its probability mass function and parameter convention are in the appendix.
Source alignment: original Lecture 2 PDF 37.
Lecture 2 · Fundamentals on Bayesian Statistics46 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Prior × likelihood — write down what is being multiplied
Let Yi∣θ∼N(θ,σ2) independently with σ2 known, and θ∼N(μ0,τ02).
Likelihood
p(y∣θ)=i=1∏n2πσ21exp{−2σ2(yi−θ)2}
Prior
p(θ)=2πτ021exp{−2τ02(θ−μ0)2}
Only the shape in θ matters, so every factor without a θ in it goes into the constant:
Divide each by its variance and gather the two powers of θ:
−21[A(σ2n+τ021)θ2−2B(σ2nyˉ+τ02μ0)θ]
One completed square finishes it — and the leftover B2/A has no θ, so it joins the constant:
Aθ2−2Bθ=A(θ−AB)2−AB2⟹p(θ∣y)∝exp{−2A(θ−AB)2}
That is a Normal density with precision A and mean B/A. Nothing was assumed; it fell out.
Source alignment: original Lecture 2 PDF 40–41. The appendix repeats the same
completion in log space for anyone who prefers it that way.
Lecture 2 · Fundamentals on Bayesian Statistics48 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Normal observations — combine information by precision
Reading A and B/A back gives the posterior in the form worth remembering.
Precisions add
τ121=priorτ021+dataσ2n
Yˉ∣θ∼N(θ,σ2/n), so the data carry precision n/σ2 — information adds, variances do not.
The mean is a weighted average
μ1=1/τ02+n/σ2(1/τ02)μ0+(n/σ2)yˉ
Each side is weighted by exactly the precision it brings, and θ∣D∼N(μ1,τ12).
Sharper prior
τ02↓ — the prior mean μ0 is more trusted and pulls μ1 harder.
Quieter sensor
σ2↓ — each reading is more precise, so yˉ pulls harder.
More data
n↑ — yˉ pulls harder still, and eventually the prior stops mattering.
Source alignment: original Lecture 2 PDF 42. The three sensitivity readings are
the source's own and were missing from the deck.
Lecture 2 · Fundamentals on Bayesian Statistics49 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Four temperature readings — add the precisionsthe previous slide's two formulas, with numbers put in
Prior θ∼N(20,22); measurement noise has standard deviation 3; four readings average 23.
Step 1 — state each source as a precision, since that is the currency that adds:
the priorτ021=221=41andfour readings, yˉ=23σ2n=324=94.
Step 2 — add them, then invert to come back to a variance:
τ121=41+94=3625,τ12=2536=1.44,τ1=1.2.
Source alignment: original Lecture 2 PDF 40–42.
Lecture 2 · Fundamentals on Bayesian Statistics50 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Four temperature readings — weight the means36% prior, 64% data — and the estimate lands at 21.92
Step 3 — weight each mean by the precision that carries it. Dividing through by the total precision 25/36 turns the formula into an ordinary weighted average:
The four readings took 64% of the weight and left the prior 36%, so the estimate moved from 20 to 21.92 — most of the way to the data, but not all of it.
Precision decides the split, and four readings at σ=3 are worth just under twice a prior at τ0=2.
Source alignment: original Lecture 2 PDF 40–42.
Lecture 2 · Fundamentals on Bayesian Statistics51 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Temperature thread — update an uncertain temperatureshared teaching example · predict before revealing the calculation
The true temperature θ has prior N(20,4). One sensor reading is y=22, with y∣θ∼N(θ,1). The second parameter here is variance.
Predict: Will the posterior mean be closer to 20 or to 22? Will its variance equal the variance of a new reading?
Calculate and check. The gain is K=4/(4+1)=0.8. The posterior mean is 20+0.8(22−20)=21.6 and variance is (1−0.8)4=0.8. A new reading with independent sensor noise has predictive variance 0.8+1=1.8.
Learning the unknown temperature and predicting another noisy measurement are different questions.
Lecture 2 · Fundamentals on Bayesian Statistics52 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Try it — the sensor variance rises to 4work independently · reveal only after writing an answer
Keep the prior and the observed value 22. Change the sensor variance from 1 to 4, for both this and the next reading. Find the posterior mean, posterior variance and predictive variance.
Check your answer.K=4/(4+4)=0.5, posterior mean 21, posterior variance 2, predictive variance 6. The less precise reading pulls the posterior less strongly.
State which distribution each variance belongs to before adding or comparing numbers.
Lecture 2 · Fundamentals on Bayesian Statistics53 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Experiment 6 — vary precision with the same average
Predict: does noisier data move the estimate closer to 20 or 23? Try: change noise SD, prior SD, and the number of readings. Explain: the average stays at 23; precision determines its weight. The grey likelihood is normalised for plotting.
Source alignment: original Lecture 2 PDF 39–42.
Lecture 2 · Fundamentals on Bayesian Statistics54 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Normal prediction — restore the observation noise
The updated mean parameter is θ∣D∼N(μ1,τ12). A new reading is Y~=θ+ϵ, with independent ϵ∼N(0,σ2).
Y~∣D∼N(μ1,τ12+σ2).
For the previous four readings:
θ∣D∼N(21.92,1.44),Y~∣D∼N(21.92,10.44).
Same centre, different uncertainty. Learning the temperature does not remove noise from the thermometer.
Source alignment: original Lecture 2 PDF 43–44.
Lecture 2 · Fundamentals on Bayesian Statistics55 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Experiment 7 — compare the mean and the next reading
Predict: which curve keeps a noise floor? Try: increase readings from 1 to 100. Explain: posterior parameter variance shrinks, while predictive variance remains 9 plus that variance. Here noise SD is fixed at 3 and prior SD at 2.
Source alignment: original Lecture 2 PDF 43–44.
Lecture 2 · Fundamentals on Bayesian Statistics56 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
More than two outcomes — the Dirichlet updatethe categorical model
Suppose each service request is delivery, pickup or return. The probabilities form a vector θ with non-negative entries adding to 1.
The likelihood adds one count to the corresponding exponent for each observation:
θ∣D∼Dirichlet(α1+Y1,α2+Y2,α3+Y3).
The Beta update with a longer list of categories. With two categories, the Dirichlet reduces to a Beta distribution for the first probability.
Source alignment: original Lecture 2 PDF 45–46.
Lecture 2 · Fundamentals on Bayesian Statistics57 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
An unseen category need not get zero probability
Start from Dirichlet(1,1,1) and observe ten requests: 6 deliveries, 4 pickups, 0 returns.
Category
Count
MLE
Posterior parameter
Next-request probability
Delivery
6
6/10
1+6=7
7/13
Pickup
4
4/10
1+4=5
5/13
Return
0
0/10
1+0=1
1/13
The posterior is Dirichlet(7,5,1) and predictive probabilities add to 1. The prior gives an unseen but possible category some support.
This update can estimate the rows of a transition matrix. Ten observations without a return do not prove returns are impossible.
Source alignment: original Lecture 2 PDF 46–47.
Lecture 2 · Fundamentals on Bayesian Statistics58 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Experiment 8 — observe a previously unseen category
Predict: is a return impossible after zero observed returns? Try: add Return, change the prior strength, then clear the data. Explain: posterior parameters are prior pseudo-counts plus observed counts; divide by their sum to predict one request.
Source alignment: original Lecture 2 PDF 46–47.
Lecture 2 · Fundamentals on Bayesian Statistics59 / 96
03 · CONJUGATE MODELS3 · Conjugate pairsLecture 2
Check — what uncertainty belongs in a new measurement?
With known noise variance σ2 and posterior mean variance τ12, what is the variance of the next Normal observation?
The unknown mean and independent noise both vary in the predictive calculation. More data learns the mean but does not eliminate the assumed observation noise. We will use exactly this idea for regression.
Source alignment: original Lecture 2 PDF 43–47.
Lecture 2 · Fundamentals on Bayesian Statistics60 / 96
04 · REGRESSION
4 · Bayesian regression and regularisation
Follow the original regression route: formulate the task, solve least squares, interpret MLE, keep a Bayesian posterior, then motivate and interpret regularisation.
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Problem solving — estimate a housing price
Task → model → algorithm. The two house-price observations are illustrative, not an empirical housing dataset.
We now learn a vector of weights. The Bayesian logic stays the same as for a coin, a rate, or a mean.
Source alignment: original Lecture 2 PDF 49–51.
Lecture 2 · Fundamentals on Bayesian Statistics62 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Regression roadmap — the same model from several views
We keep yi=xi⊤w+ϵi throughout.
1 · Optimisationminimise squared residuals → normal equation
2 · MLEGaussian noise → the same least-squares fit
3 · Full Bayes and MAPprior + likelihood → posterior; its peak is MAP
4 · Regularisationshrink weights → ridge or lasso; interpret the prior
One regression model, several ways to describe what learning means. We will connect the objectives instead of introducing unrelated methods.
Source alignment: original Lecture 2 PDF 52.
Lecture 2 · Fundamentals on Bayesian Statistics63 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Put a line into matrix form
Include the intercept by adding a constant feature 1. For the illustrative data (x,y)=(0,1),(1,2),(2,2),
Each row is one observation. Each column is one feature. The residual vector is y−Xw.
In general X∈Rn×d, w∈Rd and y∈Rn. Here d includes the intercept. Keep this orientation throughout the derivation.
Source alignment: original Lecture 2 PDF 53–54.
Lecture 2 · Fundamentals on Bayesian Statistics64 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Least squares — use Lecture 1's optimality condition
Choose weights to minimise squared residuals:
J(w)=21∥y−Xw∥2,∇J(w)=X⊤(Xw−y).
The Hessian is X⊤X⪰0, so J is convex. Therefore
w^ minimises J⟺X⊤Xw^=X⊤y.
This is the normal equation. The zero-gradient condition is exact here because the problem is convex, differentiable and unconstrained.
Only when X has full column rank is the minimiser unique and (X⊤X)−1X⊤y valid. Otherwise minimisers are not unique; use QR or SVD methods for the linear algebra instead of explicitly forming an inverse.
Source alignment: original Lecture 2 PDF 55–56.
Lecture 2 · Fundamentals on Bayesian Statistics65 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Solve the three-point regression by hand
For the previous three observations,
X⊤X=(3335),X⊤y=(56).
The normal equation gives 3w0+3w1=5 and 3w0+5w1=6. Subtract to get w1=1/2, then w0=7/6.
A best-fitting line need not pass through every point. It balances the residuals to minimise their squared total.
Source alignment: original Lecture 2 PDF 55–56.
Lecture 2 · Fundamentals on Bayesian Statistics66 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Why Gaussian noise turns MLE into least squares
Assume independent noise ϵi∼N(0,σ2), with known σ2>0:
p(y∣X,w)=i=1∏n2πσ21exp[−2σ2(yi−xi⊤w)2].
Take the negative log:
−logp(y∣X,w)=constant in w2nlog(2πσ2)+2σ21∥y−Xw∥2.
For fixed σ2, maximising this likelihood is exactly minimising squared error. Least squares itself does not require Gaussian noise; this probabilistic interpretation does.
Source alignment: original Lecture 2 PDF 57–58.
Lecture 2 · Fundamentals on Bayesian Statistics67 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Experiment 9 — move the line and watch its residuals
Predict: does making one residual zero minimise the total error? Try: adjust intercept and slope, then select Fit least squares. Explain: the same minimiser gives SSE = 1/6 and maximises the displayed Gaussian likelihood.
Source alignment: original Lecture 2 PDF 53–58.
Lecture 2 · Fundamentals on Bayesian Statistics68 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
From MLE to Bayesian regression
MLE: choose one weight vector
w^ML=wargmaxp(y∣X,w).
We retain the weight vector giving the largest likelihood.
Bayesian: update a distribution
p(w∣X,y)∝p(y∣X,w)p(w).
MAP is its most dense point; full Bayes also keeps the spread and correlations.
The prior acts on weights, just as the Beta prior acted on the coin bias. A Gaussian prior makes this update analytically tractable.
Source alignment: original Lecture 2 PDF 59–61.
Lecture 2 · Fundamentals on Bayesian Statistics69 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Complete the square again — now with a matrix
Same two factors as before, with w in place of θ. Keep only what carries a w:
logp(w∣X,y)=−2σ21(y−Xw)⊤(y−Xw)−2τ21w⊤w+C.
Expand (y−Xw)⊤(y−Xw)=y⊤y−2w⊤X⊤y+w⊤X⊤Xw and gather the two powers of w:
−21[w⊤A(σ2X⊤X+τ2I)w−2w⊤bσ2X⊤y]
The scalar identity survives transposition — A is symmetric, so
w⊤Aw−2w⊤b=(w−A−1b)⊤A(w−A−1b)−b⊤A−1b,
and the leftover carries no w. What is left is a Gaussian with precision matrix A and mean A−1b.
Line for line the scalar derivation, with a matrix where the number was: A was σ2n+τ021 and is now σ2X⊤X+τ2I; the mean was B/A and is now A−1b. Precision still adds; the mean is still precision-weighted.
Source alignment: original Lecture 2 PDF 60–61. This is the appendix's log-space
completion, moved into the body — the result is unusable as a formula to remember
unless you have seen where the two terms of A came from.
Lecture 2 · Fundamentals on Bayesian Statistics70 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Full Bayes keeps the distribution over weights
With independent noise ϵi∼N(0,σ2) and prior w∼N(0,τ2I), the posterior is also Gaussian:
w∣X,y∼N(μw,Σw).
The centre
μw=Σwσ2X⊤y.
Here the mean and mode coincide, so μw is also the MAP estimate. Later we will connect it to ridge regression.
The uncertainty
Σw−1=σ2X⊤X+τ2I.
Data precision plus prior precision. Large posterior variance marks directions in the weights that remain uncertain.
Read straight off the previous slide: Σw=A−1 and μw=A−1b. Known positive σ2 and τ2 are assumed, which is what makes A positive definite — and therefore invertible — even when X has fewer rows than columns.
Source alignment: original Lecture 2 PDF 60–61.
Lecture 2 · Fundamentals on Bayesian Statistics71 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Bayesian regression — one posterior in two spaces
Two rows, three columns, on nested simulated datasets (n = 2, 10, 100). Blue: MLE; green: posterior mean/MAP and sampled lines; ×: true weights. Corresponding axes use common scales.
Top: plausible mean functions. Bottom: plausible weights. More informative data contracts both views of the same posterior.
Source alignment: original Lecture 2 PDF 62.
Lecture 2 · Fundamentals on Bayesian Statistics72 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Experiment 10 — change data, watch the posterior over a line
Predict: which fit is most unstable with two cases? Try: compare 2, 10, and 100 nested cases, then draw new data. Explain: the left panel shows sampled mean functions; the right shows the same uncertainty in coefficient space.
Source alignment: original Lecture 2 PDF 59–62.
Lecture 2 · Fundamentals on Bayesian Statistics73 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Regression prediction — a line and a noisy observation
At a new feature vector x∗, the fitted mean is f∗=x∗⊤w. Since w∣D∼N(μw,Σw),
f∗∣D∼N(x∗⊤μw,x∗⊤Σwx∗).
An individual response also includes noise, Y~∗=f∗+ϵ∗:
Drawing posterior lines shows uncertainty about the mean function. Add noise to predict actual observations. Both depend on the linear model being appropriate.
Source alignment: original Lecture 2 PDF 62.
Lecture 2 · Fundamentals on Bayesian Statistics74 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
When the integral is hard — simulate the two stages
For regression, draw w(s) from its Gaussian posterior, then draw noise and set y~∗(s)=x∗⊤w(s)+ϵ∗(s).
Conjugate examples allow direct sampling. Other models may require MCMC or an approximation, whose accuracy must be checked. See the Stan posterior prediction guide for the same two-stage construction.
Source alignment: original Lecture 2 PDF 62.
Lecture 2 · Fundamentals on Bayesian Statistics75 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Why regularise a regression?
The original goal is to predict new observations, not only to fit the training cases.
A flexible fit
Extra features can lower training error. With limited or correlated data, fitted weights may change substantially when the sample changes.
A controlled fit
Penalising large weights can reduce this sensitivity. We accept some fitting bias in exchange for potentially better predictions.
w^ridge=wargmin{∥y−Xw∥2+λ2∥w∥2}.
Check the tradeoff on independent validation data. Neither more flexibility nor more shrinkage is automatically better.
Source alignment: original Lecture 2 PDF 63–65.
Lecture 2 · Fundamentals on Bayesian Statistics76 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Why shrinkage helps — and what it changes
Ridge changes the normal equation to
(X⊤X+λ2I)w^=X⊤y.
Small or correlated datasets
Several weight vectors may fit almost equally well. Small data perturbations can then produce large changes in the OLS weights.
Adding λ2I makes the system positive definite for λ2>0 and stabilises these directions.
The tradeoff
Shrinkage introduces bias toward the prior mean for potentially lower variance. It can help prediction but does not guarantee better test performance.
Choose strength with prior knowledge and appropriate validation; inspect feature scaling.
The Gaussian-posterior example gives all weights a prior. The next experiment leaves the intercept unpenalised; applications often treat it separately.
Source alignment: original Lecture 2 PDF 64–65.
Lecture 2 · Fundamentals on Bayesian Statistics77 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Experiment 11 — compare training fit with validation error
Predict: must the best training fit predict best? Try: sweep λ on one fixed dataset, then change its size or draw new training data. Explain: polynomial features keep the model linear in its weights; validation data stays separate and fixed.
Source alignment: original Lecture 2 PDF 63–66.
Lecture 2 · Fundamentals on Bayesian Statistics78 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Add a Gaussian prior — derive ridge, not just name it
Let w∼N(0,τ2I) with known τ2>0. The negative log posterior is
−logp(w∣X,y)=2σ21∥y−Xw∥2+2τ21∥w∥2+constant.
Multiply by 2σ2, which does not change the minimiser:
w^MAP=wargmin{∥y−Xw∥2+λ2∥w∥2},λ2=σ2/τ2.
A smaller prior variance penalises large weights more strongly. The regulariser is the negative log prior, with the noise scale accounted for.
Source alignment: original Lecture 2 PDF 67–68.
Lecture 2 · Fundamentals on Bayesian Statistics79 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Lasso — a different prior changes the penalty
Independent Laplace priors with scale bL>0 have
p(w)=j∏2bL1e−∣wj∣/bL.
With the same Gaussian likelihood,
w^MAP=wargmin{∥y−Xw∥2+λ1∥w∥1},λ1=bL2σ2.
The absolute-value penalty has a corner at zero, so some MAP coefficients can be exactly zero. A continuous Laplace prior has no probability mass at the single point zero.
Source alignment: original Lecture 2 PDF 66, 69.
Lecture 2 · Fundamentals on Bayesian Statistics80 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Experiment 12 — see why ridge shrinks and lasso can select
Predict: which constraint has corners on the axes? Try: change λ and switch between ridge and lasso. Explain: the contact point is the fitted weight vector. Priors are scaled to peak height 1 to compare shapes; this illustration uses noise variance 1.
Source alignment: original Lecture 2 PDF 65–69.
Lecture 2 · Fundamentals on Bayesian Statistics81 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
Check — the prior wearing a disguise
Under Gaussian noise, what prior gives MAP the ridge objective ∥y−Xw∥2+λ2∥w∥2?
Taking the negative log turns the Gaussian likelihood into squared residuals and the Gaussian prior into a squared-weight penalty. For this unaveraged objective, λ2=σ2/τ2. Averaging the data loss by n changes the coefficient convention.
Source alignment: original Lecture 2 PDF 67–69.
Lecture 2 · Fundamentals on Bayesian Statistics82 / 96
04 · REGRESSION4 · Bayesian regression and regularisationLecture 2
What we can now calculate
Task
Calculation
Example
Update a belief
posterior ∝ prior × likelihood
Beta(2,2) + HHT → Beta(4,3)
Choose a point
MLE, MAP or a loss-based posterior summary
Gaussian prior + Gaussian noise → ridge
Predict data
average the sampling model over the posterior
uncertain Poisson rate → Negative Binomial
Check the model
simulate, compare and revise
replicated counts or regression residuals
Lecture 3 asks how to represent many interacting variables. Conditional independence makes a large probabilistic model manageable.
Source alignment: original Lecture 2 PDF 70.
Lecture 2 · Fundamentals on Bayesian Statistics83 / 96
Questions?
Can you explain which uncertainty is over a parameter, which is over an observation, and where each appears in the calculation?
Source alignment: original Lecture 2 PDF 70.
APPENDIX
Appendix · extra derivations and checks
Optional details for questions and self-study; the main lecture has completed the original route.
APPENDIXAppendix · extra derivations and checksLecture 2
Reading guide — one Bayesian calculation, several observation modelsone main idea to explain, one comparison, one application
What distribution is specified, updated, and used for prediction?
Compare
MLE, MAP and full Bayes on the same coin or regression data
Which answer is a point estimate, and which carries uncertainty?
Apply
The original Pokémon district counts and housing-price example
How does the observation model affect the estimate and prediction?
Use selected sections as a reference, not the entire book as an assignment. For each example write the likelihood, prior, posterior and predictive target before doing algebra.
Lecture 2 · Fundamentals on Bayesian Statistics86 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — integrate the Beta–Binomial prediction
Write α′=α+S, β′=β+n−S. For K heads in m future tosses,
For m=2 and Beta(4,3), probabilities of K=0,1,2 are 3/14,6/14,5/14. They sum to 1.
Before observing data, use α,β to obtain the prior predictive. With a Beta(2,2) prior and two tosses, its probabilities are 0.3,0.4,0.3. Future batch size m need not equal training size n.
Source alignment: original Lecture 2 PDF 24, 31.
Lecture 2 · Fundamentals on Bayesian Statistics87 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — MLE, MAP and posterior mean
Estimate
Definition
Beta(2,2) prior + HHT
MLE
argmaxθp(D∣θ)
2/3
MAP
argmaxθp(θ∣D)=argmaxθp(D∣θ)p(θ)
3/5
Posterior mean
E[θ∣D]
4/7
MAP picks the posterior's mode. The posterior mean minimises posterior expected squared-error loss; the posterior median minimises expected absolute-error loss.
The posterior mode depends on the parameterisation. With abundant informative data and suitable regularity, MLE and MAP may become close; they need not be identical for a finite sample.
Lecture 2 · Fundamentals on Bayesian Statistics88 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — when does prior influence fade?
In the Beta–Binomial model, for a fixed proper Beta prior,
prior weight=α+β+nα+β⟶0.
This does not mean any prior can be overcome in any model:
An identifiable model needs informative observations about the parameter.
A prior excluding a whole region cannot acquire posterior mass there by multiplication.
Model misspecification can produce confident but misleading conclusions.
Check prior sensitivity when data is limited. More data is not a substitute for a plausible model.
Lecture 2 · Fundamentals on Bayesian Statistics89 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — checking a fitted probability model
Before fitting: prior predictive check
Draw parameters from the prior, then simulate data. Do plausible parameters produce plausible counts, prices or temperatures?
After fitting: posterior predictive check
Draw parameters from the posterior and simulate replicated datasets of the same design. Compare their spread, extremes and patterns with the observations.
For the Pokémon example: compare the observed mean 10.55 and sample variance 11.94 with replicated 20-district datasets. Also examine exposure and spatial patterns. Mean–variance similarity alone does not establish the Poisson assumptions.
Use a mismatch to improve the model. Evaluate future prediction on held-out data too; checking training data is not a test of generalisation.
E[K∣D]=mμ. The multiplier of Binomial variance is 1 at m=1 and greater than 1 at m>1. Future tosses share one latent bias; independently resampling a bias for each toss would be a different model.
Lecture 2 · Fundamentals on Bayesian Statistics91 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — the Poisson–Gamma predictive distribution
With posterior λ∣D∼Gamma(a′,b′) in shape–rate form, a new unit-exposure count has
This is Negative Binomial with shape a′ and probability b′/(b′+1) under the displayed convention; a′ need not be an integer. For future exposure t, the mean is ta′/b′ and variance ta′/b′+t2a′/b′2.
Lecture 2 · Fundamentals on Bayesian Statistics92 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — the Dirichlet predictive distribution
For category counts yj, let αj′=αj+yj and A′=∑jαj′. Then
p(θ∣D)∝j∏θjαj′−1,P(Y~=j∣D)=A′αj′.
For a future batch of size m with counts kj adding to m,
C,C′,C′′ do not depend on θ. A new observation is θ plus independent Gaussian noise, so its predictive distribution is N(μ1,τ12+σ2).
Lecture 2 · Fundamentals on Bayesian Statistics94 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — three remarks on the regression posterior
The completion of the square now sits in the body, at Complete the square again — now with a matrix. Three things worth saying only if asked:
Always invertible
X⊤X alone is singular whenever X has fewer rows than columns. Adding I/τ2 makes A positive definite, so a Bayesian fit is defined where least squares is not — the prior supplies the missing rank.
Mean equals MAP
A Gaussian's mean, mode and median coincide, so μw is simultaneously the posterior mean and the MAP estimate. That is special to the Gaussian and does not survive a skewed posterior.
What the point estimate drops
Σw is precisely what collapsing to μw throws away — and its large directions are the ones a prediction should hedge in.
Lecture 2 · Fundamentals on Bayesian Statistics95 / 96
APPENDIXAppendix · extra derivations and checksLecture 2
Backup — why Lasso can select an exact zero
For one coordinate, write the objective, up to a constant, as
q(wj)=ajwj2−2rjwj+λ1∣wj∣,aj>0.
At zero, ∂∣wj∣=[−1,1]. The optimality condition is
0∈−2rj+λ1[−1,1]⟺∣rj∣≤λ1/2.
Otherwise the solution is the soft-thresholded value
wj=ajsign(rj)max(∣rj∣−λ1/2,0).
This is a property of MAP optimisation. A continuous Laplace prior and the resulting continuous posterior have no atom at zero; full posterior samples are not sparse in this exact-zero sense.
Lecture 2 · Fundamentals on Bayesian Statistics96 / 96
IE437 · Lecture 2 — Fundamentals on Bayesian Statistics
1Fundamentals on Bayesian Statistics
1 · Introduction and Bayes’ rule
3Where we are — the coefficients must be learned
4Statistics works backwards from data to a model
5Two approaches, both able to quantify uncertainty
6The lecture route — keep each example together
7Bayes' rule — name each part before using it
8Why Bayes' rule works
9Two candidate coins — Bayes' rule with numbers
10One formula, two readings — probability and likelihood
11One toss, a sequence, and a count
12The coin MLE — maximise the log likelihood
13Experiment 1 — repeat the coin experiment
14The Bayesian move — carry a distribution
15Prior, posterior, predictive — keep the target clear
16Check — what the distribution is over
2 · Bayesian estimation for coin flipping
18A Beta prior — location and strength
19Derive the posterior by collecting powers
20Sequential updating — do not count old data twice
21Bayesian coin updating — the first five tosses
22Bayesian coin updating — from 8 to 500 tosses
23Beta(4,3) — the mean and the mode, by hand
24Beta(4,3) — the interval and the next toss
25Experiment 2 — repeat an interval procedure
26Read the two 95% statements carefully
27The posterior mean is a balance — in numbers
28Experiment 3 — change the prior, keep the data
29Does more data always make a posterior narrower?
30From estimating the coin to predicting its next toss
31Predicting a batch — one uncertain coin is shared
32Where the Beta-Binomial comes from
33Which Beta you feed it is the whole difference
34Experiment 4 — predict one toss, then a batch
35Three steps in Bayesian approaches
36Check — who wins as the data piles up?
3 · Conjugate pairs
38Conjugacy — recognise the same family after updating
39Binomial–Beta recap — our template for the next models
40Counting events — why Poisson and Gamma?
41Poisson–Gamma updating — counts and exposure add
42The original example — Pokémon counts in 20 districts
43The count estimate — calculate
44The count estimate — interpret
45Experiment 5 — observe the districts one by one
46Predict one new district — rate uncertainty is not count noise
47Prior × likelihood — write down what is being multiplied
48Multiply out, collect, complete the square
49Normal observations — combine information by precision
50Four temperature readings — add the precisions
51Four temperature readings — weight the means
52Temperature thread — update an uncertain temperature
53Try it — the sensor variance rises to 4
54Experiment 6 — vary precision with the same average
55Normal prediction — restore the observation noise
56Experiment 7 — compare the mean and the next reading
57More than two outcomes — the Dirichlet update
58An unseen category need not get zero probability
59Experiment 8 — observe a previously unseen category
60Check — what uncertainty belongs in a new measurement?
4 · Bayesian regression and regularisation
62Problem solving — estimate a housing price
63Regression roadmap — the same model from several views
64Put a line into matrix form
65Least squares — use Lecture 1's optimality condition
66Solve the three-point regression by hand
67Why Gaussian noise turns MLE into least squares
68Experiment 9 — move the line and watch its residuals
69From MLE to Bayesian regression
70Complete the square again — now with a matrix
71Full Bayes keeps the distribution over weights
72Bayesian regression — one posterior in two spaces
73Experiment 10 — change data, watch the posterior over a line
74Regression prediction — a line and a noisy observation
75When the integral is hard — simulate the two stages
76Why regularise a regression?
77Why shrinkage helps — and what it changes
78Experiment 11 — compare training fit with validation error
79Add a Gaussian prior — derive ridge, not just name it
80Lasso — a different prior changes the penalty
81Experiment 12 — see why ridge shrinks and lasso can select
82Check — the prior wearing a disguise
83What we can now calculate
84Questions?
Appendix · extra derivations and checks
86Reading guide — one Bayesian calculation, several observation models
87Backup — integrate the Beta–Binomial prediction
88Backup — MLE, MAP and posterior mean
89Backup — when does prior influence fade?
90Backup — checking a fitted probability model
91Backup — Beta–Binomial normalisation and moments
92Backup — the Poisson–Gamma predictive distribution
93Backup — the Dirichlet predictive distribution
94Backup — complete the square for the Normal mean
95Backup — three remarks on the regression posterior