Bayesian Linear Regression

Volume II, Chapter 5 — Part I. Full Bayesian treatment of linear regression: conjugate Gaussian prior, closed-form posterior derivation, predictive distribution with epistemic and aleatoric uncertainty, MAP–Ridge equivalence, sequential updating, and the kernel dual form leading to Gaussian processes.

Intermediate

Table of Contents

  1. Learning Objectives
  2. Prerequisites
  3. Notation
  4. Core Intuition
  5. From MLE to MAP to Full Bayesian Inference
  6. The Conjugate Gaussian Model
  7. Posterior Derivation via Gaussian Identities
  8. The Predictive Distribution
  9. Epistemic and Aleatoric Uncertainty
  10. Sequential Bayesian Updating
  11. Connection to Ridge Regression
  12. Computational Identities: Woodbury and Dual Form
  13. Connection to Gaussian Processes
  14. Worked Examples
  15. Connection to the Broader Curriculum
  16. Common Pitfalls and Misconceptions
  17. Research Perspective
  18. Summary of Takeaways
  19. Exercises

Learning Objectives

After reading this chapter, you should be able to:

  1. Distinguish MLE, MAP, and full Bayesian inference for linear regression and explain what each provides.
  2. Specify a conjugate Gaussian prior–likelihood pair and derive the posterior Pr(θX,y)\Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) in closed form.
  3. Compute the posterior predictive distribution Pr(yx,X,y)\Pr(y^* \mid \mathbf{x}^*, \mathbf{X}, \mathbf{y}) and decompose its variance into epistemic and aleatoric components.
  4. Prove that MAP estimation with a Gaussian prior is equivalent to Ridge regression.
  5. Perform sequential Bayesian updating via precision-matrix rank-1 additions.
  6. Apply the Woodbury identity to convert between primal (D×DD \times D) and dual (N×NN \times N) formulations.
  7. Recognize the Gaussian process prediction formula as the kernel dual of Bayesian linear regression.

Prerequisites

This chapter assumes familiarity with:


Notation

  • w\mathbf{w} — Regression weights (random vector)
  • mN,SN\mathbf{m}_N, \mathbf{S}_N — Posterior mean and covariance
  • m0,S0\mathbf{m}_0, \mathbf{S}_0 — Prior mean and covariance
  • α,β\alpha, \beta — Prior precision and noise precision
  • p(wD)p(\mathbf{w} \mid \mathcal{D}) — Posterior over weights

Core Intuition

Classical linear regression returns a point estimate θ^\hat{\boldsymbol{\theta}} — a single best guess for the parameters. Bayesian linear regression returns a distribution over parameters, encoding which settings are plausible given the data and prior beliefs.

Why does this matter?

  1. Uncertainty quantification. Predictions come with confidence intervals that widen when extrapolating beyond training data.
  2. Regularization with meaning. A prior Pr(θ)\Pr(\boldsymbol{\theta}) is not an ad hoc penalty — it encodes genuine beliefs about parameter magnitude before seeing data.
  3. Sequential learning. New data updates the posterior directly; the old posterior becomes the new prior.
  4. Foundation for advanced methods. Variational inference, Gaussian processes, and Bayesian neural networks all extend the framework developed here.

For linear regression with Gaussian noise and a Gaussian prior, the posterior is exactly Gaussian — no approximation needed. This conjugacy makes Bayesian linear regression one of the few models where full Bayesian inference is analytically tractable.

Series context. This opens Chapter 5 (Bayesian Machine Learning) in Volume II. It is followed by Variational Inference, which handles models where the posterior is not conjugate.

Bayesian Linear Regression

N = 3σ_post ≈ 1.597
Data pts
3
2σ bandPosterior mean
Explore: With no data, the wide prior band reflects uncertainty. As points arrive, the posterior narrows around the best-fit slope.

From MLE to MAP to Full Bayesian Inference

