Search

Search papers and lessons

Rademacher Complexity

Level 4 · 13 min read

Rademacher complexity measures how well a family of functions can fit random plus-or-minus-one noise, and that ability sets how far training error can be from test error.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Calculus
  • Learning basics
  • Losses & regularization
  • ReadReady to readNot yet

TL;DR

A learning method picks one function from a family of functions using training data, and we want its error on new data to match its error on the training data. Rademacher complexity is a number that measures how much a family can cheat: it asks how well the best function in the family can match random plus-or-minus-one labels on your sample. A family that matches random noise easily can also memorise the real labels, so its training error can be far below its true error, which is the overfitting problem in its purest form.

Builds on: Empirical Risk Minimization, Concentration Inequalities, Bernoulli Distribution · Leads to: the random-label experiments that motivated modern generalisation theory

Where it's used

Bounding the error of a trained classifier. Before deploying a spam filter, a team wants a guarantee like "the error on new email is at most the error on our test set plus a small margin". Rademacher complexity of the filter's family of rules gives that margin. A family of simple linear rules gets a small margin; a family of very flexible rules gets a margin too large to be useful.

Explaining kernel and linear methods. Support vector machines with a bounded weight vector have a Rademacher bound that depends on the norm of the weights and the size of the data points, not on the number of features. This is why a kernel method with a huge feature space can still generalise when its weights stay small. The bound is a clean, checkable quantity, which is why textbooks use it as the standard example.

Studying deep networks. A neural network can have millions of parameters and still reach low training error. Rademacher-style bounds, once adapted to networks by controlling weight norms per layer, are one of the tools researchers use to ask when such a network can generalise. Their limits are part of the story: a 2016 study showed that large image networks can fit completely random labels, which means a capacity measure that ignores the data can be far too pessimistic.

How it works

Take a tiny instance. We have a sample of two points, x1x_1 and x2x_2, and a family F\mathcal{F} with two functions. Each function is written as the pair of values it takes on the sample:

  • fa=(1,1)f_a = (1, 1), so fa(x1)=1f_a(x_1) = 1 and fa(x2)=1f_a(x_2) = 1.
  • fb=(1,−1)f_b = (1, -1), so fb(x1)=1f_b(x_1) = 1 and fb(x2)=−1f_b(x_2) = -1.
  1. Draw random signs. Pick σ1\sigma_1 and σ2\sigma_2 independently, each equal to +1+1 or −1-1 with probability one half (a coin flip mapped to plus or minus one). There are four equally likely patterns: (+,+)(+,+), (+,−)(+,-), (−,+)(-,+), (−,−)(-,-). Check: the four probabilities add to 11, since 4×14=14 \times \tfrac14 = 1.
  2. Score each function against the signs. For a pattern and a function, compute the average of σif(xi)\sigma_i f(x_i) over the two points. Take (+,+)(+,+): faf_a scores 12(1+1)=1\tfrac12(1 + 1) = 1, and fbf_b scores 12(1−1)=0\tfrac12(1 - 1) = 0. Check: a function that agrees with the signs everywhere scores 11.
  3. Keep the best function. For each pattern, keep the highest score in the family. For (+,+)(+,+) that is max⁡(1,0)=1\max(1, 0) = 1. Check: the best function is the one that fits the signs best, so this number can never be below any single function's score.
  4. Average over the patterns. The four best scores are 11 for (+,+)(+,+), 11 for (+,−)(+,-), 00 for (−,+)(-,+) and 00 for (−,−)(-,-). Their average is 1+1+0+04=12\tfrac{1+1+0+0}{4} = \tfrac12. That average is the empirical Rademacher complexity of this family on this sample. Check: it lies between 00 and 11.
flowchart LR
  S["Sample x1, x2"] --> G["Draw signs (sigma1, sigma2)"]
  G --> B["Best score in the family for these signs"]
  B --> M["Average the best scores over all four patterns"]
  M --> C["Empirical Rademacher complexity = 1/2"]

