
EE 541 - Unit 4
Fall 2026
Regularization and the Bias-Variance Tradeoff
Information Theory and Loss Functions
MMSE: \(\hat{Y} = \mathbb{E}[Y|X]\)
Linear MMSE: \(\hat{Y} = \frac{\text{Cov}(X,Y)}{\text{Var}(X)}(X - \mathbb{E}[X]) + \mathbb{E}[Y]\)
In practice:
Empirical approximation:
\[\mathbb{E}[h(X)] \approx \frac{1}{n}\sum_{i=1}^n h(x_i)\]
\[\text{Cov}(X,Y) \approx \frac{1}{n}\sum_{i=1}^n (x_i - \bar{x})(y_i - \bar{y})\]

Population moments – require \(p(x)\): \[\mathbb{E}[X] = \int x \cdot p(x) \, dx\] \[\text{Var}(X) = \int (x - \mathbb{E}[X])^2 p(x) \, dx\]
Sample moments – require only data: \[\bar{X} = \frac{1}{n} \sum_{i=1}^n X_i, \qquad S_X^2 = \frac{1}{n} \sum_{i=1}^n (X_i - \bar{X})^2\]
Law of Large Numbers: \(\bar{X} \xrightarrow{a.s.} \mathbb{E}[X]\)
Central Limit Theorem: \(\sqrt{n}(\bar{X} - \mathbb{E}[X]) \xrightarrow{d} \mathcal{N}(0, \text{Var}(X))\)
Monte Carlo approximation: integrals become sums over samples

Population risk (what we want to minimize): \[R(f) = \mathbb{E}_{(X,Y)}[\ell(Y, f(X))]\] \[= \int\int \ell(y, f(x)) \, p(x,y) \, dx \, dy\]
Cannot compute without knowing \(p(x,y)\)
Empirical risk (what we can compute): \[\hat{R}_n(f) = \frac{1}{n} \sum_{i=1}^n \ell(y_i, f(x_i))\]
Empirical Risk Minimization (ERM): \[\hat{f}_n = \arg\min_{f \in \mathcal{F}} \hat{R}_n(f)\]
Convergence guarantee (fixed \(\mathcal{F}\), not too rich): \[R(\hat{f}_n) - \inf_{f \in \mathcal{F}} R(f) \xrightarrow{P} 0\]
Risk of the sample minimizer approaches the best risk in \(\mathcal{F}\)

Training error: \(\hat{R}_n(\hat{f}_n)\), the empirical risk of the fit on the data that produced it
Test error: \(\hat{R}(\hat{f}_n)\) on held-out data, an unbiased estimate of \(R(\hat{f}_n)\)
The order never changes (\(f^*\) the best in \(\mathcal{F}\)): \[\mathbb{E}[\hat{R}_n(\hat{f}_n)] \leq R(f^*) \leq \mathbb{E}[R(\hat{f}_n)]\]
Least squares, \(p\) weights, \(n\) samples, noise variance \(\sigma^2\):
Overfitting: the gap \(2\sigma^2 p/n\) grows with every added weight

ERM: Minimize a loss over data \[\hat{f} = \arg\min_{f} \frac{1}{n}\sum_{i=1}^n \ell(y_i, f(x_i))\]
Which loss? Different choices give different estimators:
The choice encodes assumptions about how noise enters the data
Maximum likelihood makes this explicit:

Assume data comes from a process: \[y = \mathbf{w}^T \mathbf{x} + \epsilon\]
where \(\epsilon\) is random noise (\(\mathbf{x}\) includes a constant 1, so the bias is in \(\mathbf{w}\))
What we observe:
Questions:
Common assumption: \(\epsilon \sim \mathcal{N}(0, \sigma^2)\)
Why Gaussian? Often reasonable in practice:

