MIT 6.790 — Lecture 6

Uncertainty, Regularizers, and Features

§ Aleatoric vs. Epistemic Uncertainty

There are two types of uncertainty that we would like to conceptually differentiate here.

Aleatoric Uncertainty. This refers to uncertainty caused by the intrinsic randomness in how the response y(n)y^{(n)} relates to the feature vector x(n)x^{(n)}. It's the uncertainty in the PDF p(yx,θ)p(y \mid x, \theta).

Epistemic Uncertainty. This refers to uncertainty caused by an incomplete model of the data being perceived. It's the uncertainty in the posterior p(θX,Y)p(\theta \mid X, Y) caused by an insufficient amount of data.

Reading in more data will generally lessen the epistemic uncertainty, but more data won't be able to help with aleatoric uncertainty. As Lecture 5 showed, a misspecified model will produce great aleatoric uncertainty, yet the posterior overconfidently presents itself with very high epistemic certainty as it receives more data.

Remark. This overconfidence isn't unique to the Bayesian setting, of course; in the frequentist setting, standard errors and CI-widths also generally decrease as more data is read, even if the aleatoric uncertainty remains high.

§ MAP for Bayesian Linear Regression

We'll make some simplifying assumptions about our prior: assume θN(0,σ02ID)\theta \sim \mathcal{N}(0, \sigma_0^2 \cdot I_D), where DD is the feature dimension. Then the posterior looks like the following; compare with the proof in Lecture 5, perhaps.

p(θX,Y)exp(YXθ22σ2) LN(θ)exp(θ22σ02) p(θ).p(\theta \mid X, Y) \propto \underbrace{\mathrm{exp}\left( -\frac{\|Y - X\theta\|^2}{2\sigma^2} \right)}_{ \propto ~ L_N(\theta) } \cdot \underbrace{\mathrm{exp}\left( -\frac{\|\theta\|^2}{2\sigma_0^2} \right)}_{\propto ~ p(\theta)}.

Then the maximum a posteriori (MAP) satisfies the following:

Theorem. (Bayesian MAP) The maximum a posteriori for Bayesian linear regression, under the prior θN(0,σ02ID)\theta \sim \mathcal{N}(0, \sigma_0^2 I_D), is:

θ^MAP=arg minθ[XθY2+σ2σ02θ2]=(σ2σ02ID+XX)1XY.\hat{\theta}_{\mathrm{MAP}} = \argmin_{\theta} \left[ \|X\theta - Y\|^2 + \frac{\sigma^2}{\sigma_0^2}\|\theta\|^2 \right] = \left(\frac{\sigma^2}{\sigma_0^2}I_D + X^{\top}X\right)^{-1} X^{\top}Y.

Proof: The first equality is trivial, so it remains to show the RHS expression for θ^MAP\hat{\theta}_{\mathrm{MAP}} minimizes the middle expression. A shortcut is to just reuse the results we derived from Lecture 5, but for (μ0,Σ0)=(0,σ02ID)(\mu_0, \Sigma_0) = (0, \sigma_0^2 I_D).

ΣN1=1σ02ID+1σ2XX    and    ΣN1μN=1σ2XY.\Sigma_N^{-1} = \frac{1}{\sigma_0^2} I_D + \frac{1}{\sigma^2} X^{\top}X ~~~ \text{ and } ~~~ \Sigma_N^{-1}\mu_N = \frac{1}{\sigma^2}X^{\top}Y.

The posterior distribution is a Gaussian N(μN,ΣN)\mathcal{N}(\mu_N, \Sigma_N), so it is maximized at θ^MAP=μN\hat{\theta}_{\mathrm{MAP}} = \mu_N. The result falls right out from there.   \blacksquare

The quantity being minimized in the theorem statement above is referred to as the ridge regression objective.

It is the sum of our ordinary squared-loss and a new “ridge regression term”, the latter of which penalizes point estimates θ^MAP\hat{\theta}_{\mathrm{MAP}} that have needlessly large coefficients—large coefficients in θ^MAP\hat{\theta}_{\mathrm{MAP}} often suggest overfitting.

We'll oftentimes denote λ:=σ2σ02\lambda := \frac{\sigma^2}{\sigma_0^2} in the ridge regression objective and expression for θ^MAP\hat{\theta}_{\mathrm{MAP}}. Note that, while we can choose the value of σ0\sigma_0 in our prior, we usually have no control or knowledge regarding σ\sigma. So the value of λ\lambda can alternatively be interpreted as a parameter of our choosing that indicates how strongly we want to discourage overfitting.