The number 12\tfrac12 says the family can match random signs about half the time on this tiny sample. A family that could match every sign pattern perfectly would score 11; a family with one fixed function would score close to 00.

The math

Random signs

A Rademacher variable is a random number σ\sigma with P(σ=+1)=P(σ=−1)=12P(\sigma = +1) = P(\sigma = -1) = \tfrac12. Its average is zero, and that is what makes it useful: a sum of signs cancels out unless the terms are chosen to line up with the sign. Step 1 above draws nn such variables σ1,…,σn\sigma_1, \dots, \sigma_n, one per sample point.

Step 2 in symbols

Let S=(x1,…,xn)S = (x_1, \dots, x_n) be the sample. The score of a function ff against the signs is the average of σif(xi)\sigma_i f(x_i):

1n∑i=1nσif(xi).\frac{1}{n}\sum_{i=1}^{n} \sigma_i f(x_i).

Here σi\sigma_i is the sign attached to point ii, and f(xi)f(x_i) is the function's value there. A large score means ff tracks the signs.

Step 3 in symbols: the supremum

Step 3 keeps the best function, which is the supremum over the family:

sup⁡f∈F1n∑i=1nσif(xi).\sup_{f \in \mathcal{F}} \frac{1}{n}\sum_{i=1}^{n} \sigma_i f(x_i).

The supremum is taken over the whole family F\mathcal{F}, so it depends on the signs. It can be negative when every function anti-tracks the signs, which is why the average in step 4 matters.

Step 4 in symbols: the empirical Rademacher complexity

Average over all sign patterns with the expected value over σ\sigma:

R^S(F)=Eσ[sup⁡f∈F1n∑i=1nσif(xi)].\hat{\mathfrak{R}}_S(\mathcal{F}) = \mathbb{E}_{\sigma}\left[\sup_{f \in \mathcal{F}} \frac{1}{n}\sum_{i=1}^{n} \sigma_i f(x_i)\right].

This is the empirical Rademacher complexity. It depends on the sample SS and on the family, and it can be computed from data. For the tiny instance, the expectation is the average over the four patterns, giving 12\tfrac12.

Averaging over the sample as well gives the Rademacher complexity Rn(F)=ES[R^S(F)]\mathfrak{R}_n(\mathcal{F}) = \mathbb{E}_S\big[\hat{\mathfrak{R}}_S(\mathcal{F})\big], which describes the family before any data is seen.

Why this controls the gap

For a loss ℓ\ell with values in [0,1][0, 1] and a sample of size nn, one common form of the bound says that with probability at least 1−δ1 - \delta, for every ff in the family,

R(f)≤R^S(f)+2 Rn(ℓ∘F)+ln⁡(1/δ)2n.R(f) \le \hat{R}_S(f) + 2\,\mathfrak{R}_n(\ell \circ \mathcal{F}) + \sqrt{\frac{\ln(1/\delta)}{2n}}.

Here R(f)R(f) is the true risk (the average loss on new data), R^S(f)\hat{R}_S(f) is the training risk, ℓ∘F\ell \circ \mathcal{F} is the family of loss functions, and δ\delta is the allowed chance that the bound fails. The last term is the usual concentration term from concentration inequalities: it shrinks like 1/n1/\sqrt{n}. The middle term is the Rademacher complexity of the losses. The reason it appears is a symmetry argument: the largest gap between true and training risk has an expected size that can be bounded by twice the Rademacher complexity.

A bound for linear rules