Definition 1 (Likelihood). Given the Gaussian noise model yi=θTx~i+εiy_i = \boldsymbol{\theta}^T \tilde{\mathbf{x}}_i + \varepsilon_i with εiN(0,σn2)\varepsilon_i \sim \mathcal{N}(0, \sigma_n^2), the likelihood of parameters θ\boldsymbol{\theta} is

Pr(yX,θ)=N(yXθ,σn2IN).(1)\Pr(\mathbf{y} \mid \mathbf{X}, \boldsymbol{\theta}) = \mathcal{N}(\mathbf{y} \mid \mathbf{X}\boldsymbol{\theta}, \sigma_n^2 \mathbf{I}_N). \tag{1}

We use the standard design matrix convention XRN×(d+1)\mathbf{X} \in \mathbb{R}^{N \times (d+1)} with y^i=θTx~i\hat{y}_i = \boldsymbol{\theta}^T \tilde{\mathbf{x}}_i, so yN(Xθ,σn2I)\mathbf{y} \sim \mathcal{N}(\mathbf{X}\boldsymbol{\theta}, \sigma_n^2 \mathbf{I}).

Definition 2 (Three Inference Paradigms).

  • MLEθ^ML=argmaxθPr(yX,θ)\hat{\boldsymbol{\theta}}_{\text{ML}} = \arg\max_{\boldsymbol{\theta}} \Pr(\mathbf{y} \mid \mathbf{X}, \boldsymbol{\theta}) — Point estimate
  • MAPθ^MAP=argmaxθPr(θX,y)\hat{\boldsymbol{\theta}}_{\text{MAP}} = \arg\max_{\boldsymbol{\theta}} \Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) — Point estimate (posterior mode)
  • Bayesian — Compute Pr(θX,y)\Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) — Full posterior distribution

Proposition 1 (MLE = OLS). The MLE is the ordinary least squares solution:

θ^ML=(XTX)1XTy.(2)\hat{\boldsymbol{\theta}}_{\text{ML}} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}. \tag{2}

Proof. Maximizing the Gaussian log-likelihood is equivalent to minimizing Xθy2\|\mathbf{X}\boldsymbol{\theta} - \mathbf{y}\|^2. See Linear Regression. \blacksquare

Proposition 2 (Bayes' Rule for Parameters).

Pr(θX,y)=Pr(yX,θ)Pr(θ)Pr(yX).(3)\Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) = \frac{\Pr(\mathbf{y} \mid \mathbf{X}, \boldsymbol{\theta})\, \Pr(\boldsymbol{\theta})}{\Pr(\mathbf{y} \mid \mathbf{X})}. \tag{3}

The marginal likelihood Pr(yX)=Pr(yX,θ)Pr(θ)dθ\Pr(\mathbf{y} \mid \mathbf{X}) = \int \Pr(\mathbf{y} \mid \mathbf{X}, \boldsymbol{\theta})\Pr(\boldsymbol{\theta})\, d\boldsymbol{\theta} is the evidence. For conjugate models, it is analytically computable.


The Conjugate Gaussian Model

Definition 3 (Gaussian Prior). We place an isotropic Gaussian prior on parameters:

Pr(θ)=N(θ0,σp2Id+1).(4)\Pr(\boldsymbol{\theta}) = \mathcal{N}(\boldsymbol{\theta} \mid \mathbf{0}, \sigma_p^2 \mathbf{I}_{d+1}). \tag{4}

The prior mean 0\mathbf{0} reflects a belief that parameters should be small. The prior variance σp2\sigma_p^2 controls strength: large σp2\sigma_p^2 is a weak (vague) prior; small σp2\sigma_p^2 strongly shrinks parameters toward zero.

Definition 4 (Conjugacy). A prior is conjugate to a likelihood if the posterior belongs to the same parametric family as the prior. The Gaussian prior is conjugate to the Gaussian likelihood — the posterior is Gaussian.

Theorem 1 (Posterior Distribution). Under the Gaussian likelihood (1) and Gaussian prior (4), the posterior is

