Quant Memo
Advanced

Structural Risk Minimization

Fitting harder always lowers training error, so training error cannot tell you when to stop. Structural risk minimization stacks your model families from simple to complex, charges each one a complexity fee decided in advance, and picks the level where fit plus fee is smallest.

Prerequisites: Empirical Risk Minimization, The VC Generalization Bound, The Generalization Gap

Empirical risk minimization has one instruction: among the models available, take the one that scores best on your data. Give it a rich enough family and it will always find something that fits perfectly, and that something will be worthless. The rule contains no brake, because training error only ever goes down as you allow more flexibility. Asking it "should I stop at degree three or go to degree twelve?" is asking a question it cannot answer — twelve always wins.

The obvious response is "add a penalty for complexity", and everyone nods. The hard part is the next question: how much penalty? Pick it too small and you are back to ERM. Pick it too large and you underfit everything. Pick it by trying values and seeing which works and you have quietly used your data twice.

Structural risk minimization answers this by refusing to invent the penalty. It reads the penalty off a generalization bound — a formula that already tells you how far a class's training score can drift from its true score — and then minimises the bound rather than the training error. The penalty is not a tuning knob. It is the price the mathematics already quoted you.

The analogy: the handicap agreed before the round

Two portfolio managers pitch you. One runs a three-parameter carry model that returned 12% last year. The other runs a forty-parameter machine-learning ensemble that returned 15%.

Ranking them by realised return is ERM, and it picks the ensemble every time — including in the world where the ensemble is pure curve-fitting. What you actually want is a handicap: the elaborate model should have to beat the simple one by a margin, and that margin should reflect how much more room it had to get lucky.

The crucial detail is that the handicap must be agreed before the round. If you set it after seeing the scores, you are not handicapping, you are choosing your favourite. Structural risk minimization is the handicap system: you write down the levels and their fees in advance, then let the data pick a level.

Writing it down

Start by stacking your hypothesis classes so each contains the previous one:

H1H2H3\mathcal{H}_1 \subset \mathcal{H}_2 \subset \mathcal{H}_3 \subset \cdots

This is the structure. Polynomials of degree 1, 2, 3, ...; trees of depth 1, 2, 3, ...; models using the first kk factors. The nesting means a richer level can always match a simpler one, so training error can only fall as kk rises.

Next hand out a confidence budget. Choose weights pkp_k with kpk1\sum_k p_k \le 1 before seeing any data — pk=2kp_k = 2^{-k} is the usual choice — and spend δpk\delta p_k of your total failure probability δ\delta on level kk. This is what lets a single guarantee cover every level at once.

Feed those into the finite-class uniform-convergence bound. For level kk, with probability at least 1δpk1 - \delta p_k, every hHkh \in \mathcal{H}_k satisfies R(h)R^S(h)+pen(k,n)R(h) \le \hat{R}_S(h) + \text{pen}(k, n) where

pen(k,n)=lnHk+ln(1/pk)+ln(1/δ)2n\text{pen}(k, n) = \sqrt{\frac{\ln|\mathcal{H}_k| + \ln(1/p_k) + \ln(1/\delta)}{2n}}

In words: the fee for a level is the square root of (how many rules it contains, plus how little of your confidence budget you set aside for it, plus your overall confidence demand) divided by twice your sample size. Richer levels pay more through lnHk\ln|\mathcal{H}_k|; levels you thought less likely pay more through ln(1/pk)\ln(1/p_k); more data makes everything cheaper.

Then the rule itself:

k^=argmink[  R^S(h^k)+pen(k,n)  ]\hat{k} = \arg\min_{k} \left[\; \hat{R}_S(\hat{h}_k) + \text{pen}(k, n) \;\right]

Fit the best model at every level, add each one's fee, and take the smallest total. You are minimising an upper bound on true risk rather than the training error itself — and unlike training error, that bound has a genuine minimum, because its first term falls with kk while its second rises.

H₁ H₂ H₃ H₄ H₅ fee 0.172 fee 0.156 fee 0.137 fee 0.117 fee 0.091 each level contains the one inside it, and costs more
The structure is fixed before any data is seen: nested classes, each with a fee written next to it. All the data does is choose which ring to stop at.

Worked example 1: choosing a level with 500 observations

Five nested classes, each roughly a hundred times richer than the last, so lnHk=kln100=4.605k\ln|\mathcal{H}_k| = k\ln 100 = 4.605k. Weights pk=2kp_k = 2^{-k}, so ln(1/pk)=0.693k\ln(1/p_k) = 0.693k. Take δ=0.05\delta = 0.05, so ln(1/δ)=2.996\ln(1/\delta) = 2.996, and n=500n = 500, so the denominator 2n=10002n = 1000.

The numerator at level kk is 4.605k+0.693k+2.996=5.298k+2.9964.605k + 0.693k + 2.996 = 5.298k + 2.996.

kknumeratorpen(k,n)\text{pen}(k, n)R^S\hat{R}_Sbound
18.2940.09110.3400.431
213.5920.11660.2400.357
318.8910.13740.1900.327
424.1890.15550.1780.334
529.4870.17170.1720.344

Check one row by hand. At k=3k = 3: pen=18.891/1000=0.018891=0.1374\text{pen} = \sqrt{18.891/1000} = \sqrt{0.018891} = 0.1374, and 0.190+0.1374=0.3270.190 + 0.1374 = 0.327.

Read the two columns against each other. Training error falls at every single level — 0.340, 0.240, 0.190, 0.178, 0.172 — so ERM would take level 5 without hesitating. The bound bottoms out at level 3, because after that the fee rises faster than the fit improves: going from 3 to 4 buys 1.2 points of training error and costs 1.8 points of fee. SRM stops at 3.

