EE 541 - Unit 4
Dr. Brandon Franzke
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:
Population moments – require \(p(x)\):
Sample moments – require only data:
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):
Cannot compute without knowing \(p(x,y)\)
Empirical risk (what we can compute):
Empirical Risk Minimization (ERM):
Convergence guarantee (fixed \(\mathcal{F}\), not too rich):
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}\)):
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
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:
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:
Density of \(y\) given \(\mathbf{x}\):
For entire dataset \(\mathcal{D} = \{(\mathbf{x}_i, y_i)\}_{i=1}^n\):
Assuming independent samples:
Maximum likelihood principle: Find \(\mathbf{w}\) that makes observed data most likely:
Equivalently, minimize \(-\frac{1}{n}\sum_i \log p(y_i|\mathbf{x}_i; \mathbf{w})\): ERM with loss \(\ell = -\log p\)
Log-likelihood:
Substitute Gaussian pdf:
Simplify:
To maximize \(\log L(\mathbf{w})\):
Result: MLE = Least squares
Gaussian noise assumption leads to squared loss
Real data has outliers:
Laplace noise model:
Heavier tails than Gaussian: large residuals are not unusual
Likelihood with Laplace noise:
Log-likelihood:
Maximizing \(\log L(\mathbf{w})\) equivalent to minimizing:
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:
where:
Vectorized over dataset:
Augmented notation (absorb the bias):
Then: \(\hat{y} = \tilde{\mathbf{w}}^T \tilde{\mathbf{x}}\) and \(\hat{\mathbf{y}} = \tilde{\mathbf{X}}\tilde{\mathbf{w}}\). From here on \(\mathbf{X}\) includes the column of ones.
Empirical risk (squared loss):
Matrix form:
Expanded:
This is a quadratic in \(\mathbf{w}\):
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:
Set to zero:
Normal equations:
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\):
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
Solution:
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):
Moore-Penrose pseudoinverse (full column rank):
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
w = np.linalg.solve(X.T @ X, X.T @ y)
Complexity:
Condition number: \(\kappa(\mathbf{A}) = \sigma_{\max}(\mathbf{A}) / \sigma_{\min}(\mathbf{A})\), the ratio of largest to smallest singular value
Squaring:
QR factorization: \(\mathbf{X} = \mathbf{Q}\mathbf{R}\)
Substitute into the normal equations:
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\):
Q, R = np.linalg.qr(X) w = scipy.linalg.solve_triangular(R, Q.T @ y)
Singular Value Decomposition:
where:
Solution via SVD:
where \(\boldsymbol{\Sigma}^+\) = pseudoinverse of \(\boldsymbol{\Sigma}\):
Rank deficient: smallest \(\|\mathbf{w}\|\) among all minimizers
Component form: one term per singular direction
Cost:
np.linalg.lstsq uses the SVDTruncated SVD (regularization): \(f_i = 1\) for the \(k\) largest \(\sigma_i\), else \(0\)
First-order Taylor expansion:
Gradient points uphill:
Direction of maximum increase of \(J\)
Update rule:
where \(\eta\) = step size / learning rate
Convergence criterion:
At optimum: \(\nabla J(\mathbf{w}^*) = \mathbf{0}\) (critical point)
NumPy (\(\mathbf{X}\) includes the ones column):
def gradient_descent(X, y, eta=0.01, steps=1000): n, p = X.shape w = np.zeros(p) for _ in range(steps): grad = X.T @ (X @ w - y) / n w = w - eta * grad return w
Definition: \(f\) is convex if for all \(\lambda \in [0,1]\):
Squared loss is convex:
Proof via Hessian:
Since \(\mathbf{X}^T\mathbf{X} \succeq 0\) (positive semidefinite):
Therefore \(J\) is convex.
Strong convexity if \(\mathbf{X}\) full column rank:
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}\)):
Too small: Slow convergence
Too large: Overshoot, divergence
Theoretical bounds: need \(|1 - \eta\lambda_i| < 1\) for every \(i\):
Optimal step size:
Convergence rate (\(\kappa = \lambda_{\max}/\lambda_{\min}\)):
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
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:
where \(i_t\) randomly selected
For squared loss (\(\ell_i = \frac{1}{2}(y_i - \mathbf{w}^T\mathbf{x}_i)^2\)):
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:
Noise in gradient:
Cost and use:
Fixed step size: Converges to neighborhood
where \(\sigma_g^2\) = gradient noise variance, \(\mu = \lambda_{\min}(\mathbf{H})\)
Decreasing step size: Converges to exact solution
Required conditions (Robbins-Monro):
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:
where \(|\mathcal{B}| = m\) = batch size
Variance reduction:
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:
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\):
Fisher information (curvature of the log-likelihood):
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):
Independence of \(\epsilon\) and \(\hat{f}\):
Add and subtract \(\mathbb{E}[\hat{f}(x_0)]\):
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\)):
Solution (\(\nabla J_\lambda = \mathbf{0}\)), with \(\mathbf{D} = \text{diag}(0, 1, \ldots, 1)\):
Effect:
Posterior: \(p(\mathbf{w}|\mathcal{D}) \propto p(\mathcal{D}|\mathbf{w}) \cdot p(\mathbf{w})\)
MAP estimation:
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}\)
Other priors:
Effect of \(\lambda\):
In the figure:
Information content of a single outcome \(x\):
Units: bits (base 2), nats (base \(e\), used from here on)
Properties:
Logarithm: information from independent events adds
Fair coin: \(I(\text{heads}) = -\log_2 0.5 = 1\) bit
Entropy: expected information content over all outcomes
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
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:
Solution: \(\mathcal{N}(\mu, \sigma^2)\)
Known mean absolute deviation:
Solution: Laplace with scale \(b\)
The two noise models of MLE:
Constrained maximization over densities \(p\), one multiplier per constraint:
Stationarity in \(p\) at every \(x\):
Solve for \(p\):
Coding: samples come from \(p\), the code was built for \(q\)
Cross-entropy: the expected cost of coding \(p\) with \(q\)
Cost with the right code: \(H(p, p) = H(p)\)
Extra cost: \(H(p, q) - H(p) \geq 0\), zero iff \(q = p\)
The extra cost has a name:
Decomposition:
Properties of cross-entropy:
Kullback-Leibler divergence:
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
Mutual information: KL from the joint to the product of marginals
Conditional entropy: \(H(X|Y) = -\mathbb{E}[\log p(X|Y)]\), the uncertainty left in \(X\) once \(Y\) is known
Equivalent forms:
Properties:
Bivariate Gaussian with correlation \(\rho\):
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\))
Setup: data from \(p\), model family \(\{q_\theta\}\)
Minimize the forward KL:
Expectation to sample average (the ERM step):
Result: maximum likelihood = ERM with \(\ell = -\log q_\theta\) = 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
Principle: loss = negative log-likelihood
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:
Negative log-likelihood:
One-hot encoding \(y_k = \mathbf{1}_{y=k}\):
Categorical cross-entropy: the cross-entropy between the one-hot label and the predicted probabilities
Bernoulli (\(K = 2\)): \(P(Y = 1 \,|\, \mathbf{x}) = \pi\)
Negative log-likelihood:
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:
Sigmoid:
Model: \(P(Y = 1 \,|\, \mathbf{x}) = \sigma(\mathbf{w}^T\mathbf{x})\)
Loss: the Bernoulli negative log-likelihood
Gradient per sample: \((\sigma(z) - y)\,\mathbf{x}\), the least-squares form \((\hat{y} - y)\,\mathbf{x}\) with \(\hat{y}\) squashed