Take the family of linear rules f(x)=⟨w,x⟩f(x) = \langle w, x \rangle with ∥w∥≤B\|w\| \le B, on inputs with ∥xi∥≤R\|x_i\| \le R. Three steps give the bound.

  1. For a fixed sign pattern, the best score is sup⁡∥w∥≤B1n⟨w,∑iσixi⟩=Bn∥∑iσixi∥\sup_{\|w\| \le B} \frac{1}{n}\langle w, \sum_i \sigma_i x_i \rangle = \frac{B}{n}\big\|\sum_i \sigma_i x_i\big\|, by the Cauchy–Schwarz inequality.
  2. Averaging over signs and using Jensen's inequality (the square root is concave), E∥∑iσixi∥≤E∥∑iσixi∥2=∑i∥xi∥2\mathbb{E}\big\|\sum_i \sigma_i x_i\big\| \le \sqrt{\mathbb{E}\big\|\sum_i \sigma_i x_i\big\|^2} = \sqrt{\sum_i \|x_i\|^2}, because the cross terms have zero average.
  3. Since ∥xi∥≤R\|x_i\| \le R, the square root is at most n R\sqrt{n}\,R, so Rn(F)≤Bnn R\mathfrak{R}_n(\mathcal{F}) \le \frac{B}{n} \sqrt{n}\,R.
Rn(F)≤BRn.\mathfrak{R}_n(\mathcal{F}) \le \frac{B R}{\sqrt{n}}.

The bound has no dependence on the number of features, only on the weight size BB, the input size RR and the sample size nn.

2040608010000.20.40.60.81n (number of samples)complexity bound
  • BR / sqrt(n) with B = R = 1
More samples shrink the bound like one over the square root of n. With B = R = 1, 100 samples give 0.1 and 10,000 samples give 0.01.

Worked examples

Example
1. One function, no choice

Family F={f}\mathcal{F} = \{f\} with f=(1,−1)f = (1, -1) on two points. There is only one function, so the supremum is just its score.

  1. The four sign patterns are (+,+)(+,+), (+,−)(+,-), (−,+)(-,+), (−,−)(-,-).
  2. Score for (+,+)(+,+): 12(1⋅1+(−1)⋅1)=12(1−1)=0\tfrac12(1 \cdot 1 + (-1) \cdot 1) = \tfrac12(1 - 1) = 0.
  3. Score for (+,−)(+,-): 12(1⋅1+(−1)⋅(−1))=12(1+1)=1\tfrac12(1 \cdot 1 + (-1)\cdot(-1)) = \tfrac12(1 + 1) = 1.
  4. Score for (−,+)(-,+): 12((−1)⋅1+1⋅(−1))=12(−1−1)=−1\tfrac12((-1)\cdot 1 + 1 \cdot (-1)) = \tfrac12(-1 - 1) = -1.
  5. Score for (−,−)(-,-): 12((−1)⋅1+(−1)⋅(−1))=12(−1+1)=0\tfrac12((-1)\cdot 1 + (-1)\cdot(-1)) = \tfrac12(-1 + 1) = 0.
  6. Average the four scores: 14(0+1−1+0)=0\tfrac14(0 + 1 - 1 + 0) = 0.

Interpretation: a single fixed function cannot fit the noise, because its scores cancel over all patterns. The complexity is 00, so this family has no room to memorise.

Example
2. The family of all labelings

Take n=3n = 3 points and the family of all 23=82^3 = 8 functions that output ±1\pm 1 on those points. For any sign pattern σ\sigma, one of those functions equals σ\sigma on every point.

  1. Fix any sign pattern σ=(σ1,σ2,σ3)\sigma = (\sigma_1, \sigma_2, \sigma_3).
  2. Choose ff with f(xi)=σif(x_i) = \sigma_i for each ii. This ff is in the family.
  3. Its score is 13(σ12+σ22+σ32)=13(1+1+1)=1\tfrac13(\sigma_1^2 + \sigma_2^2 + \sigma_3^2) = \tfrac13(1 + 1 + 1) = 1.
  4. No function can score above 11, since each term σif(xi)\sigma_i f(x_i) is at most 11.
  5. So the supremum is 11 for every pattern, and the average over patterns is 11.

Interpretation: this family can fit any labels on these points. Plugging R=1\mathfrak{R} = 1 into the bound gives R(f)≤R^S(f)+2+⋯R(f) \le \hat{R}_S(f) + 2 + \sqrt{\cdots}, and since the true risk never exceeds 11 the bound says nothing. Complexity 11 means the bound is vacuous.