Pr(θX,y)=N(θμpost,Σpost),(5)\Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) = \mathcal{N}(\boldsymbol{\theta} \mid \boldsymbol{\mu}_{\text{post}}, \boldsymbol{\Sigma}_{\text{post}}), \tag{5}

with

Σpost1=1σn2XTX+1σp2I,(6)\boldsymbol{\Sigma}_{\text{post}}^{-1} = \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{X} + \frac{1}{\sigma_p^2}\mathbf{I}, \tag{6} μpost=Σpost1σn2XTy.(7)\boldsymbol{\mu}_{\text{post}} = \boldsymbol{\Sigma}_{\text{post}} \cdot \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{y}. \tag{7}

Equivalently, in closed form:

μpost=(XTX+σn2σp2I)1XTy,Σpost=σn2(XTX+σn2σp2I)1.(8)\boldsymbol{\mu}_{\text{post}} = \left(\mathbf{X}^T\mathbf{X} + \frac{\sigma_n^2}{\sigma_p^2}\mathbf{I}\right)^{-1}\mathbf{X}^T\mathbf{y}, \quad \boldsymbol{\Sigma}_{\text{post}} = \sigma_n^2\left(\mathbf{X}^T\mathbf{X} + \frac{\sigma_n^2}{\sigma_p^2}\mathbf{I}\right)^{-1}. \tag{8}

Posterior Derivation via Gaussian Identities

We prove Theorem 1 using two fundamental identities for multivariate Gaussians.

Lemma 1 (Likelihood as Gaussian in θ\boldsymbol{\theta}). Rewriting the likelihood as a function of θ\boldsymbol{\theta}:

N(yXθ,σn2I)N(θμ,Σ),(9)\mathcal{N}(\mathbf{y} \mid \mathbf{X}\boldsymbol{\theta}, \sigma_n^2 \mathbf{I}) \propto \mathcal{N}(\boldsymbol{\theta} \mid \boldsymbol{\mu}_\ell, \boldsymbol{\Sigma}_\ell), \tag{9}

where Σ1=1σn2XTX\boldsymbol{\Sigma}_\ell^{-1} = \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{X} and μ=Σ1σn2XTy\boldsymbol{\mu}_\ell = \boldsymbol{\Sigma}_\ell \cdot \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{y}.

Proof. Complete the square in θ\boldsymbol{\theta}:

yXθ2=(θμ)TΣ1(θμ)+const(y).(10)\|\mathbf{y} - \mathbf{X}\boldsymbol{\theta}\|^2 = (\boldsymbol{\theta} - \boldsymbol{\mu}_\ell)^T \boldsymbol{\Sigma}_\ell^{-1} (\boldsymbol{\theta} - \boldsymbol{\mu}_\ell) + \text{const}(\mathbf{y}). \tag{10}

The exponent of the Gaussian density in θ\boldsymbol{\theta} is 12(θμ)TΣ1(θμ)-\frac{1}{2}(\boldsymbol{\theta} - \boldsymbol{\mu}_\ell)^T \boldsymbol{\Sigma}_\ell^{-1}(\boldsymbol{\theta} - \boldsymbol{\mu}_\ell). \blacksquare

Lemma 2 (Product of Gaussians). For two Gaussians in the same variable:

N(θa,A)N(θb,B)N(θc,C),(11)\mathcal{N}(\boldsymbol{\theta} \mid \mathbf{a}, \mathbf{A}) \cdot \mathcal{N}(\boldsymbol{\theta} \mid \mathbf{b}, \mathbf{B}) \propto \mathcal{N}(\boldsymbol{\theta} \mid \mathbf{c}, \mathbf{C}), \tag{11}

where

C1=A1+B1,c=C(A1a+B1b).(12)\mathbf{C}^{-1} = \mathbf{A}^{-1} + \mathbf{B}^{-1}, \quad \mathbf{c} = \mathbf{C}(\mathbf{A}^{-1}\mathbf{a} + \mathbf{B}^{-1}\mathbf{b}). \tag{12}

Proof. Expanding both exponents and collecting quadratic and linear terms in θ\boldsymbol{\theta}:

