Foundations to Frontier
Tests

The No Free Lunch Theorem

Is there a best learning algorithm? The No Free Lunch theorems say no: averaged over all possible problems, every learner (and every black-box optimizer) performs exactly the same, so any advantage on some problems is paid for on others. This topic states and proves NFL for off-training-set generalization and for search, connects it to the need for inductive bias and prior knowledge, and explains why learning works anyway: real-world problems are highly structured. In the research exercise you verify both theorems by exhaustive enumeration, then show that once the problem class has structure, algorithm rankings appear, and they depend on which structure.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

No algorithm wins everywhere

Suppose someone gives you a few examples of a rule and asks you to guess the rest. If the rule could be anything, with no pattern at all, the examples tell you nothing about the unseen cases, and every guessing strategy is a coin flip. Learning only works because we assume something about the world: nearby things behave alike, simpler explanations are likelier, physics is smooth. Those assumptions are a learner’s inductive bias, and they help only when they match the world.

No free lunch: averaged over every possible world, all learners tie
training inputs (click):
possible worlds:
1-NN
50.0%
majority
50.0%
always 0
50.0%
anti 1-NN
50.0%
256 possible target functions · 4 unseen inputs · average accuracy on the unseen inputs shown above — exactly 50% for every learner
If every labeling of the unseen points is equally possible, the training labels say nothing about them, so no learner can beat a coin flip on average. Learning only works because real problems aren't arbitrary: they're smooth, or skewed, or structured. A learner's built-in assumption (its inductive bias) wins when the assumption matches the world, as 1-NN does on smooth targets, and loses equally when it doesn't (anti 1-NN).
Why engineers care

NFL is why there is no universal best model. Choosing a CNN for images (translation symmetry), a physics-informed model for dynamics, or a Gaussian process with a smooth kernel for sensor fields all encode prior knowledge. In robotics and space, where data is scarce, building the right assumptions in (symmetries, conservation laws, priors) often matters more than any learning algorithm.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Can one learning algorithm be best on every possible problem?
  2. 2. The assumptions a learner makes to generalize are its…
  3. 3. Learning works in practice because real problems…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Off-training-set generalization

Take a finite input set X, a training set T ⊂ X, and binary targets f. A learner sees f on T and must predict f off T. If all 2∣X∣2^{|X|} targets are equally likely, then given the training labels, the labels off T are still uniform. With 8 inputs and 4 seen, 16 targets agree with the training data, and for every unseen point exactly half of them say 1. So every learner’s expected off-training-set accuracy is exactly 1/2 (Wolpert, 1996).

What NFL does and doesn’t say

  • It does say that no learner beats another when averaged uniformly over all problems.
  • It doesn’t say learning is hopeless. Real problems are not uniformly random. It says the only way to win is to assume something, and to be right about it.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Number of binary target functions on 8 inputs:
  2. 2. With 8 inputs and 4 labels seen, how many targets agree with the data?
  3. 3. Averaged over all targets, a learner's off-training-set accuracy is…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 35 minUndergraduate students and practising engineers.

NFL for optimization

Wolpert and Macready (1997) proved the analogue for black-box search. Averaged over all functions f:X→Yf: X\to Y on finite sets, any two algorithms that don’t revisit points produce the same distribution of observed values after m evaluations. Hill climbing, random search, a fixed sweep and even a deliberately bad “anti-hill-climber” all tie. Over the 3⁸ = 6561 functions from 8 points to 3 values, the mean best-so-far after 1–4 evaluations is 1.000, 1.444, 1.667, 1.790 for every algorithm.

Structure breaks the tie

  • Smooth targets (at most one label change along x): 1-NN gets 87.5% off-training-set, majority 71.9%, and the anti-1-NN 12.5%.
  • Search: on smooth single-peak functions hill climbing wins, but on broad-plateau unimodal functions exploring far wins.

The ranking of algorithms is a property of algorithm and problem class together.

Learning-theory version

A sharper form (Shalev-Shwartz and Ben-David, 2014): for any learner and any sample size below |X|/2, there is a distribution where a perfect classifier exists, yet the learner errs at least 1/8 of the time with probability at least 1/7. Hence learning requires restricting the hypothesis class, which is the start of PAC learning (B2).