Try it: with n=2n = 2 points and the family of all four functions on those points, what is the empirical Rademacher complexity? Answer: it is 11. The same argument as above applies: for any pattern, the function equal to the signs scores 11, and no function scores more.

Example
3. A realistic linear classifier

A spam filter is a linear rule with ∥w∥≤1\|w\| \le 1, trained on n=10,000n = 10{,}000 emails whose feature vectors satisfy ∥xi∥≤1\|x_i\| \le 1. The chance of failure is δ=0.05\delta = 0.05.

  1. Rademacher bound for linear rules: Rn≤BRn\mathfrak{R}_n \le \dfrac{BR}{\sqrt{n}} with B=R=1B = R = 1.
  2. Compute 10,000=100\sqrt{10{,}000} = 100, so Rn≤1100=0.01\mathfrak{R}_n \le \dfrac{1}{100} = 0.01.
  3. The complexity term is 2×0.01=0.022 \times 0.01 = 0.02.
  4. Compute the concentration term: ln⁡(1/0.05)=ln⁡20≈2.996\ln(1/0.05) = \ln 20 \approx 2.996.
  5. Divide by 2n=20,0002n = 20{,}000: 2.99620,000≈0.00015\dfrac{2.996}{20{,}000} \approx 0.00015.
  6. Take the square root: 0.00015≈0.0122\sqrt{0.00015} \approx 0.0122.
  7. Add the two terms: 0.02+0.0122=0.03220.02 + 0.0122 = 0.0322.

Interpretation: with high confidence, the true error of the spam filter is at most its training error plus about 0.0320.032. A filter with training error 0.040.04 therefore has true error at most about 0.0720.072.

Try it: the same filter is trained on n=40,000n = 40{,}000 emails, with the same norm bounds. What is the bound on Rn\mathfrak{R}_n? Answer: 140,000=1200=0.005\dfrac{1}{\sqrt{40{,}000}} = \dfrac{1}{200} = 0.005.

Common mistakes and tradeoffs

It is tempting to think Rademacher complexity counts parameters. In fact it measures how well the family fits random signs on the data, which depends on weight norms, input sizes and the sample. A model with a million weights but tight norm limits can have a small complexity, and a model with few parameters but unlimited flexibility can have a large one.

It is tempting to think a small complexity means the model is good. In fact it only bounds the gap between training and true error. A family can have a small gap and still be too simple to fit the data, so training error stays high. The bound is about the gap, not about accuracy.

It is tempting to think the bound is tight. In fact the bounds are usually loose by large factors, because they must hold for every function in the family at once. The random-label experiments in the paper linked above show networks that fit random labels, which a tight complexity measure would have to penalise heavily. Many researchers therefore look for data-dependent or norm-based measures.

When to use it. Use Rademacher complexity to prove a generalisation bound for a family you can analyse, such as linear rules with norm limits, kernel methods or ensembles with bounded weights. It works for any loss and does not need the family to be finite.

When not to use it. Do not use it to choose a model on a validation set; cross-validation is cheaper and more accurate there. Do not expect it to give useful numbers for very large neural networks without extra structure.

Alternatives. The VC dimension gives a bound that depends only on the family's combinatorics and is easier to compute, but it is often looser for real-valued function classes. Gaussian complexity replaces the signs with Gaussian noise and is easier to calculate in some settings.

History

In the 1970s, Vapnik and Chervonenkis showed that the size of a family of classifiers controls how well it generalises, and they introduced the symmetrisation argument that later theory builds on. Their measure, the VC dimension, counts patterns a family can shatter, and it is distribution-free but often too coarse.