12θT(A1+B1)θ+θT(A1a+B1b)+const.(13)-\frac{1}{2}\boldsymbol{\theta}^T(\mathbf{A}^{-1} + \mathbf{B}^{-1})\boldsymbol{\theta} + \boldsymbol{\theta}^T(\mathbf{A}^{-1}\mathbf{a} + \mathbf{B}^{-1}\mathbf{b}) + \text{const}. \tag{13}

Completing the square yields (12). \blacksquare

Proof of Theorem 1. The posterior is proportional to likelihood ×\times prior:

Pr(θX,y)N(θμ,Σ)N(θ0,σp2I).(14)\Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) \propto \mathcal{N}(\boldsymbol{\theta} \mid \boldsymbol{\mu}_\ell, \boldsymbol{\Sigma}_\ell) \cdot \mathcal{N}(\boldsymbol{\theta} \mid \mathbf{0}, \sigma_p^2 \mathbf{I}). \tag{14}

Applying Lemma 2 with A=Σ\mathbf{A} = \boldsymbol{\Sigma}_\ell, a=μ\mathbf{a} = \boldsymbol{\mu}_\ell, B=σp2I\mathbf{B} = \sigma_p^2 \mathbf{I}, b=0\mathbf{b} = \mathbf{0}:

Σpost1=Σ1+1σp2I=1σn2XTX+1σp2I,(15)\boldsymbol{\Sigma}_{\text{post}}^{-1} = \boldsymbol{\Sigma}_\ell^{-1} + \frac{1}{\sigma_p^2}\mathbf{I} = \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{X} + \frac{1}{\sigma_p^2}\mathbf{I}, \tag{15} μpost=Σpost(Σ1μ)=Σpost1σn2XTy.(16)\boldsymbol{\mu}_{\text{post}} = \boldsymbol{\Sigma}_{\text{post}} \left(\boldsymbol{\Sigma}_\ell^{-1}\boldsymbol{\mu}_\ell\right) = \boldsymbol{\Sigma}_{\text{post}} \cdot \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{y}. \tag{16}

Normalizing gives the full posterior (5). \blacksquare

Important equation. Equation (8) shows that the posterior mean equals the Ridge regression solution with λ=σn2/σp2\lambda = \sigma_n^2/\sigma_p^2. Bayesian inference and regularized frequentist estimation coincide for point predictions — but the Bayesian framework additionally provides Σpost\boldsymbol{\Sigma}_{\text{post}} for uncertainty.


The Predictive Distribution

Definition 5 (Posterior Predictive). For a new input x\mathbf{x}^*, the posterior predictive distribution is

Pr(yx,X,y)=Pr(yx,θ)Pr(θX,y)dθ.(17)\Pr(y^* \mid \mathbf{x}^*, \mathbf{X}, \mathbf{y}) = \int \Pr(y^* \mid \mathbf{x}^*, \boldsymbol{\theta})\, \Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y})\, d\boldsymbol{\theta}. \tag{17}

Theorem 2 (Predictive Distribution). Under the conjugate Gaussian model:

Pr(yx,X,y)=N(y    μpostTx~,    x~TΣpostx~+σn2).(18)\Pr(y^* \mid \mathbf{x}^*, \mathbf{X}, \mathbf{y}) = \mathcal{N}\left(y^* \;\Big|\; \boldsymbol{\mu}_{\text{post}}^T \tilde{\mathbf{x}}^*,\;\; \tilde{\mathbf{x}}^{*T}\boldsymbol{\Sigma}_{\text{post}}\tilde{\mathbf{x}}^* + \sigma_n^2\right). \tag{18}

Proof. Both factors in (17) are Gaussian:

Pr(yx,θ)=N(yθTx~,σn2),Pr(θX,y)=N(θμpost,Σpost).(19)\Pr(y^* \mid \mathbf{x}^*, \boldsymbol{\theta}) = \mathcal{N}(y^* \mid \boldsymbol{\theta}^T \tilde{\mathbf{x}}^*, \sigma_n^2), \quad \Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) = \mathcal{N}(\boldsymbol{\theta} \mid \boldsymbol{\mu}_{\text{post}}, \boldsymbol{\Sigma}_{\text{post}}). \tag{19}