complexity level k 1 2 3 4 5 fit fee bound minimum total fit keeps improving; the total does not
The fit curve never turns up, which is exactly why training error cannot choose a level. Adding a fee that rises with complexity creates a bottom, and the bottom is the answer SRM returns.

Worked example 2: the same structure with ten times the data

Nothing about the classes or the weights changes. Only nn moves, from 500 to 5,000, so the denominator becomes 2n=10,0002n = 10{,}000 and every fee divides by 10=3.162\sqrt{10} = 3.162.

kkpen(k,n)\text{pen}(k, n)R^S\hat{R}_Sbound
10.02880.3400.369
20.03690.2400.277
30.04350.1900.233
40.04920.1780.227
50.05430.1720.226

Now the minimum sits at level 5. The fees collapsed while the fit numbers stayed put, so complexity that was unaffordable on 500 observations is affordable on 5,000. SRM is not a fixed preference for simple models; it is a preference that weakens as evidence accumulates — which is exactly the behaviour you want, and exactly what a fixed hand-chosen penalty fails to deliver.

One more calculation makes the role of the weights vivid. Suppose you skip the pkp_k budget and instead apply one union bound over the whole union H1H5\mathcal{H}_1 \cup \cdots \cup \mathcal{H}_5, whose size is 100+104+106+108+10101.01×1010100 + 10^4 + 10^6 + 10^8 + 10^{10} \approx 1.01 \times 10^{10}, giving lnH=23.04\ln|\mathcal{H}| = 23.04. At n=500n = 500 the fee is (23.04+3.00)/1000=0.1614\sqrt{(23.04 + 3.00)/1000} = 0.1614the same for every level. A constant added to every row cannot change which row is smallest, so the winner is whichever has the lowest training error: level 5. You have reinvented ERM. The ln(1/pk)\ln(1/p_k) term is not decoration; it is the entire mechanism by which simple models get preferred.

The explorer below shows the underlying shape SRM is trying to locate without a test set: drag complexity and watch training error slide down while test error turns back up.

Bias–variance explorer
model complexity →sweet spot
test error 1.54train error 0.92underfitting

SRM minimises R^S(h^k)+pen(k,n)\hat{R}_S(\hat{h}_k) + \text{pen}(k,n) instead of R^S\hat{R}_S alone. The penalty is not invented — it is read off a generalization bound, and the confidence weights pkp_k, fixed before you see data, are what make richer levels cost more.

What this means in practice

You have almost certainly done SRM without the name. AIC and BIC are fit plus a parameter-count fee. Ridge and lasso are fit plus a norm fee, which is the same idea with a continuous index instead of integer levels — see Regularization as a Prior. Minimum description length is fit plus a code-length fee. The template is universal; only the fee differs.

In real work, cross-validation usually beats it. SRM's bounds are worst-case over every distribution and every hypothesis in the level, and are famously loose — a bound of 0.33 next to a genuine test error of 0.19 is typical. Cross-validation estimates the actual quantity on your actual data and is normally much tighter.

But SRM survives where cross-validation cannot. When splitting is destructive — tiny samples, heavily overlapping time series, online settings where each observation arrives once — a penalty computed from a formula is the only mechanism you have. It is also the right frame for reasoning about why a complexity control should behave a certain way, which no amount of cross-validating tells you.

The structure must be fixed before you look at the data. Choosing the nesting after inspecting results is model selection wearing a proof as a disguise, and it invalidates the guarantee completely.

The most common misreading is to take the bound's value seriously. It is not a prediction of test error; it is a worst-case ceiling that is routinely two or three times too high. What SRM gives you is the location of the minimum, not its height, and quoting the bound as an expected error is simply wrong. Two further traps. First, SRM is not cross-validation and does not become cross-validation when you replace the fee with a validation score — that procedure is valid, useful and different, and it consumes data that SRM does not. Second, the penalty must depend on kk; a complexity term that charges every level the same amount, as the union-bound calculation above shows, reduces SRM to plain ERM on the largest class while looking rigorous. And the classes must genuinely nest — if H2\mathcal{H}_2 does not contain H1\mathcal{H}_1, training error can rise with kk and the whole trade-off argument falls apart.

Practise it

  1. In example 1, what training error would level 4 need for SRM to choose it? (Answer: below 0.3270.1555=0.1710.327 - 0.1555 = 0.171.)
  2. Recompute the level-2 fee in example 1 with δ=0.01\delta = 0.01 instead of 0.05. (Answer: numerator =5.298(2)+4.605=15.201= 5.298(2) + 4.605 = 15.201, fee =0.015201=0.1233= \sqrt{0.015201} = 0.1233.)
  3. With pk=2kp_k = 2^{-k}, what is kpk\sum_k p_k over all k1k \ge 1, and why does the budget need to be at most 1? (Answer: it sums to 1; the total failure probability across levels must not exceed δ\delta.)
  4. Between n=500n = 500 and n=5,000n = 5{,}000 the chosen level moved from 3 to 5. At roughly what nn does level 4 first beat level 3? (Answer: solve 0.190+18.891/2n=0.178+24.189/2n0.190 + \sqrt{18.891/2n} = 0.178 + \sqrt{24.189/2n}, giving 1/2n(4.9184.346)=0.012\sqrt{1/2n}\,(4.918 - 4.346) = 0.012, so 2n=(0.572/0.012)2=22722n = (0.572/0.012)^2 = 2272 and n1136n \approx 1136.)

Related concepts

Practice in interviews

Further reading

  • Vapnik, The Nature of Statistical Learning Theory, ch. 4
  • Shalev-Shwartz & Ben-David, Understanding Machine Learning, ch. 7.2
ShareTwitterLinkedIn