In 2001 Koltchinskii proposed penalising a model by a Rademacher-type quantity, and in 2002 Bartlett and Mendelson developed Rademacher and Gaussian complexities as general tools for proving generalisation bounds. The method caught on because it works directly with the data, applies to real-valued losses, and produces bounds that adapt to norms rather than raw parameter counts. The name comes from the Rademacher functions, the plus-or-minus-one functions studied by the mathematician Hans Rademacher in the 1920s, which are the sign patterns used here.

Recap

  • A Rademacher variable is a random ±1\pm 1 sign with equal chances, so its average is zero.
  • The empirical Rademacher complexity averages, over random signs, the best score a family can achieve in matching them on the sample.
  • Its expected version Rn\mathfrak{R}_n bounds the gap between true and training risk, up to a 1/n1/\sqrt{n} term from concentration.
  • Norm-limited linear rules have Rn≤BR/n\mathfrak{R}_n \le BR/\sqrt{n}, a bound that ignores the number of features.
  • Next, read the overfitting lesson for the intuition behind the gap, and the random-label paper for why such bounds can be too pessimistic for deep networks.

Check yourself

QuestionWhat is the empirical Rademacher complexity of a family with a single function on a sample, if that function's values on the sample are (1,1)(1, 1)?Show answer

Compute the four sign patterns. For (+,+)(+,+) the score is 12(1+1)=1\tfrac12(1 + 1) = 1. For (+,−)(+,-) it is 12(1−1)=0\tfrac12(1 - 1) = 0. For (−,+)(-,+) it is 12(−1+1)=0\tfrac12(-1 + 1) = 0. For (−,−)(-,-) it is 12(−1−1)=−1\tfrac12(-1 - 1) = -1. The average is 14(1+0+0−1)=0\tfrac14(1 + 0 + 0 - 1) = 0. A single function has no choice to make, and its scores cancel across sign patterns, so the complexity is 00.

QuestionFor the linear bound Rn≤BR/n\mathfrak{R}_n \le BR/\sqrt{n}, what is the bound when B=2B = 2, R=3R = 3 and n=36n = 36?Show answer

Compute BR=2×3=6BR = 2 \times 3 = 6. Compute 36=6\sqrt{36} = 6. Divide: 66=1\dfrac{6}{6} = 1. The complexity bound is 11.

QuestionWhy does a family that can fit every labeling of the sample give a useless generalisation bound?Show answer

Such a family has empirical Rademacher complexity 11, because for every sign pattern some function matches the signs exactly and scores 11. The bound has a term 2Rn2\mathfrak{R}_n, which would be 22 in this case. Since the true risk of a [0,1][0,1] loss is at most 11, a bound that allows 22 plus a positive term says nothing about the risk.

QuestionA linear family has B=1B = 1, R=1R = 1, and a sample of n=400n = 400 points. A learner has training risk 0.100.10 and the failure probability is δ=0.05\delta = 0.05. Give the bound on the true risk, using the form in the math section.Show answer

Complexity term: 2⋅1⋅1400=2⋅120=0.102 \cdot \dfrac{1 \cdot 1}{\sqrt{400}} = 2 \cdot \dfrac{1}{20} = 0.10. Concentration term: ln⁡202⋅400=2.996800≈0.003745≈0.0612\sqrt{\dfrac{\ln 20}{2 \cdot 400}} = \sqrt{\dfrac{2.996}{800}} \approx \sqrt{0.003745} \approx 0.0612. Total bound: 0.10+0.10+0.0612=0.26120.10 + 0.10 + 0.0612 = 0.2612, so the true risk is at most about 0.260.26.

QuestionWhy does a norm limit on the weights matter more than the number of features in this bound?Show answer

The bound on Rn\mathfrak{R}_n depends on BB, the bound on the weight size, and RR, the bound on the input size, and on nn. It does not depend on the number of features. A score is ⟨w,∑iσixi⟩\langle w, \sum_i \sigma_i x_i \rangle, which is at most BB times the length of ∑iσixi\sum_i \sigma_i x_i. So the weight limit caps how well the family can match random signs, however many features there are.

Sources