Model: \(y = \mathbf{w}^T \mathbf{x} + \epsilon\), where \(\epsilon \sim \mathcal{N}(0, \sigma^2)\)
This implies \(y|\mathbf{x}\) is Gaussian: \[y|\mathbf{x} \sim \mathcal{N}(\mathbf{w}^T \mathbf{x}, \sigma^2)\]
Density of \(y\) given \(\mathbf{x}\): \[p(y|\mathbf{x}; \mathbf{w}) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(y - \mathbf{w}^T \mathbf{x})^2}{2\sigma^2}\right)\]
For entire dataset \(\mathcal{D} = \{(\mathbf{x}_i, y_i)\}_{i=1}^n\):
Assuming independent samples: \[p(\mathcal{D}|\mathbf{w}) = \prod_{i=1}^n p(y_i|\mathbf{x}_i; \mathbf{w})\]
Maximum likelihood principle: Find \(\mathbf{w}\) that makes observed data most likely: \[\hat{\mathbf{w}}_{\text{ML}} = \arg\max_{\mathbf{w}} p(\mathcal{D}|\mathbf{w})\]
Equivalently, minimize \(-\frac{1}{n}\sum_i \log p(y_i|\mathbf{x}_i; \mathbf{w})\): ERM with loss \(\ell = -\log p\)

Log-likelihood: \[\log L(\mathbf{w}) = \log p(\mathcal{D}|\mathbf{w}) = \sum_{i=1}^n \log p(y_i|\mathbf{x}_i; \mathbf{w})\]
Substitute Gaussian pdf: \[\log L(\mathbf{w}) = \sum_{i=1}^n \log \left(\frac{1}{\sqrt{2\pi\sigma^2}} e^{-\frac{(y_i - \mathbf{w}^T \mathbf{x}_i)^2}{2\sigma^2}}\right)\]
Simplify: \[\log L(\mathbf{w}) = -\frac{n}{2}\log(2\pi\sigma^2) - \frac{1}{2\sigma^2}\sum_{i=1}^n(y_i - \mathbf{w}^T \mathbf{x}_i)^2\]
To maximize \(\log L(\mathbf{w})\):
Result: MLE = Least squares
\[\hat{\mathbf{w}}_{\text{ML}} = \arg\min_{\mathbf{w}} \sum_{i=1}^n(y_i - \mathbf{w}^T \mathbf{x}_i)^2\]
Gaussian noise assumption leads to squared loss

Real data has outliers:
Laplace noise model: \[p(\epsilon) = \frac{1}{2b}\exp\left(-\frac{|\epsilon|}{b}\right)\]
Heavier tails than Gaussian: large residuals are not unusual
Likelihood with Laplace noise: \[p(y|\mathbf{x}; \mathbf{w}) = \frac{1}{2b}\exp\left(-\frac{|y - \mathbf{w}^T \mathbf{x}|}{b}\right)\]
Log-likelihood: \[\log L(\mathbf{w}) = -n\log(2b) - \frac{1}{b}\sum_{i=1}^n |y_i - \mathbf{w}^T \mathbf{x}_i|\]
Maximizing \(\log L(\mathbf{w})\) equivalent to minimizing: \[\sum_{i=1}^n |y_i - \mathbf{w}^T \mathbf{x}_i|\]
L1 loss emerges directly from the Laplace noise assumption.
This is least absolute deviations (LAD): the fit tracks the conditional median, not the mean

Residuals \(e_i = y_i - \hat{y}_i\) estimate the noise: each plot tests one part of \(\epsilon_i \sim \mathcal{N}(0, \sigma^2)\), independent

When linear regression fails:
Notation: Weight vector \(\mathbf{w}\), bias \(b\) (replacing LMMSE parameters \(\mathbf{a}, b\))
Model structure: \[\hat{y} = \mathbf{w}^T \mathbf{x} + b\]
where:
Vectorized over dataset: \[\hat{\mathbf{y}} = \mathbf{X}\mathbf{w} + b\mathbf{1}\]
Augmented notation (absorb the bias): \[\tilde{\mathbf{x}} = \begin{bmatrix} 1 \\ \mathbf{x} \end{bmatrix}, \quad \tilde{\mathbf{w}} = \begin{bmatrix} b \\ \mathbf{w} \end{bmatrix}\]
Then: \(\hat{y} = \tilde{\mathbf{w}}^T \tilde{\mathbf{x}}\) and \(\hat{\mathbf{y}} = \tilde{\mathbf{X}}\tilde{\mathbf{w}}\), with \(\mathbf{X}\) including the column of ones.