The integral is a convolution of Gaussians. The predictive mean is E[θTx~]=μpostTx~\mathbb{E}[\boldsymbol{\theta}^T \tilde{\mathbf{x}}^*] = \boldsymbol{\mu}_{\text{post}}^T \tilde{\mathbf{x}}^*. The predictive variance is:

Var(y)=x~TΣpostx~epistemic+σn2aleatoric.(20)\text{Var}(y^*) = \underbrace{\tilde{\mathbf{x}}^{*T}\boldsymbol{\Sigma}_{\text{post}}\tilde{\mathbf{x}}^*}_{\text{epistemic}} + \underbrace{\sigma_n^2}_{\text{aleatoric}}. \tag{20}

The epistemic term arises from uncertainty in θ\boldsymbol{\theta}; the aleatoric term is irreducible observation noise. \blacksquare


Epistemic and Aleatoric Uncertainty

Definition 6 (Epistemic Uncertainty). Epistemic (model) uncertainty reflects incomplete knowledge about θ\boldsymbol{\theta}. It is reducible with more data — as NN \to \infty, Σpost0\boldsymbol{\Sigma}_{\text{post}} \to \mathbf{0} and epistemic uncertainty vanishes.

Definition 7 (Aleatoric Uncertainty). Aleatoric (data) uncertainty reflects inherent noise in observations. It is irreducible regardless of sample size.

Proposition 3 (Extrapolation Behavior). As x~\|\tilde{\mathbf{x}}^*\| \to \infty in directions poorly covered by training data, x~TΣpostx~\tilde{\mathbf{x}}^{*T}\boldsymbol{\Sigma}_{\text{post}}\tilde{\mathbf{x}}^* \to \infty and predictive uncertainty grows without bound.

Proof sketch. Σpost\boldsymbol{\Sigma}_{\text{post}} is positive definite (for any λ>0\lambda > 0). For x~\tilde{\mathbf{x}}^* orthogonal to the column space of X\mathbf{X}, x~T(XTX)x~=0\tilde{\mathbf{x}}^{*T}(\mathbf{X}^T\mathbf{X})\tilde{\mathbf{x}}^* = 0, so the prior term dominates and x~TΣpostx~σp2x~2\tilde{\mathbf{x}}^{*T}\boldsymbol{\Sigma}_{\text{post}}\tilde{\mathbf{x}}^* \approx \sigma_p^2 \|\tilde{\mathbf{x}}^*\|^2. \blacksquare

This is a principled mechanism for knowing what you don't know — something point estimates cannot provide.


Sequential Bayesian Updating

Theorem 3 (Online Update). After observing a new data point (x~new,ynew)(\tilde{\mathbf{x}}_{\text{new}}, y_{\text{new}}), the updated posterior precision is

Σnew1=Σold1+1σn2x~newx~newT.(21)\boldsymbol{\Sigma}_{\text{new}}^{-1} = \boldsymbol{\Sigma}_{\text{old}}^{-1} + \frac{1}{\sigma_n^2}\tilde{\mathbf{x}}_{\text{new}}\tilde{\mathbf{x}}_{\text{new}}^T. \tag{21}

The updated mean satisfies

μnew=Σnew(Σold1μold+1σn2x~newynew).(22)\boldsymbol{\mu}_{\text{new}} = \boldsymbol{\Sigma}_{\text{new}}\left(\boldsymbol{\Sigma}_{\text{old}}^{-1}\boldsymbol{\mu}_{\text{old}} + \frac{1}{\sigma_n^2}\tilde{\mathbf{x}}_{\text{new}}\, y_{\text{new}}\right). \tag{22}

Proof. The old posterior becomes the new prior. Applying Lemma 2 with the new likelihood (rank-1 update to precision) yields (21)–(22). \blacksquare