§ Features

Let's stop restricting ourselves to linear models. The idea is to create our own feature vectors whose entries are nonlinear functions of the entries of the feature vectors {x(n)}n=1N\{x^{(n)}\}_{n = 1}^N.

Definition. We define our own features as ϕ:RDRP\phi: \mathbb{R}^D \to \mathbb{R}^P and write our regression hypothesis as h(x)=θϕ(x)h(x) = \theta^{\top} \phi(x).

Example. In the case of D=1D = 1, we might take ϕ(x):=[1xx2]\phi(x) := \begin{bmatrix} 1 & x & x^2 \end{bmatrix}^{\top}, which yields the hypothesis h(x)=θ0+θ1x+θ2x2h(x) = \theta_0 + \theta_1x + \theta_2x^2.

Example. In the case of D=2D = 2, we might take ϕ(x):=[1x1x2x12x22x1x2]\phi(x) := \begin{bmatrix} 1 & x_1 & x_2 & x_1^2 & x_2^2 & x_1x_2 \end{bmatrix}^{\top}, and the set of all possible hypotheses becomes the set of all two-variable quadratic polynomials.

Here's how regression performs when we get nonlinear features involved.

Notice how setting the feature dimension PP too large results in overfitting, to the point where our degree-99 regression is just performing Lagrange interpolation. To reduce overfitting, let's bring back a trick from just a few paragraphs ago: ridge regression.

And so degree-99 regression works just fine with a ridge regression term using λ=e18\lambda = e^{-18}.

§ Kernel: Unlimited Features

There's another reason why too many features is bad: if we let ΦRN×P\Phi \in \mathbb{R}^{N \times P} (with rows ϕ(x(n))\phi(x^{(n)})^{\top}) be our stand-in for XRN×DX \in \mathbb{R}^{N \times D}, then the ridge solution looks like:

θ^MAP=(λIP+ΦΦ)1ΦY.\hat{\theta}_{\mathrm{MAP}} = \left( \lambda I_P + \Phi^{\top}\Phi \right)^{-1} \Phi^{\top}Y.

Computing this would require a P×PP \times P matrix inversion, which is far too computationally intensive for PDP \gg D. So it seems like there is an upper bound on the number of features PP we can reasonably have.

Or maybe there isn't! We claim that there is an alternative way to approach our computation of ridge regressions that allows for PP to be arbitrarily large at no computational cost; the rest of this section is dedicated to showing how.

First, we claim the following theorem is true; the proof is unenlightening algebraic manipulation, so we omit it.

Theorem. (Bayesian MAP, Rewritten) The ridge solution θ^MAP\hat{\theta}_{\mathrm{MAP}} may be expressed as:

θ^MAP=Φ(λIN+ΦΦ)1Y.\hat{\theta}_{\mathrm{MAP}} = \Phi^{\top}\left( \lambda I_N + \Phi\Phi^{\top} \right)^{-1}Y.

Note, importantly, that this implies that the ridge regression may be expressed as:

h(x)=θ^MAPϕ(x)=Y(λIN+ΦΦ)1Φϕ(x).h(x) = \hat{\theta}^{\top}_{\mathrm{MAP}} \phi(x) = Y^{\top}\left( \lambda I_N + \Phi\Phi^{\top} \right)^{-1} \Phi \phi(x).

In this form, it turns out that there's a great amount of simplification to be made if we introduce the following:

Definition. The kernel is the function k ⁣:X×XRk \colon \mathcal{X} \times \mathcal{X} \to \mathbb{R} (where X\mathcal{X} is the input space) given by k(x(i),x(j)):=ϕ(x(i))ϕ(x(j))k(x^{(i)}, x^{(j)}) := \phi^{\top}(x^{(i)}) \phi(x^{(j)}).

We can now again rewrite the ridge regression formula using the language of the kernel.

Theorem. (Bayesian MAP, w/ Kernel) The ridge regression may be expressed as:

h(x)=Y(λIN+K)1k(x).h(x) = Y^{\top}\left(\lambda I_N + K\right)^{-1} k(x).

Here's the upshot of all of this: the expression above only deals with matrices in RN×N\mathbb{R}^{N \times N} and vectors in RN\mathbb{R}^{N}; there's no dependency on PP anywhere! So as long as we can efficiently compute the kernel k ⁣:X×XRk \colon \mathcal{X} \times \mathcal{X} \to \mathbb{R}, we can set our number of features PP as large as we'd like.