Empirical risk (squared loss): \[J(\mathbf{w}) = \frac{1}{2n} \sum_{i=1}^n (y_i - \underbrace{\mathbf{w}^T \mathbf{x}_i}_{\hat{y}_i})^2\]
Matrix form: \[J(\mathbf{w}) = \frac{1}{2n} \|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2\]
Expanded: \[J(\mathbf{w}) = \frac{1}{2n}(\mathbf{y} - \mathbf{X}\mathbf{w})^T(\mathbf{y} - \mathbf{X}\mathbf{w})\] \[= \frac{1}{2n}(\mathbf{y}^T\mathbf{y} - 2\mathbf{y}^T\mathbf{X}\mathbf{w} + \mathbf{w}^T\mathbf{X}^T\mathbf{X}\mathbf{w})\]
This is a quadratic in \(\mathbf{w}\): \[J(\mathbf{w}) = \frac{1}{2n}(\mathbf{w}^T\mathbf{A}\mathbf{w} - 2\mathbf{c}^T\mathbf{w} + \mathbf{y}^T\mathbf{y})\]
where:
Convexity: \(\nabla^2 J = \frac{1}{n}\mathbf{X}^T\mathbf{X} \succeq 0\)

Minimize: \(J(\mathbf{w}) = \frac{1}{2n}\|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2\)
Take gradient: \[\nabla_{\mathbf{w}} J = \frac{1}{n}\mathbf{X}^T(\mathbf{X}\mathbf{w} - \mathbf{y})\]
Set to zero: \[\mathbf{X}^T(\mathbf{X}\mathbf{w} - \mathbf{y}) = \mathbf{0}\]
Normal equations: \[\boxed{\mathbf{X}^T\mathbf{X}\mathbf{w} = \mathbf{X}^T\mathbf{y}}\]
Observations:
Hence name: residual \(\mathbf{y} - \mathbf{X}\hat{\mathbf{w}}\) is orthogonal (normal) to every column of \(\mathbf{X}\) - the sample form of the orthogonality principle

Normal equations: \(\mathbf{X}^T\mathbf{X}\mathbf{w} = \mathbf{X}^T\mathbf{y}\)
Divide by \(n\): \[\frac{1}{n}\mathbf{X}^T\mathbf{X}\mathbf{w} = \frac{1}{n}\mathbf{X}^T\mathbf{y}\]
With the column of ones: \(\frac{1}{n}\mathbf{X}^T\mathbf{X}\) holds second moments, not covariances
Center first (\(\mathbf{X}_c\): each column minus its mean, \(\mathbf{y}_c = \mathbf{y} - \bar{y}\)): the ones column drops out and the equations become \[\hat{\mathbf{K}}_{XX} \mathbf{w} = \hat{\mathbf{k}}_{XY}\]
Solution: \[\mathbf{w} = \hat{\mathbf{K}}_{XX}^{-1} \hat{\mathbf{k}}_{XY}\]
This is empirical LMMSE.
Population: \(\mathbf{w}^* = \mathbf{K}_{XX}^{-1} \mathbf{k}_{XY}\) Sample: \(\hat{\mathbf{w}} = \hat{\mathbf{K}}_{XX}^{-1} \hat{\mathbf{k}}_{XY}\)
Consistency: \(\hat{\mathbf{w}} \to \mathbf{w}^*\) as \(n \to \infty\)

Solution (when \(\mathbf{X}^T\mathbf{X}\) invertible): \[\mathbf{w} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}\]
Moore-Penrose pseudoinverse (full column rank): \[\mathbf{X}^+ = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\]
So: \(\mathbf{w} = \mathbf{X}^+\mathbf{y}\)
Properties of \(\mathbf{X}^+\):
When is \(\mathbf{X}^T\mathbf{X}\) invertible?
Rank deficient case: infinitely many solutions; the SVD pseudoinverse picks the one with minimum \(\|\mathbf{w}\|\)

Method 1: Normal equations
Complexity:
Condition number: \(\kappa(\mathbf{A}) = \sigma_{\max}(\mathbf{A}) / \sigma_{\min}(\mathbf{A})\), the ratio of largest to smallest singular value
Squaring: \[\kappa(\mathbf{X}^T\mathbf{X}) = \kappa(\mathbf{X})^2\]