Each observation adds a rank-1 term to the precision matrix — the posterior concentrates incrementally. This is the Bayesian analog of recursive least squares.


Connection to Ridge Regression

Theorem 4 (MAP–Ridge Equivalence). The MAP estimator under prior (4) is

θ^MAP=argmaxθPr(θX,y)=(XTX+σn2σp2I)1XTy.(23)\hat{\boldsymbol{\theta}}_{\text{MAP}} = \arg\max_{\boldsymbol{\theta}} \Pr(\boldsymbol{\theta} \mid \mathbf{X}, \mathbf{y}) = \left(\mathbf{X}^T\mathbf{X} + \frac{\sigma_n^2}{\sigma_p^2}\mathbf{I}\right)^{-1}\mathbf{X}^T\mathbf{y}. \tag{23}

This is Ridge regression with regularization parameter λ=σn2/σp2\lambda = \sigma_n^2/\sigma_p^2.

Proof. The MAP maximizes logPr(yX,θ)+logPr(θ)\log \Pr(\mathbf{y} \mid \mathbf{X}, \boldsymbol{\theta}) + \log \Pr(\boldsymbol{\theta}), equivalent to minimizing:

12σn2Xθy2+12σp2θ2.(24)\frac{1}{2\sigma_n^2}\|\mathbf{X}\boldsymbol{\theta} - \mathbf{y}\|^2 + \frac{1}{2\sigma_p^2}\|\boldsymbol{\theta}\|^2. \tag{24}

Setting the gradient to zero gives (23). \blacksquare

Interpretation. λ=σn2/σp2\lambda = \sigma_n^2/\sigma_p^2 is the ratio of observation noise to prior uncertainty. Noisy data (σn2\sigma_n^2 large)     \implies weak regularization. Strong prior (σp2\sigma_p^2 small)     \implies strong shrinkage.


Computational Identities: Woodbury and Dual Form

When NdN \ll d (few samples, many features), inverting XTX\mathbf{X}^T\mathbf{X} is expensive. The Woodbury matrix identity converts between primal and dual forms.

Lemma 3 (Woodbury Identity). For conformable matrices:

(A1+BTC1B)1BTC1=ABT(BABT+C)1.(25)(\mathbf{A}^{-1} + \mathbf{B}^T\mathbf{C}^{-1}\mathbf{B})^{-1}\mathbf{B}^T\mathbf{C}^{-1} = \mathbf{A}\mathbf{B}^T(\mathbf{B}\mathbf{A}\mathbf{B}^T + \mathbf{C})^{-1}. \tag{25}

Proposition 4 (Dual Predictive Mean). Applying (25) with A=σp2I\mathbf{A} = \sigma_p^2 \mathbf{I}, B=X\mathbf{B} = \mathbf{X}, C=σn2I\mathbf{C} = \sigma_n^2 \mathbf{I}:

x~Tμpost=σp2x~TX(σp2XTX+σn2IN)1y.(26)\tilde{\mathbf{x}}^{*T}\boldsymbol{\mu}_{\text{post}} = \sigma_p^2 \tilde{\mathbf{x}}^{*T}\mathbf{X}\left(\sigma_p^2 \mathbf{X}^T\mathbf{X} + \sigma_n^2 \mathbf{I}_N\right)^{-1}\mathbf{y}. \tag{26}

The inversion is now N×NN \times N instead of (d+1)×(d+1)(d+1) \times (d+1) — efficient when NdN \ll d.


Connection to Gaussian Processes