🐍 Exercise 1: NFL by enumeration
Enumerate all 256 binary targets on 8 inputs. For several learners (all zeros, majority, 1-NN and anti-1-NN), compute the average off-training-set accuracy and verify it is exactly 50%. Then restrict to smooth targets and see which inductive bias pays off.
📝 Quick check (Level 2)
0/3 answered
  1. 1. NFL for optimization compares algorithms that…
  2. 2. On smooth targets, 1-NN scored…
  3. 3. NFL implies that useful learning needs…

Level 3: Advanced

★★★★☆ Advanced⏱ 35 minGraduate level, with full derivations and proofs.

Proof (off-training-set, uniform targets)

Fix the training labels. The consistent targets are all 2∣X∖T∣2^{|X\setminus T|} completions of the unseen labels, each equally likely. For any unseen x and any prediction ŷ, exactly half of the completions have f(x) = ŷ. So the expected accuracy at x is 1/2, and the off-training-set average is 1/2 for every learner. ∎

Gains are paid for

Pair each target f with fˉ\bar f, which agrees with f on T and is flipped off T. Both give the learner the same training data, hence the same predictions, so acc(f)+acc(fˉ)=1\text{acc}(f) + \text{acc}(\bar f) = 1. Any target where a learner beats 50% has a twin where it does equally worse. ∎

Optimization NFL (sketch)

Condition on the values seen so far. For a uniformly random f, the value at any unvisited point is uniform and independent of the history, whichever point the algorithm picks. By induction, the sequence of observed values has the same distribution for every non-revisiting algorithm. ∎

📝 Quick check (Level 3)
0/3 answered
  1. 1. The 'twin target' argument pairs f with a target that…
  2. 2. Binary targets on 20 inputs consistent with 15 seen labels:
  3. 3. In optimization NFL, the next value observed is uniform because…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Exhaustive verification and the role of structure

Learning. Over all 256 targets, every learner scores exactly 0.500 off-training-set: always-0, majority, 1-NN, and anti-1-NN alike. Over the 16 smooth targets: 1-NN 0.875, majority 0.719, always-0 0.500 and anti-1-NN 0.125. (1-NN and its anti-version always sum to 1.)

Search. Over all 6561 functions, the mean best-so-far curves of the sweep, random-order, hill-climbing and anti-hill-climbing searches are identical to machine precision. After 4 evaluations:

problem class hill climbing anti-hill sweep
broad unimodal (787 functions) 1.607 1.668 1.582
smooth single peak (256 functions) 1.547 1.461 1.484

Neither search is better in general. Which one wins depends on the problem’s shape. Algorithm benchmarks (optimizers, neural architectures, RL methods) therefore only make sense relative to a problem distribution.

🐍 Exercise 2 (research): No Free Lunch for search
Enumerate all 6561 functions from 8 points to 3 values and run four non-revisiting search strategies. Verify that their average best-so-far curves are identical, then restrict to two structured problem classes and show that the ranking appears, and flips, depending on the structure.

No Free Lunch in AI, robotics and aerospace

  • Architecture design: CNNs (translation), graph networks (permutation), equivariant networks (a12-3) build in known symmetries.
  • Physics-informed learning: conservation laws (a13-11, a13-12) as inductive bias for data-poor dynamics.
  • Bayesian methods: priors make the inductive bias explicit (a5-2-1); Gaussian-process kernels encode smoothness.
  • Benchmarking: evaluate optimizers and learners on distributions that match the deployment domain (terrain, missions), not on arbitrary test suites.

References

  1. D. Wolpert (1996). “The lack of a priori distinctions between learning algorithms.” Neural Computation, 8.
  2. D. Wolpert, W. Macready (1997). “No free lunch theorems for optimization.” IEEE Transactions on Evolutionary Computation, 1.
  3. S. Shalev-Shwartz, S. Ben-David (2014). Understanding Machine Learning, ch. 5. Cambridge.
  4. T. Mitchell (1980). “The need for biases in learning generalizations.” Rutgers CBM-TR-117.
  5. C. Schaffer (1994). “A conservation law for generalization performance.” ICML.