QR factorization: \(\mathbf{X} = \mathbf{Q}\mathbf{R}\)
Substitute into the normal equations: \[\mathbf{R}^T\mathbf{Q}^T\mathbf{Q}\mathbf{R}\mathbf{w} = \mathbf{R}^T\mathbf{Q}^T\mathbf{y} \;\Rightarrow\; \mathbf{R}\mathbf{w} = \mathbf{Q}^T\mathbf{y}\]
Back-substitution: \(\mathbf{R}\) is triangular, so \(\mathbf{w}\) comes one entry at a time from the bottom row up
Accuracy: error grows with \(\kappa(\mathbf{X})\), not \(\kappa(\mathbf{X})^2\)
Cost: about \(2np^2\) flops, 2× the normal equations
Back-substitution for \(p = 3\): \[\begin{bmatrix} r_{11} & r_{12} & r_{13} \\ 0 & r_{22} & r_{23} \\ 0 & 0 & r_{33} \end{bmatrix} \begin{bmatrix} w_1 \\ w_2 \\ w_3 \end{bmatrix} = \begin{bmatrix} c_1 \\ c_2 \\ c_3 \end{bmatrix}, \quad \mathbf{c} = \mathbf{Q}^T\mathbf{y}\]
\[w_3 = c_3 / r_{33}\] \[w_2 = (c_2 - r_{23} w_3) / r_{22}\] \[w_1 = (c_1 - r_{12} w_2 - r_{13} w_3) / r_{11}\]
Singular Value Decomposition: \[\mathbf{X} = \mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^T\]
where:
Solution via SVD: \[\mathbf{w} = \mathbf{V}\boldsymbol{\Sigma}^+ \mathbf{U}^T \mathbf{y}\]
where \(\boldsymbol{\Sigma}^+\) = pseudoinverse of \(\boldsymbol{\Sigma}\):
Rank deficient: smallest \(\|\mathbf{w}\|\) among all minimizers
Component form: one term per singular direction \[\hat{\mathbf{w}} = \sum_i f_i \, \frac{\mathbf{u}_i^T \mathbf{y}}{\sigma_i} \, \mathbf{v}_i, \qquad f_i \in \{0, 1\}\]
Cost:
np.linalg.lstsq uses the SVDTruncated SVD (regularization): \(f_i = 1\) for the \(k\) largest \(\sigma_i\), else \(0\)

First-order Taylor expansion: \[J(\mathbf{w} + \Delta) \approx J(\mathbf{w}) + \nabla J(\mathbf{w})^T\Delta\]
Gradient points uphill: \[\nabla J(\mathbf{w}) = \frac{1}{n}\mathbf{X}^T(\mathbf{X}\mathbf{w} - \mathbf{y})\]
Direction of maximum increase of \(J\)
Update rule: \[\mathbf{w}_{t+1} = \mathbf{w}_t - \eta \nabla J(\mathbf{w}_t)\]
where \(\eta\) = step size / learning rate
Convergence criterion: \[\|\nabla J(\mathbf{w})\| < \text{tol}\]
At optimum: \(\nabla J(\mathbf{w}^*) = \mathbf{0}\) (critical point)
NumPy (\(\mathbf{X}\) includes the ones column):

Definition: \(f\) is convex if for all \(\lambda \in [0,1]\): \[f(\lambda \mathbf{w}_1 + (1-\lambda)\mathbf{w}_2) \leq \lambda f(\mathbf{w}_1) + (1-\lambda)f(\mathbf{w}_2)\]
Squared loss is convex: \[J(\mathbf{w}) = \frac{1}{2n}\|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2\]
Proof via Hessian: \[\nabla^2 J = \frac{1}{n}\mathbf{X}^T\mathbf{X}\]
Since \(\mathbf{X}^T\mathbf{X} \succeq 0\) (positive semidefinite): \[\mathbf{v}^T(\mathbf{X}^T\mathbf{X})\mathbf{v} = \|\mathbf{X}\mathbf{v}\|^2 \geq 0 \quad \forall \mathbf{v}\]
Therefore \(J\) is convex.
Strong convexity if \(\mathbf{X}\) full column rank: \[J(\mathbf{w}) \geq J(\mathbf{w}^*) + \frac{\mu}{2}\|\mathbf{w} - \mathbf{w}^*\|^2\] where \(\mu = \lambda_{\min}(\mathbf{X}^T\mathbf{X})/n > 0\)