Define the linear kernel k(x,x)=σp2x~Tx~k(\mathbf{x}, \mathbf{x}') = \sigma_p^2 \tilde{\mathbf{x}}^T \tilde{\mathbf{x}}'. The dual predictive distribution (26) becomes:

E[yx]=kT(K+σn2IN)1y,(27)\mathbb{E}[y^* \mid \mathbf{x}^*] = \mathbf{k}_*^T (\mathbf{K} + \sigma_n^2 \mathbf{I}_N)^{-1} \mathbf{y}, \tag{27} Var(yx)=k(x,x)kT(K+σn2IN)1k+σn2,(28)\text{Var}(y^* \mid \mathbf{x}^*) = k(\mathbf{x}^*, \mathbf{x}^*) - \mathbf{k}_*^T (\mathbf{K} + \sigma_n^2 \mathbf{I}_N)^{-1} \mathbf{k}_* + \sigma_n^2, \tag{28}

where Kij=k(x~i,x~j)\mathbf{K}_{ij} = k(\tilde{\mathbf{x}}_i, \tilde{\mathbf{x}}_j) and k=[k(x~1,x~),,k(x~N,x~)]T\mathbf{k}_* = [k(\tilde{\mathbf{x}}_1, \tilde{\mathbf{x}}^*), \ldots, k(\tilde{\mathbf{x}}_N, \tilde{\mathbf{x}}^*)]^T.

This is the Gaussian process prediction formula with a linear kernel. Replacing the kernel with a nonlinear function (e.g., RBF) yields nonlinear Bayesian regression without explicit feature engineering — the function-space view of the same mathematics.


Worked Examples

Example 1: Single-Feature Model

Prior: σp2=1\sigma_p^2 = 1, σn2=0.5\sigma_n^2 = 0.5. One observation: x~=(1,2)T\tilde{\mathbf{x}} = (1, 2)^T, y=3y = 3.

Σpost1=10.5[12][12]+I=[3449],μpost=[39]1[612].(29)\boldsymbol{\Sigma}_{\text{post}}^{-1} = \frac{1}{0.5}\begin{bmatrix}1\\2\end{bmatrix}\begin{bmatrix}1 & 2\end{bmatrix} + \mathbf{I} = \begin{bmatrix}3 & 4\\4 & 9\end{bmatrix}, \quad \boldsymbol{\mu}_{\text{post}} = \begin{bmatrix}3\\9\end{bmatrix}^{-1}\begin{bmatrix}6\\12\end{bmatrix}. \tag{29}

The posterior is tighter than the prior — data has reduced uncertainty.

Example 2: Predictive Uncertainty Near vs. Far from Data

For training points clustered near x~=(1,0)\tilde{\mathbf{x}} = (1, 0), prediction at x~=(1,0)\tilde{\mathbf{x}}^* = (1, 0) has small epistemic variance. At x~=(1,100)\tilde{\mathbf{x}}^* = (1, 100), epistemic variance is large — we are extrapolating.

Example 3: Limit of Flat Prior

As σp2\sigma_p^2 \to \infty: Σpost11σn2XTX\boldsymbol{\Sigma}_{\text{post}}^{-1} \to \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{X}, and μpostθ^ML\boldsymbol{\mu}_{\text{post}} \to \hat{\boldsymbol{\theta}}_{\text{ML}} (when XTX\mathbf{X}^T\mathbf{X} is invertible). The Bayesian posterior recovers the frequentist MLE.


Connection to the Broader Curriculum

Variational Autoencoders apply variational inference to latent variable models where the posterior over latents is approximated rather than computed exactly.


Common Pitfalls and Misconceptions

Pitfall 1: Confusing posterior variance with prediction interval width. The posterior Pr(θD)\Pr(\boldsymbol{\theta} \mid \mathcal{D}) describes uncertainty about parameters. Predictive intervals for yy^* include both epistemic and aleatoric terms (20).

Pitfall 2: Using an improper prior without care. The limit σp2\sigma_p^2 \to \infty yields an improper (non-normalizable) prior. Predictions may be valid, but the posterior may not exist when NdN \leq d.

Pitfall 3: Assuming Gaussian prior is always appropriate. Heavy-tailed priors (Student-tt) provide robustness to outliers. The Gaussian prior penalizes large coefficients quadratically.

Pitfall 4: Ignoring hyperparameter selection. σp2\sigma_p^2 and σn2\sigma_n^2 are hyperparameters. Empirical Bayes or cross-validation selects them; treating them as fixed without justification is a form of misspecification.

Pitfall 5: Conflating MAP with full Bayesian inference. MAP gives a point estimate (posterior mode). It ignores posterior covariance and can be sensitive to reparameterization — unlike the full predictive distribution (18).


Research Perspective

Bayesian linear models date to Laplace and Gauss. The modern formulation through conjugate analysis connects to empirical Bayes (Robbins, 1955; Efron & Morris, 1973) and hierarchical modeling.

In machine learning:

  • Gaussian Processes (Rasmussen & Williams, 2006) generalize Bayesian linear regression to infinite-dimensional function spaces via kernels.
  • Bayesian deep learning attempts to place priors on neural network weights — but the posterior is intractable, motivating Variational Inference.
  • Uncertainty quantification in safety-critical applications (medical diagnosis, autonomous driving) relies on principled epistemic uncertainty from Bayesian methods.
  • Last-layer Bayesian inference — treating only the final layer as Bayesian while keeping feature extractors deterministic — provides efficient uncertainty at scale.

The conjugate Gaussian case remains the gold standard: when it applies, use it exactly rather than approximating.


Summary of Takeaways

  • Posterior precisionΣpost1=1σn2XTX+1σp2I\boldsymbol{\Sigma}_{\text{post}}^{-1} = \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{X} + \frac{1}{\sigma_p^2}\mathbf{I} — Data + prior information
  • Posterior meanμpost=Σpost1σn2XTy\boldsymbol{\mu}_{\text{post}} = \boldsymbol{\Sigma}_{\text{post}} \frac{1}{\sigma_n^2}\mathbf{X}^T\mathbf{y} — = Ridge estimate
  • Predictive variancex~TΣpostx~+σn2\tilde{\mathbf{x}}^{*T}\boldsymbol{\Sigma}_{\text{post}}\tilde{\mathbf{x}}^* + \sigma_n^2 — Epistemic + aleatoric
  • Sequential updateΣnew1=Σold1+1σn2x~x~T\boldsymbol{\Sigma}_{\text{new}}^{-1} = \boldsymbol{\Sigma}_{\text{old}}^{-1} + \frac{1}{\sigma_n^2}\tilde{\mathbf{x}}\tilde{\mathbf{x}}^T — Online learning
  • MAP = Ridgeλ=σn2/σp2\lambda = \sigma_n^2/\sigma_p^2 — Bayesian interpretation of L2

Next article: Variational Inference → — for models where the posterior is not conjugate and must be approximated.


Exercises

Exercise 1 (Posterior derivation). Verify Theorem 1 by completing the square directly in θ\boldsymbol{\theta} without using Lemma 2.

Exercise 2 (Predictive distribution). Derive (18) by evaluating the integral (17) using the formula for the convolution of two Gaussians.

Exercise 3 (Sequential update). Starting from prior N(0,σp2I)\mathcal{N}(\mathbf{0}, \sigma_p^2 \mathbf{I}), derive the posterior after observing two data points sequentially. Show the result equals the posterior from observing both simultaneously.

Exercise 4 (MAP limit). Prove that as σp2\sigma_p^2 \to \infty, μpost(XTX)1XTy\boldsymbol{\mu}_{\text{post}} \to (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y} (when invertible).

Exercise 5 (Uncertainty decomposition). For a given dataset, compute the fraction of predictive variance that is epistemic vs. aleatoric at a test point near the training data centroid vs. far from it.

Exercise 6 (Woodbury). Derive (26) by applying the Woodbury identity to μpost\boldsymbol{\mu}_{\text{post}}.

Exercise 7 (Kernel form). Show that the GP formula (27)–(28) with linear kernel reproduces the Bayesian linear regression predictive distribution.

Exercise 8 (Conceptual). Explain why the posterior covariance Σpost\boldsymbol{\Sigma}_{\text{post}} does not depend on y\mathbf{y} — only on X\mathbf{X}, σn2\sigma_n^2, and σp2\sigma_p^2. What does this imply about uncertainty before seeing targets?