first-course-ml

Chapter 3: The Bayesian approach, a quick recap

Short revision notes. Exercises are not covered.

The big idea

Chapter 2 showed that estimates of the parameters carry uncertainty. Chapter 3 takes the next step: treat the parameters themselves as random variables, put a distribution on them before seeing data (the prior), and update it with the data to get the posterior. Instead of one best value you keep a whole distribution that says which values are plausible and how sure we are.

Bayes’ rule for a parameter

\[p(\theta \mid \text{data}) = \frac{p(\text{data} \mid \theta)\; p(\theta)}{p(\text{data})}\]

Only the shape matters when you work out the posterior: posterior \(\propto\) likelihood \(\times\) prior.

Example 1: the coin game (beta prior, binomial likelihood)

Maximum likelihood from one short run of tosses can give an extreme value, and it hides how little data there is. The Bayesian version asks for a distribution over the head probability \(r\).

Three priors. Uniform (“know nothing”), a sharp peak at 0.5 (“fair coin”) and a skew to heads (“biased”):

Predictions. Predict by averaging over the posterior, \(\mathbb{E}_{p(r\mid y)}\{P(\text{future outcome}\mid r)\}\), rather than plugging in one point estimate. The two agree more closely as the posterior gets narrower. With few data, the full average accounts for the remaining uncertainty and the point estimate ignores it.

Marginal likelihood for choosing priors

Integrate \(r\) out given the prior parameters: \(p(y\mid\alpha,\beta)=\int p(y\mid r)\,p(r\mid\alpha,\beta)\,dr\). A higher value means the prior setting agrees better with the data, so it can pick among the three priors. For the beta-binomial case it has a closed form. Searching over \(\alpha,\beta\) to maximise it is called Type II maximum likelihood. Caution: the prior then no longer represents beliefs held before seeing the data.

Hyper-parameters and graphical models

Example 2: Bayesian linear regression (Olympics data)

Model: \(\mathbf t = \mathbf X\mathbf w + \boldsymbol\epsilon\), noise \(\epsilon_n\sim\mathcal N(0,\sigma^2)\), with \(\sigma^2\) taken as known.

\[\boldsymbol\Sigma_w = \Big(\tfrac{1}{\sigma^2}\mathbf X^T\mathbf X + \boldsymbol\Sigma_0^{-1}\Big)^{-1}, \qquad \boldsymbol\mu_w = \boldsymbol\Sigma_w\Big(\tfrac{1}{\sigma^2}\mathbf X^T\mathbf t + \boldsymbol\Sigma_0^{-1}\boldsymbol\mu_0\Big).\]

Prediction. Average the model over the posterior:

\[p(t_{\text{new}}\mid \mathbf x_{\text{new}},\mathbf X,\mathbf t,\sigma^2)=\mathcal N\!\big(\mathbf x_{\text{new}}^T\boldsymbol\mu_w,\ \ \sigma^2+\mathbf x_{\text{new}}^T\boldsymbol\Sigma_w\mathbf x_{\text{new}}\big).\]

It looks like the maximum-likelihood predictive density, but it averages over every parameter setting that fits the data and prior, rather than committing to one.

Marginal likelihood for choosing model order

The marginal likelihood of the data under a polynomial model is again Gaussian, \(\mathcal N\big(\mathbf X\boldsymbol\mu_0,\ \sigma^2\mathbf I+\mathbf X\boldsymbol\Sigma_0\mathbf X^T\big)\), evaluated at the observed \(\mathbf t\).

Take-aways

  1. Treat parameters as random variables; prior \(\times\) likelihood gives the posterior.
  2. Conjugate pairs give closed-form posteriors: beta with binomial, Gaussian with Gaussian.
  3. Strong priors resist data; with enough data the prior stops mattering.
  4. Predict by averaging over the posterior, not by plugging in a point.
  5. The marginal likelihood compares priors and models, but is rarely tractable. Chapter 4 covers approximations.