Error recursion (quadratic \(J\), Hessian \(\mathbf{H} = \frac{1}{n}\mathbf{X}^T\mathbf{X}\)): \[\mathbf{w}_{t+1} - \mathbf{w}^* = (\mathbf{I} - \eta\mathbf{H})(\mathbf{w}_t - \mathbf{w}^*)\]
Too small: Slow convergence \[\mathbf{w}_{t+1} \approx \mathbf{w}_t\]
Too large: Overshoot, divergence \[J(\mathbf{w}_{t+1}) > J(\mathbf{w}_t)\]
Theoretical bounds: need \(|1 - \eta\lambda_i| < 1\) for every \(i\): \[0 < \eta < \frac{2}{\lambda_{\max}(\mathbf{H})}\]
Optimal step size: \[\eta^* = \frac{2}{\lambda_{\min} + \lambda_{\max}}\]
Convergence rate (\(\kappa = \lambda_{\max}/\lambda_{\min}\)): \[\|\mathbf{w}_t - \mathbf{w}^*\| \leq \left(\frac{\kappa - 1}{\kappa + 1}\right)^t \|\mathbf{w}_0 - \mathbf{w}^*\|\]

Loss surface shape: set by eigenvalues of \(\mathbf{H} = \frac{1}{n}\mathbf{X}^T\mathbf{X}\)
Principal axes: Eigenvectors of \(\mathbf{H}\)
Curvature along axis: Eigenvalue
Gradient descent behavior:
\(\kappa(\mathbf{H}) = \kappa(\mathbf{X})^2\): gradient descent pays for conditioning in steps, the normal equations in digits
Preconditioning: make all eigenvalues equal \[\tilde{\mathbf{X}} = \mathbf{X}\mathbf{P}^{-1}, \quad \tilde{\mathbf{X}}^T\tilde{\mathbf{X}} = \mathbf{I}\]

