Learning theory: PAC, VC and double descent¶
Learning theory asks when low error on the training set guarantees low error on new data. The classical answer (the hypothesis class must be small relative to the data) is rigorous and illuminating, and modern deep learning violates its premise: networks fit random labels, interpolate noise, and still generalise, with test error that can fall, rise and fall again as models grow.
10,000 ft
Every trained model is a bet that patterns in a finite sample hold in the world. Learning theory prices that bet. Its classical core (PAC learning, VC dimension, Rademacher complexity, margin bounds) explains why we need inductive bias, why more data helps, why regularisation and large margins generalise, and why there is no universally best algorithm. From 2016 onwards, deep learning forced a rethink: over-parameterised networks interpolate their training data yet generalise, and test error shows double descent. The modern picture adds the optimiser's implicit bias, benign overfitting, flatness and PAC-Bayes. Theory still does not predict the empirical scaling laws that guide frontier training, which is itself one of the field's open problems.
2,000 ft
Training error is an average over a sample, so for any single fixed model it concentrates around the true error at rate \(1/\sqrt{m}\) (Hoeffding). The danger is choosing the model after seeing the data: with many candidates, one may fit the sample by luck. Theory bounds the worst case over the class:
- Finite classes: the gap grows like \(\sqrt{\ln|\mathcal{H}|/m}\) (Hoeffding plus a union bound).
- Infinite classes: what matters is how many distinct labellings the class can produce on \(m\) points, summarised by the VC dimension \(d\): gap \(\sim\sqrt{d\ln m/m}\). Finite VC dimension is exactly what makes a class learnable.
- Data-dependent measures (Rademacher complexity, margins, norms, PAC-Bayes) replace parameter counts with how large or how flat the learned function is.
- Modern regime: when models can fit anything, the optimiser chooses which interpolating solution; gradient descent prefers small-norm, flat ones, and test error can fall again past the interpolation threshold.
Ground level¶
The setup¶
Data \((\mathbf{x}, y)\) come from an unknown distribution \(\mathcal{D}\). We see a sample \(S\) of \(m\) i.i.d. draws and pick a hypothesis \(h\) from a class \(\mathcal{H}\) (all linear classifiers, all depth-5 trees, all networks of a given architecture). With a loss \(\ell \in [0, 1]\) (0–1 loss for classification):
Empirical risk minimisation (ERM) picks \(\hat h = \arg\min_{h\in\mathcal{H}}\hat R_S(h)\). The question is the generalisation gap \(R(\hat h) - \hat R_S(\hat h)\). Test error decomposes into pieces that theory treats separately:
Classical theory is about the tension between the middle two: a richer class approximates better and estimates worse. That is the bias–variance trade-off in its distribution-free form.
No free lunch: why bias is necessary¶
Wolpert (1996) showed that, averaged uniformly over all possible target functions, every learning algorithm has the same expected off-training-set error. A learner that does well on some problems must do badly on others. The Shalev-Shwartz and Ben-David version: for any learner and any training size below half the domain, there is a distribution on which it fails although a perfect classifier exists. Learning is possible only by restricting or ranking hypotheses in advance: an inductive bias. Everything below quantifies how much bias is enough.
PAC learning¶
Valiant (1984) defined learnability precisely. A class \(\mathcal{H}\) is probably approximately correct (PAC) learnable if there is an algorithm and a sample size \(m(\varepsilon, \delta)\) such that for every distribution, with probability at least \(1 - \delta\) over the sample, the output has error at most \(\varepsilon\). "Approximately" is \(\varepsilon\); "probably" is \(\delta\): we can never be certain, because the sample might be unrepresentative.
Finite class, realisable case (some \(h \in \mathcal{H}\) has zero error). A hypothesis with true error above \(\varepsilon\) survives one random example with probability at most \(1 - \varepsilon\), and \(m\) independent examples with probability at most \((1 - \varepsilon)^m \le e^{-\varepsilon m}\). A union bound over at most \(|\mathcal{H}|\) bad hypotheses gives failure probability \(\le |\mathcal{H}|e^{-\varepsilon m}\), so
examples suffice for ERM. Worked example: a million hypotheses, \(\varepsilon = 0.01\), \(\delta = 0.05\): \(m \ge (13.82 + 3.00)/0.01 = 1{,}682\). Note the logarithm: squaring the class size adds only 1,382 examples. Bits of description, not counts, are what cost data.
Finite class, agnostic case (no perfect hypothesis). Hoeffding's inequality for one fixed \(h\), \(P(|\hat R_S(h) - R(h)| > \varepsilon) \le 2e^{-2m\varepsilon^2}\), plus the union bound gives, with probability \(\ge 1 - \delta\), simultaneously for all \(h \in \mathcal{H}\):
With \(|\mathcal{H}| = 10^6\), \(m = 10{,}000\), \(\delta = 0.05\): \(\sqrt{(13.82 + 3.69)/20{,}000} = 0.030\). The rate is now \(1/\sqrt{m}\), not \(1/m\): without realisability, you need about \(1/\varepsilon^2\) examples.
A practical corollary. Any finite set of models you compare on a test set is a finite class. Evaluating 1,000 prompt variants on a 500-question benchmark and reporting the best inflates the score by up to roughly \(\sqrt{\ln 1000/1000} \approx 0.08\). This is why evaluation hygiene insists on a held-out set that is used once.
VC dimension: counting behaviours, not parameters¶
Linear classifiers in the plane form an infinite class, yet clearly learnable. What matters is how many different labellings the class can induce on the sample. The growth function \(\Pi_{\mathcal{H}}(m)\) is the maximum number of distinct labellings of \(m\) points. If \(\Pi_{\mathcal{H}}(m) = 2^m\), the class shatters some set of \(m\) points: it can fit any labelling, including noise. The VC dimension \(d_{VC}\) is the largest \(m\) that can be shattered.
| Class | VC dimension |
|---|---|
| Thresholds on a line, \(x \ge t\) | 1 |
| Intervals on a line | 2 |
| Half-spaces (linear classifiers) in \(\mathbb{R}^p\) | \(p + 1\) |
| Axis-aligned rectangles in \(\mathbb{R}^2\) | 4 |
| \(\operatorname{sign}(\sin(\omega x))\), one parameter | \(\infty\) |
The last row is the warning: parameter counting is not capacity. One frequency parameter can shatter arbitrarily many suitably placed points.
The Sauer–Shelah lemma turns finite VC dimension into polynomial growth: if \(d_{VC} = d\), then \(\Pi_{\mathcal{H}}(m) \le \sum_{i=0}^{d}\binom{m}{i} \le (em/d)^d\) for \(m \ge d\). Exponential growth stops at \(m = d\). Plugging this "effective size" into a union-bound argument (made rigorous with a ghost-sample symmetrisation) gives, with probability \(\ge 1 - \delta\), for all \(h\):
The fundamental theorem of statistical learning (for binary classification with 0–1 loss) closes the circle: \(\mathcal{H}\) is PAC learnable if and only if \(d_{VC}(\mathcal{H})\) is finite, if and only if ERM works, if and only if empirical risks converge uniformly to true risks. The sample complexity is \(\Theta\big((d + \ln(1/\delta))/\varepsilon^2\big)\) in the agnostic case: VC dimension is the measure of difficulty for worst-case binary classification.
Rademacher complexity: how well can the class fit noise?¶
VC bounds are distribution-free, hence pessimistic. Rademacher complexity measures capacity on the actual data: draw random signs \(\sigma_i \in \{-1, +1\}\) and ask how well the class can correlate with them,
A class that can fit any random sign pattern has complexity near 1; a class that cannot fit noise has complexity near 0. For losses in \([0,1]\), with probability \(\ge 1 - \delta\), for all \(h\): \(R(h) \le \hat R_S(h) + 2\mathfrak{R}_m(\ell\circ\mathcal{H}) + \sqrt{\ln(1/\delta)/2m}\). The payoff is dimension-free bounds: for linear functions with \(\lVert\mathbf{w}\rVert \le B\) on inputs with \(\lVert\mathbf{x}\rVert \le R\), \(\hat{\mathfrak{R}}_S \le BR/\sqrt{m}\) (derived below), whatever the dimension. Combined with a margin loss, this gives the margin bound: a classifier that separates the data with margin \(\gamma\) (in units of \(\lVert\mathbf{w}\rVert\)) has a gap of order \(R/(\gamma\sqrt{m})\). That is the theoretical case for SVMs working in infinite-dimensional feature spaces, and part of why boosting keeps improving as margins grow (see trees and ensembles).
PAC-Bayes: bounds for distributions over weights¶
Rather than a single hypothesis, consider a distribution \(Q\) over hypotheses (for a network: weights plus Gaussian noise). Fix a prior \(P\) before seeing the data. McAllester's PAC-Bayes theorem (1998–1999), in a commonly used form: with probability \(\ge 1 - \delta\), for all \(Q\) simultaneously,
The complexity term is the KL divergence from the prior: how much information the data had to inject. If the training minimum is flat, you can add a lot of noise to the weights without hurting training loss, so \(Q\) can be broad and close to the prior, giving a small KL. Dziugaite and Roy (2017) optimised such a bound directly and obtained the first non-vacuous generalisation bounds for stochastic neural networks with far more parameters than training examples on MNIST. In the largest empirical comparison so far, Jiang et al. (2019) trained over 10,000 networks and found that "sharpness-based measures such as PAC-Bayesian bounds … perform the best overall", while many norm-based measures, including a spectral-norm-product bound, correlated negatively with generalisation.
The deep learning puzzle¶
Zhang et al. (2016) ran the decisive experiment: standard image-classification networks "easily fit a random labeling of the training data", even with random pixels instead of images, and explicit regularisation barely changed this. So the class these networks represent can shatter training sets of tens of thousands of images; its Rademacher complexity is essentially maximal, and every uniform-convergence bound over the class is vacuous. Yet the same networks, trained on real labels, generalise well. Whatever explains generalisation, it is not the size of the hypothesis class alone. It must involve the data and the algorithm.
Double descent¶
Classical theory predicts a U-shaped test-error curve in model size.
But the U is only the left half of the story. Belkin, Hsu, Ma and Mandal (2019) showed a fuller picture across random-feature models, trees and networks: test error decreases, rises to a peak at the interpolation threshold (where the model can just barely fit the training data exactly), then decreases again as the model grows past it, often to below the classical minimum. Nakkiran et al. (2019) found the same in deep networks along three axes: model size, training epochs, and (surprisingly) sample size, where more data can make a model at the threshold worse. Loog et al. (2020) traced similar peaks in the statistics and physics literature back decades; the 2019 papers made them central.
The cleanest case is linear regression with the minimum-norm solution. With \(m = 40\) samples and models using the first \(p\) of 100 weakly informative features (the code in Build it):
The mechanism is not mysterious once you look at it. Below the threshold, least squares has a unique solution, and its variance grows like \(p/(m - p - 1)\) as \(p \to m\) (derived below). At \(p = m\) the design matrix is square and nearly singular: its smallest singular value is close to zero, and the solution must use huge coefficients along that direction to hit every noisy label exactly. Past the threshold there are infinitely many interpolating solutions, and the minimum-norm one spreads the fit across many directions; each extra feature adds a direction that can absorb noise harmlessly, so the variance falls again like \(m/(p - m - 1)\). Nakkiran et al. (2020) proved that for isotropic linear regression, optimally tuned \(\ell_2\) regularisation makes the curve monotone, and showed it mitigates double descent empirically in networks too: the peak is an artefact of fitting noise exactly with no regularisation, not a law of nature.
Implicit bias and benign overfitting¶
Who chose the minimum-norm solution? Nobody wrote it into the loss. Gradient descent did. On under-determined least squares, gradient descent started from zero stays in the row space of the data matrix, and the only interpolating solution there is the minimum-norm one. On linearly separable data with logistic loss, Soudry et al. (2018) proved that gradient descent's iterates converge in direction to the hard-margin SVM solution, slowly (at rate \(1/\log t\)), with no explicit regulariser. The optimiser is part of the inductive bias. This is why "the network has more parameters than data, so it must overfit" is the wrong frame: the question is which of the many zero-loss solutions the training procedure finds.
Benign overfitting. Bartlett, Long, Lugosi and Tsigler (2019) characterised exactly when the minimum-norm interpolant in linear regression predicts nearly optimally despite fitting noise: the data covariance must have a few strong directions (which carry the signal) and a large number of weak directions (which soak up the noise in tiny, spread-out components that barely affect predictions). High-dimensional, heavy-tailed spectra, which is what real embeddings look like, are exactly the benign case. Hastie, Montanari, Rosset and Tibshirani (2019) give exact asymptotic risk curves for this setting, including the double-descent peak.
Grokking and other puzzles¶
Power et al. (2022) trained small transformers on modular arithmetic tables and saw grokking: training accuracy reaches 100% early, validation accuracy stays at chance for a long time, then jumps to near-perfect, long after the model has "overfit". Weight decay makes it more likely and faster. The emerging explanation is a slow transition, driven by regularisation, from a memorising solution to a simpler, generalising circuit, which links grokking to implicit bias and to mechanistic interpretability. As of 2026 there is no single theory that predicts when large networks generalise, how much data they need, or the power-law exponents of scaling laws; the tools on this page are the vocabulary in which those questions are posed.
History¶
- 1968–1971: Vapnik and Chervonenkis prove uniform convergence of frequencies to probabilities for classes of finite VC dimension (in Russian 1968; Theory of Probability and its Applications, 1971).
- 1984: Valiant's "A theory of the learnable" defines PAC learning and brings computational complexity in (Turing Award, 2010).
- 1989: Blumer, Ehrenfeucht, Haussler and Warmuth connect PAC learnability and VC dimension in the computer-science framework.
- 1990s: Schapire's boosting answers Kearns and Valiant's weak-learning question; Vapnik's The Nature of Statistical Learning Theory (1995) and the SVM make margin-based theory practical; Wolpert's no-free-lunch theorems (1996); McAllester's PAC-Bayes (1998–1999).
- 2002: Bartlett and Mendelson popularise Rademacher complexity.
- 2016–2017: Zhang et al. show networks fit random labels; Neyshabur et al. and Dziugaite and Roy pursue norm-, sharpness- and PAC-Bayes-based explanations.
- 2018–2020: implicit bias of gradient descent (Soudry et al.); double descent (Belkin et al.; Nakkiran et al.); exact high-dimensional asymptotics (Hastie et al.); benign overfitting (Bartlett et al.).
- 2022: grokking.
First principles¶
Why a single model needs no theory, but a chosen one does. For a fixed \(h\) picked before seeing data, \(\hat R_S(h)\) is an average of i.i.d. bounded variables, and Hoeffding makes it close to \(R(h)\). The selection step breaks this: \(\hat h\) depends on \(S\), so its training error is biased downwards. Every bound on this page is a way of paying for selection: a union bound over \(|\mathcal{H}|\) choices, over \(\Pi_{\mathcal{H}}(2m)\) behaviours, over how much the posterior moved from the prior.
Why the logarithm of the class size. The union bound multiplies the failure probability by the number of hypotheses, and Hoeffding's failure probability is exponentially small in \(m\), so the number of hypotheses only costs its logarithm in sample size. \(\ln|\mathcal{H}|\) is the number of nats needed to name a hypothesis: the bound says you pay in data for every bit of choice. This is the Occam's razor theorem, and the bridge to minimum description length and Bayesian model selection.
Why VC dimension is the right count. On a fixed sample, two hypotheses that label it identically are indistinguishable to the learner, so the effective class size on \(m\) points is the number of distinct labellings, at most \(\Pi_{\mathcal{H}}(m)\). If that number is \(2^m\) for every \(m\), the class can explain any labelling of any sample, so the sample tells you nothing about unseen points. Finite VC dimension caps the growth at polynomial, \(\ln\Pi_{\mathcal{H}}(m) = O(d\ln m)\), and the union-bound logic goes through.
Why the classical bounds fail for deep networks, and what that does not mean. The bounds are worst-case over all distributions and all hypotheses in the class. Networks are capable of fitting noise, so worst-case bounds must be vacuous for them. That does not mean the theory is wrong: it means the class is the wrong unit of analysis. What generalises is the particular function SGD finds on natural data, which lives in a tiny, simple corner of the class. Modern theory therefore conditions on the algorithm (implicit bias, stability), the solution (norms, margins, flatness) or the data (spectra, low intrinsic dimension).
Why interpolation can be harmless. Fitting noise exactly requires putting energy into directions that carry the noise. If there are many weak directions, the noise can be spread thinly across them, so each adds a tiny, nearly independent error to predictions, and these average out. If there are few, the noise concentrates in a handful of large coefficients and wrecks prediction. Benign overfitting is a high-dimensional averaging effect.
The maths¶
Derivation: Hoeffding plus the union bound (finite class, agnostic)
Hoeffding's inequality: if \(Z_1,\dots,Z_m\) are independent with \(Z_i \in [a, b]\), then \(P\big(|\bar Z - \mathbb{E}\bar Z| > \varepsilon\big) \le 2\exp\!\big(-2m\varepsilon^2/(b-a)^2\big)\). For a fixed \(h\), \(Z_i = \ell(h(\mathbf{x}_i), y_i) \in [0, 1]\), so \(P(|\hat R_S(h) - R(h)| > \varepsilon) \le 2e^{-2m\varepsilon^2}\).
Union bound: \(P\big(\exists h \in \mathcal{H}: |\hat R_S(h) - R(h)| > \varepsilon\big) \le \sum_{h} 2e^{-2m\varepsilon^2} = 2|\mathcal{H}|e^{-2m\varepsilon^2}\). Setting this equal to \(\delta\) and solving, \(\varepsilon = \sqrt{(\ln|\mathcal{H}| + \ln(2/\delta))/2m}\).
Consequence for ERM: with \(h^{*} = \arg\min_{\mathcal{H}}R\), on the good event \(R(\hat h) \le \hat R_S(\hat h) + \varepsilon \le \hat R_S(h^{*}) + \varepsilon \le R(h^{*}) + 2\varepsilon\). ERM is within \(2\varepsilon\) of the best in class.
Derivation: the Sauer–Shelah lemma
Claim: if \(d_{VC}(\mathcal{H}) = d\) then for any set \(C\) of \(m\) points, the number of labellings \(|\mathcal{H}_C| \le \sum_{i=0}^d\binom{m}{i}\). Write \(\Phi_d(m)\) for the right-hand side. Induct on \(m\); it holds trivially for \(m = 0\) or \(d = 0\). Remove one point \(x\) from \(C\), leaving \(C'\). Each labelling of \(C'\) in \(\mathcal{H}_{C'}\) extends to one or two labellings of \(C\). Let \(\mathcal{H}_2\) be the labellings of \(C'\) that extend both ways. Then \(|\mathcal{H}_C| = |\mathcal{H}_{C'}| + |\mathcal{H}_2|\). The first term is at most \(\Phi_d(m-1)\) by induction. If \(\mathcal{H}_2\) shattered a set \(T \subseteq C'\), the original class would shatter \(T \cup \{x\}\) (every labelling of \(T\) extends both ways on \(x\)), so \(\mathcal{H}_2\) has VC dimension at most \(d - 1\) and \(|\mathcal{H}_2| \le \Phi_{d-1}(m-1)\). Pascal's rule \(\binom{m-1}{i} + \binom{m-1}{i-1} = \binom{m}{i}\) gives \(\Phi_d(m-1) + \Phi_{d-1}(m-1) = \Phi_d(m)\). Finally, for \(m \ge d\), \(\sum_{i\le d}\binom{m}{i} \le \sum_{i \le d}\frac{m^i}{i!} \le \big(\frac{m}{d}\big)^d\sum_{i}\frac{d^i}{i!} \le (em/d)^d\).
Derivation: Rademacher complexity of norm-bounded linear functions
Let \(\mathcal{F} = \{\mathbf{x} \mapsto \mathbf{w}^\top\mathbf{x} : \lVert\mathbf{w}\rVert_2 \le B\}\) and \(\lVert\mathbf{x}_i\rVert_2 \le R\). Then
The second step is Cauchy–Schwarz (the supremum aligns \(\mathbf{w}\) with the sum), the inequality is Jensen, and the cross terms vanish because \(\mathbb{E}[\sigma_i\sigma_j] = 0\) for \(i \ne j\). No dimension appears: capacity is controlled by the norm. With the \(\gamma\)-margin ramp loss (which is \(1/\gamma\)-Lipschitz) and Talagrand's contraction lemma, the loss class has complexity at most \(BR/(\gamma\sqrt{m})\), which is the margin bound.
Derivation: variance of least squares near the interpolation threshold
Well-specified model \(\mathbf{y} = X\boldsymbol\beta + \boldsymbol\varepsilon\), \(X \in \mathbb{R}^{m\times p}\) with i.i.d. \(\mathcal{N}(0,1)\) entries, \(\boldsymbol\varepsilon \sim \mathcal{N}(0, \sigma^2 I)\), test point \(\mathbf{x} \sim \mathcal{N}(0, I)\).
Under-parameterised (\(p < m - 1\)): \(\hat{\boldsymbol\beta} = (X^\top X)^{-1}X^\top\mathbf{y}\) is unbiased with covariance \(\sigma^2(X^\top X)^{-1}\). The excess test risk is \(\mathbb{E}[(\mathbf{x}^\top(\hat{\boldsymbol\beta} - \boldsymbol\beta))^2] = \sigma^2\,\mathbb{E}\operatorname{tr}\big((X^\top X)^{-1}\big)\). \(X^\top X\) is Wishart with \(m\) degrees of freedom, and \(\mathbb{E}[(X^\top X)^{-1}] = I/(m - p - 1)\), so the excess risk is \(\sigma^2\,p/(m - p - 1)\), which blows up as \(p \to m - 1\). At \(m = 40\): \(p = 30\) gives \(3.3\sigma^2\), \(p = 38\) gives \(38\sigma^2\).
Over-parameterised (\(p > m + 1\)), minimum-norm \(\hat{\boldsymbol\beta} = X^\top(XX^\top)^{-1}\mathbf{y}\): it projects \(\boldsymbol\beta\) onto the \(m\)-dimensional row space, so it misses a fraction \(1 - m/p\) of the signal (bias \(\lVert\boldsymbol\beta\rVert^2(1 - m/p)\) for isotropic \(\boldsymbol\beta\)), and its noise term is \(\sigma^2\,\mathbb{E}\operatorname{tr}\big((XX^\top)^{-1}\big) = \sigma^2\,m/(p - m - 1)\) (Hastie et al., 2019). As \(p\) grows past \(m\), variance falls and bias rises slowly, giving the second descent. In our experiment the learner also misses the features beyond \(p\) (a misspecified model), so the true signal outside the model acts as extra noise, but the shape is the same.
In practice¶
- Use bounds for intuition, not numbers. For modern models nearly all uniform bounds are vacuous (greater than 1). What transfers to practice is the logic: you pay for every choice made using the data, regularisation and margins buy generalisation, and held-out data is the only honest estimate.
- Selection on the test set is a finite-class problem. Every hyperparameter tried, prompt variant compared or checkpoint picked against a test set spends some of its reliability; the agnostic bound tells you roughly how much. Keep a final test set that is used once (see validation and leakage).
- Expect non-monotone curves. Near the interpolation threshold (model size roughly matching the effective number of training examples, or training until training loss just hits zero) test error can spike. More regularisation, early stopping, more data or a much larger model usually moves you off the peak.
- Prefer flat minima. Large learning rates, small batches, weight decay and sharpness-aware optimisation all bias training towards flatter solutions, consistent with the PAC-Bayes picture and with Jiang et al.'s findings. They are heuristics, not guarantees.
Common misconceptions¶
“More parameters than data points means overfitting”
Parameter count is not capacity (one parameter can have infinite VC dimension), and even maximal capacity does not force bad generalisation when the optimiser picks a simple interpolant. Double descent shows larger can be strictly better past the threshold.
“Double descent overturns the bias–variance trade-off”
It refines it. Bias and variance still decompose the error. What changed is the assumption that variance increases monotonically with model size: for minimum-norm solutions, variance peaks at the threshold and falls beyond it. With optimal regularisation the curve is monotone again.
“A vacuous bound means the theory is useless”
A vacuous bound says the worst case over the class is uninformative, not that the analysis is wrong. The productive response has been to find tighter, data- and algorithm-dependent quantities (margins, PAC-Bayes, stability), several of which now produce non-vacuous numbers.
Build it¶
Two experiments: count the labellings half-planes can realise (the VC dimension of lines in the plane), and reproduce double descent with minimum-norm least squares.
import numpy as np
rng = np.random.default_rng(0)
# 1) Shattering: how many of the 2^m labelings can half-planes in R^2 realise?
def dichotomies(P, trials=200_000):
W = rng.normal(size=(trials, 2)); b = rng.normal(size=trials) * 3
labels = (P @ W.T + b > 0).T # trials x m sign patterns
return len({tuple(r) for r in labels})
triangle = np.array([[0, 0], [1, 0], [0, 1]])
square = np.array([[0, 0], [1, 1], [1, 0], [0, 1]]) # XOR corners
print(f"3 points: {dichotomies(triangle)}/8 labelings, 4 points: {dichotomies(square)}/16 labelings")
# 2) Double descent: min-norm least squares using the first p of D = 100 weak features
D, n, sigma, trials = 100, 40, 0.5, 200
beta = rng.normal(size=D) / np.sqrt(D) # signal spread evenly over all features
def risk(p, lam=0.0):
errs = []
for _ in range(trials):
X = rng.normal(size=(n, D)); y = X @ beta + sigma * rng.normal(size=n)
Xt = rng.normal(size=(1000, D)); yt = Xt @ beta + sigma * rng.normal(size=1000)
A = X[:, :p]
if lam == 0: w = np.linalg.pinv(A) @ y # least squares; min-norm when p > n
else: w = np.linalg.solve(A.T @ A + lam * np.eye(p), A.T @ y)
errs.append(np.mean((Xt[:, :p] @ w - yt)**2))
return np.median(errs)
print(" p min-norm LS best ridge")
for p in (5, 20, 30, 36, 40, 44, 50, 70, 100):
ridge = min(risk(p, lam) for lam in (0.01, 0.1, 1.0, 10.0, 100.0))
print(f"{p:3d} {risk(p):10.3f} {ridge:10.3f}")
Output (about 8 seconds):
3 points: 8/8 labelings, 4 points: 14/16 labelings
p min-norm LS best ridge
5 1.274 1.147
20 2.029 1.126
30 3.421 1.049
36 6.477 1.032
40 67.570 1.037
44 6.820 1.031
50 3.262 1.002
70 1.325 0.951
100 0.942 0.907
Read the table against the theory. The total signal variance is about 1 and the noise variance 0.25, so predicting zero scores about 1.25. In the classical regime each extra feature brings a little signal and a lot of variance, so error climbs from 1.27 to 6.5 as \(p\) approaches 40, and at \(p = m = 40\) the median error is 67.6 (we report medians because the mean diverges there). Past the threshold it falls again, and at \(p = 100\) the interpolating min-norm model (0.94) beats every under-parameterised model. Ridge with a tuned \(\lambda\) has no peak at all, matching Nakkiran et al.'s theorem.
Things to try
- Set
sigma = 0and rerun. Predict first: does the peak survive without label noise? (In our run it does: about 60 at \(p = 40\). The signal in the features the model cannot see behaves exactly like label noise. At \(p = 100\) the error drops to about 0.56, matching the pure-bias formula \(\lVert\boldsymbol\beta\rVert^2(1 - m/p)\).) - Concentrate the signal:
beta = np.zeros(D); beta[:10] = 1 / np.sqrt(10). Now you get the full shape: a first descent to about 0.33 at \(p = 10\), the rise, a peak near 18 at \(p = 40\), and a second descent to about 1.0 at \(p = 100\), which this time does not beat the small model. Whether "bigger is better" past the threshold depends on where the signal lives. - Replace
pinvwith 2,000 steps of gradient descent from \(\mathbf{w} = 0\) at \(p = 100\) and check that it converges to the same minimum-norm solution. Start from a random \(\mathbf{w}_0\) instead and watch test error get worse. - Fix \(p = 40\) and vary \(m\) from 20 to 80: sample-wise double descent, where more data first hurts.
- Extend
dichotomiesto 4 points in 3-D and 5 points in 3-D to confirm that half-spaces in \(\mathbb{R}^3\) have VC dimension 4.
Check yourself¶
A finite class has 2^30 hypotheses and is realisable. How many examples guarantee error at most 5% with probability 99%?
\(m \ge (\ln 2^{30} + \ln 100)/0.05 = (20.79 + 4.61)/0.05 \approx 508\).
What is the VC dimension of intervals [a, b] on the real line (label 1 inside), and why can they not shatter 3 points?
- Any two points can be labelled all four ways. For three points \(x_1 < x_2 < x_3\), the labelling \((1, 0, 1)\) is impossible: an interval containing \(x_1\) and \(x_3\) contains \(x_2\).
Why does the agnostic bound scale as 1/√m while the realisable one scales as 1/m?
In the realisable case we only need to rule out hypotheses with true error above \(\varepsilon\) that make zero training mistakes, and the chance of that falls as \((1-\varepsilon)^m \approx e^{-\varepsilon m}\). In the agnostic case we must estimate error rates that are not near zero, and an average of Bernoulli variables with variance of order 1 has fluctuations of order \(1/\sqrt{m}\) (Hoeffding, or the central limit theorem).
Zhang et al. showed networks can fit random labels. Why does this make every bound based only on the hypothesis class vacuous for those networks?
If the class can fit random labels on the training set, its empirical Rademacher complexity is near its maximum and it shatters sets of that size, so its VC dimension is at least the training-set size. Any bound that depends only on the class must hold for the random-label case too, where test error is chance, so it cannot certify low test error for the real-label case. A non-vacuous bound must depend on the data, the algorithm or the particular solution.
In the min-norm regression experiment, why is the error at p = 100 lower than at p = 5, even though the model interpolates noisy labels?
At \(p = 100\) the model can represent all of the signal, and the minimum-norm interpolant spreads the label noise over the 60-dimensional null space of extra directions, where it adds small, nearly independent errors that average out on test points. At \(p = 5\) the model misses about 95% of the signal, so its bias dominates. This is benign overfitting in miniature.
Hard: gradient descent on separable data with logistic loss never reaches a minimum (the loss tends to zero only as ‖w‖ → ∞). In what sense does it still 'choose' a solution, and which one?
Its direction \(\mathbf{w}_t/\lVert\mathbf{w}_t\rVert\) converges. As \(\lVert\mathbf{w}\rVert\) grows, the loss is dominated by the points with the smallest margin (the exponential tail makes them dominate the gradient), so the direction converges to the one that maximises the minimum margin: the hard-margin SVM solution (Soudry et al., 2018). Convergence is only logarithmic in time, so validation loss can keep improving long after training accuracy hits 100%.
Hard: the PAC-Bayes bound contains KL(Q || P). Explain why flat minima give small bounds, and why the prior P must not depend on the training data.
If the loss is flat around the solution, a broad Gaussian \(Q\) centred there still has low training loss, and a broad \(Q\) can be close in KL to a broad prior \(P\); a sharp minimum forces a narrow \(Q\), which is far from any data-independent prior, so the KL is large. The prior must be fixed before seeing \(S\) because the proof applies a change-of-measure inequality under \(P\) to a quantity whose concentration relies on \(P\) being independent of the sample. (Data-dependent priors are possible with care, for example by building them from a separate part of the data.)
Go deeper¶
Papers
- A theory of the learnable — Valiant, CACM, 1984. The definition of PAC learning; short and readable.
- On the Uniform Convergence of Relative Frequencies of Events to Their Probabilities — Vapnik and Chervonenkis, 1971. Where the VC dimension comes from.
- Learnability and the Vapnik-Chervonenkis dimension — Blumer, Ehrenfeucht, Haussler and Warmuth, JACM, 1989. The PAC–VC equivalence.
- Rademacher and Gaussian Complexities: Risk Bounds and Structural Results — Bartlett and Mendelson, JMLR 2002. Data-dependent capacity.
- Some PAC-Bayesian Theorems — McAllester, Machine Learning, 1999. The original PAC-Bayes bounds.
- Understanding deep learning requires rethinking generalization — Zhang, Bengio, Hardt, Recht and Vinyals, 2016. The random-labels experiment.
- Computing Nonvacuous Generalization Bounds for Deep (Stochastic) Neural Networks — Dziugaite and Roy, 2017. PAC-Bayes made numerically meaningful.
- Reconciling modern machine learning practice and the bias-variance trade-off — Belkin, Hsu, Ma and Mandal, 2019. Double descent named and shown across model families.
- Deep Double Descent: Where Bigger Models and More Data Hurt — Nakkiran et al., 2019. Model-wise, epoch-wise and sample-wise double descent in deep networks.
- Optimal Regularization Can Mitigate Double Descent — Nakkiran, Venkat, Kakade and Ma, 2020. Why the peak is a regularisation artefact.
- Surprises in High-Dimensional Ridgeless Least Squares Interpolation — Hastie, Montanari, Rosset and Tibshirani, 2019. Exact risk curves.
- Benign Overfitting in Linear Regression — Bartlett, Long, Lugosi and Tsigler, 2019. When interpolation is harmless.
- The Implicit Bias of Gradient Descent on Separable Data — Soudry et al., 2017. Gradient descent converges to the max-margin direction.
- Fantastic Generalization Measures and Where to Find Them — Jiang et al., 2019. Forty measures tested on 10,000 networks.
- Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets — Power et al., 2022. Delayed generalisation and the role of weight decay.
- Double Descent Demystified — Schaeffer et al., 2023. A short, intuitive account of the linear-regression mechanism used here.
Videos and lectures
- Caltech Learning From Data: Lecture 2 (Is learning feasible?) and Lecture 7 (The VC dimension) — Yaser Abu-Mostafa. The best spoken introduction to Hoeffding, growth functions and VC; the full course is at work.caltech.edu.
Courses and books
- Understanding Machine Learning: From Theory to Algorithms — Shalev-Shwartz and Ben-David (free PDF for personal use). Chapters 2–6 are the clearest path from PAC to the fundamental theorem.
- Foundations of Machine Learning — Mohri, Rostamizadeh and Talwalkar (free). Rademacher complexity and margin bounds done carefully.
- Learning Theory from First Principles — Francis Bach, 2024 (free PDF). The modern synthesis: kernels, optimisation, neural networks and over-parameterisation.
Where this leads¶
- Probabilistic graphical models: the Bayesian alternative, where priors and posteriors replace worst-case bounds.
- Scaling laws: the empirical regularities that theory has yet to derive.
- Regularisation: dropout, weight decay, augmentation: the practical levers behind implicit and explicit bias.
- Benchmarks and their limits: selection effects and overfitting to test sets, in the wild.
- Open problems: why deep networks generalise remains one of them.