Iterations per 10× error reduction (at \(\eta^*\)):
Scale mismatch inflates \(\kappa(\mathbf{H})\) (figure):
Rescaling:
Standardization (z-score): \(x' = (x - \mu)/\sigma\)
Min-Max scaling: \(x' = (x - x_{min})/(x_{max} - x_{min})\)

Robust scaling: \(x' = (x - \text{median})/\text{IQR}\)
Use one sample at a time: \[\mathbf{w}_{t+1} = \mathbf{w}_t - \eta_t \nabla \ell_{i_t}(\mathbf{w}_t)\]
where \(i_t\) randomly selected
For squared loss (\(\ell_i = \frac{1}{2}(y_i - \mathbf{w}^T\mathbf{x}_i)^2\)): \[\nabla \ell_i(\mathbf{w}) = -(y_i - \mathbf{w}^T \mathbf{x}_i)\mathbf{x}_i\]
LMS algorithm (Widrow-Hoff) is SGD for squared loss: \(\mathbf{w}_{t+1} = \mathbf{w}_t + \eta e_t \mathbf{x}_t\)
Unbiased gradient estimate: \[\mathbb{E}[\nabla \ell_i(\mathbf{w})] = \nabla J(\mathbf{w})\]
Noise in gradient: \[\text{Var}[\nabla \ell_i] = \mathbb{E}[\|\nabla \ell_i\|^2] - \|\nabla J\|^2\]
Cost and use:

Fixed step size: Converges to neighborhood \[\mathbb{E}[\|\mathbf{w}_t - \mathbf{w}^*\|^2] \leq (1 - \eta\mu)^t\|\mathbf{w}_0 - \mathbf{w}^*\|^2 + O\!\left(\frac{\eta\sigma_g^2}{\mu}\right)\]
where \(\sigma_g^2\) = gradient noise variance, \(\mu = \lambda_{\min}(\mathbf{H})\)
Decreasing step size: Converges to exact solution
Required conditions (Robbins-Monro): \[\sum_{t=1}^{\infty} \eta_t = \infty, \quad \sum_{t=1}^{\infty} \eta_t^2 < \infty\]
Example: \(\eta_t = \eta_0/t\)
Lowering the floor:

Convergence rates:
| Method | Rate | Final Error |
|---|---|---|
| Batch GD | \(\left(\frac{\kappa-1}{\kappa+1}\right)^t\) | 0 |
| SGD (fixed \(\eta\)) | \((1 - \eta\mu)^t\) | \(O(\eta)\) |
| SGD (decreasing) | \(O(1/t)\) | 0 |
Mini-batch gradient: \[\nabla J_{\mathcal{B}} = \frac{1}{m} \sum_{i \in \mathcal{B}} \nabla \ell_i(\mathbf{w})\]
where \(|\mathcal{B}| = m\) = batch size
Variance reduction: \[\text{Var}[\nabla J_{\mathcal{B}}] = \frac{1}{m}\text{Var}[\nabla \ell_i]\]
Consequences:
Epoch: One pass through dataset
Equal compute:

Model: \(\mathbf{y} = \mathbf{X}\mathbf{w}^* + \epsilon\), \(\;\epsilon \sim \mathcal{N}(\mathbf{0}, \sigma^2\mathbf{I})\)
Substitute into the least-squares solution: \[\hat{\mathbf{w}} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y} = \mathbf{w}^* + (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\epsilon\]
Spread of \(\hat{\mathbf{w}}\): set by \(\sigma^2\), \(n\), and \(\mathbf{X}\)
Statistical inference:

From \(\hat{\mathbf{w}} - \mathbf{w}^* = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\epsilon\): \[\text{Cov}(\hat{\mathbf{w}}) = \sigma^2(\mathbf{X}^T \mathbf{X})^{-1}\]
Fisher information (curvature of the log-likelihood): \[\mathcal{I} = -\mathbb{E}\left[\nabla^2 \log L(\mathbf{w})\right] = \frac{1}{\sigma^2}\mathbf{X}^T \mathbf{X}\]
Confidence region: the ellipsoid \((\hat{\mathbf{w}} - \mathbf{w}^*)^T \mathcal{I} (\hat{\mathbf{w}} - \mathbf{w}^*) \leq c\)
Cramér-Rao bound: any unbiased estimator \(\tilde{\mathbf{w}}\) has \(\text{Cov}(\tilde{\mathbf{w}}) \succeq \mathcal{I}^{-1}\)

\(\sigma^2(\mathbf{X}^T\mathbf{X})^{-1}\) grows without bound when:
Way out: add a penalty \(R(\mathbf{w})\) on complexity, \(J(\mathbf{w}) + \lambda R(\mathbf{w})\)

Setup: \(y = f(x) + \epsilon\), \(\;\mathbb{E}[\epsilon] = 0\), \(\;\text{Var}(\epsilon) = \sigma^2\)
Expand at point \(x_0\), with \(\hat{f}\) random (trained on random data): \[\mathbb{E}[(y - \hat{f}(x_0))^2] = \mathbb{E}[(f(x_0) + \epsilon - \hat{f}(x_0))^2]\]
Independence of \(\epsilon\) and \(\hat{f}\): \[= \mathbb{E}[(f(x_0) - \hat{f}(x_0))^2] + \sigma^2\]
Add and subtract \(\mathbb{E}[\hat{f}(x_0)]\): \[= \text{Var}(\hat{f}(x_0)) + (f(x_0) - \mathbb{E}[\hat{f}(x_0)])^2 + \sigma^2\]
\[\boxed{\text{MSE} = \text{Variance} + \text{Bias}^2 + \sigma^2}\]
For linear models, averaged over the training inputs (what the figure measures):
Measured (polynomial degree, \(n = 20\), \(\sigma = 0.1\), the figure’s setup):
| Degree | Bias\(^2\) | Variance | Test MSE |
|---|---|---|---|
| 1 | 0.023 | 0.001 | 0.034 |
| 2 | < 0.001 | 0.001 | 0.011 |
| 5 | < 0.001 | 0.003 | 0.013 |
| 14 | < 0.001 | 0.028 | 0.038 |
Overfitting:

Ridge regression (L2 penalty on every weight but the intercept \(w_0\)): \[J_\lambda(\mathbf{w}) = \frac{1}{2n}\|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2 + \frac{\lambda}{2} \sum_{j \geq 1} w_j^2\]
Solution (\(\nabla J_\lambda = \mathbf{0}\)), with \(\mathbf{D} = \text{diag}(0, 1, \ldots, 1)\): \[\hat{\mathbf{w}}_{\text{ridge}} = (\mathbf{X}^T \mathbf{X} + n\lambda \mathbf{D})^{-1} \mathbf{X}^T \mathbf{y}\]
Effect:

Posterior: \(p(\mathbf{w}|\mathcal{D}) \propto p(\mathcal{D}|\mathbf{w}) \cdot p(\mathbf{w})\)
MAP estimation: \[\hat{\mathbf{w}}_{\text{MAP}} = \arg\max_{\mathbf{w}} [\log p(\mathcal{D}|\mathbf{w}) + \log p(\mathbf{w})]\]
Gaussian prior \(\mathbf{w} \sim \mathcal{N}(\mathbf{0}, \tau^2 \mathbf{I})\): \(\;\log p(\mathbf{w}) = -\frac{1}{2\tau^2}\|\mathbf{w}\|^2 + \text{const}\) \[\hat{\mathbf{w}}_{\text{MAP}} = \arg\min_{\mathbf{w}} \left[\frac{1}{2\sigma^2}\|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2 + \frac{1}{2\tau^2}\|\mathbf{w}\|^2\right]\]
Other priors:


Effect of \(\lambda\):
In the figure:

Information content of a single outcome \(x\): \[I(x) = -\log p(x)\]
Units: bits (base 2), nats (base \(e\))
Properties:
Logarithm: information from independent events adds \[I(A \cap B) = -\log p(A)p(B) = I(A) + I(B)\]
Fair coin: \(I(\text{heads}) = -\log_2 0.5 = 1\) bit

Entropy: expected information content over all outcomes \[H(X) = \mathbb{E}[I(X)] = -\sum_x p(x) \log p(x)\]
Interpretation:
Properties:
Examples: fair coin 1 bit, coin with \(p = 0.9\) 0.47 bits, fair die \(\log_2 6 = 2.58\) bits

Continuous case: the sum becomes an integral \[H(X) = -\int p(x) \log p(x) \, dx\]
Not bounded below:
Still meaningful:
Gaussian: \(H = \tfrac{1}{2}\log(2\pi e \sigma^2)\), negative for \(\sigma < 0.24\)

Maximum entropy principle: among all distributions meeting the known constraints, take the one with the largest entropy
Known mean and variance: \[\max_{p} H(p) \quad \text{s.t.} \quad \mathbb{E}[X] = \mu, \; \text{Var}(X) = \sigma^2\]
Solution: \(\mathcal{N}(\mu, \sigma^2)\)

Known mean absolute deviation: \[\max_{p} H(p) \quad \text{s.t.} \quad \mathbb{E}|X| = b\]
Solution: Laplace with scale \(b\)
The two noise models of MLE:

Constrained maximization over densities \(p\), one multiplier per constraint: \[\mathcal{L}[p] = -\int p \log p \, dx + \lambda_0\!\left(\int p \, dx - 1\right) + \lambda_1\!\left(\int x\, p \, dx - \mu\right) + \lambda_2\!\left(\int x^2 p \, dx - (\sigma^2 + \mu^2)\right)\]
Stationarity in \(p\) at every \(x\): \[-\log p(x) - 1 + \lambda_0 + \lambda_1 x + \lambda_2 x^2 = 0\]
Solve for \(p\): \[p(x) \propto \exp(\lambda_1 x + \lambda_2 x^2)\]
Data drawn from \(p\); a model \(q\) for them
Cross-entropy: the expected value over the data \[H(p, q) = \mathbb{E}_{X \sim p}[-\log q(X)]\]
Model equal to \(p\): \(H(p, p) = H(p)\), the entropy
Example, \(p = \mathcal{N}(0, 1)\), \(q = \mathcal{N}(1, 1.5^2)\):

The difference is the KL divergence: \[\underbrace{\mathbb{E}_p[-\log q(X)]}_{H(p,q)} - \underbrace{\mathbb{E}_p[-\log p(X)]}_{H(p)} = D_{KL}(p\|q)\]
Decomposition: \[H(p, q) = H(p) + D_{KL}(p\|q)\]
Not symmetric: \(H(p, q) \neq H(q, p)\)

Kullback-Leibler divergence: \[D_{KL}(p\|q) = \mathbb{E}_p\left[\log \frac{p(X)}{q(X)}\right] = \int p(x) \log \frac{p(x)}{q(x)} \, dx\]
Interpretation:
Properties:

Fit \(q\) to a fixed \(p\), two ways to score it:
Forward \(D_{KL}(p\|q) = \mathbb{E}_p[\log p/q]\):
Reverse \(D_{KL}(q\|p) = \mathbb{E}_q[\log q/p]\):
Maximum likelihood uses the forward direction: it needs only data and the model’s density

Mutual information: KL from the joint to the product of marginals \[I(X; Y) = D_{KL}\big(p(x,y) \,\|\, p(x)p(y)\big)\] \[= \mathbb{E}_{X,Y}\left[\log \frac{p(X,Y)}{p(X)p(Y)}\right]\]
Conditional entropy: \(H(X|Y) = -\mathbb{E}[\log p(X|Y)]\), the uncertainty left in \(X\) once \(Y\) is known
Equivalent forms: \[I(X; Y) = H(X) - H(X|Y) = H(Y) - H(Y|X)\]
Properties:

Bivariate Gaussian with correlation \(\rho\): \[I(X; Y) = -\tfrac{1}{2}\log(1 - \rho^2)\]
The same \(1 - \rho^2\) as the LMMSE error \(\text{Var}(Y)(1 - \rho^2)\): what the line cannot predict is what \(X\) does not tell
Data processing inequality: for a Markov chain \(X \to Y \to Z\) (\(Z\) depends on \(X\) only through \(Y\)) \[I(X; Z) \leq I(X; Y)\]

Setup: data from \(p\), model family \(\{q_\theta\}\)
Minimize the forward KL: \[D_{KL}(p \,\|\, q_\theta) = H(p, q_\theta) - H(p)\]
Expectation to sample average (the ERM step): \[\mathbb{E}_p[\log q_\theta(X)] \approx \frac{1}{n}\sum_{i=1}^n \log q_\theta(x_i) = \frac{1}{n}\log L(\theta)\]
Result: maximum likelihood = ERM with \(\ell = -\log q_\theta\) = minimum cross-entropy = minimum forward KL

If \(p \notin \{q_\theta\}\), no \(\theta\) makes the KL zero
The minimizer: the member of the family closest to \(p\) in forward KL
What the fit gets right: the mean and variance of \(p\), exactly
What it cannot: the two modes; the KL that remains is the price of the family

Labeled data: loss = negative log-likelihood of the label \[\ell(y, \hat{y}) = -\log p(y \,|\, \mathbf{x}; \mathbf{w})\]
Continuous targets: Gaussian noise gives squared loss, Laplace noise gives absolute loss
Discrete targets \(y \in \{1, ..., K\}\), model outputs probabilities \(\pi_k(\mathbf{x}) = P(Y = k \,|\, \mathbf{x})\):
Categorical likelihood: \[p(y \,|\, \mathbf{x}) = \prod_{k=1}^K \pi_k(\mathbf{x})^{\mathbf{1}_{y=k}}\]
Negative log-likelihood: \[-\log p(y \,|\, \mathbf{x}) = -\sum_{k} \mathbf{1}_{y=k} \log \pi_k\]
One-hot encoding \(y_k = \mathbf{1}_{y=k}\): \[\ell = -\sum_{k} y_k \log \pi_k = H(\mathbf{y}, \boldsymbol{\pi})\]
Categorical cross-entropy: the cross-entropy between the one-hot label and the predicted probabilities
Bernoulli (\(K = 2\)): \(P(Y = 1 \,|\, \mathbf{x}) = \pi\) \[p(y \,|\, \mathbf{x}) = \pi^y (1 - \pi)^{1-y}\]
Negative log-likelihood: \[\ell = -y\log \pi - (1-y)\log(1-\pi)\]
Per label:
Unbounded: \(\pi \to 0\) with \(y = 1\) costs without limit, a confident wrong answer is never cheap
Requires \(\pi \in (0, 1)\)

Binary labels \(y \in \{0, 1\}\) as regression: \(\hat{y} = \mathbf{w}^T\mathbf{x}\), predict 1 if \(\hat{y} > 0.5\)
Wrong class:
Wrong likelihood:
Needed: a map from \(\hat{y} \in \mathbb{R}\) to \(\pi \in (0, 1)\), and the Bernoulli loss on \(\pi\)

Keep the linear model, add one map: \[z = \mathbf{w}^T\mathbf{x} \in \mathbb{R} \qquad \pi = \sigma(z) = \frac{1}{1 + e^{-z}} \in (0, 1)\]
Sigmoid:
Model: \(P(Y = 1 \,|\, \mathbf{x}) = \sigma(\mathbf{w}^T\mathbf{x})\)
Loss: the Bernoulli negative log-likelihood \[\ell = -y \log \sigma(z) - (1 - y)\log(1 - \sigma(z))\]
Gradient per sample: \((\sigma(z) - y)\,\mathbf{x}\), the least-squares form \((\hat{y} - y)\,\mathbf{x}\) with \(\hat{y}\) squashed
