A Tutorial Introduction to the Minimum Description Length Principle
Learning is compression. The model that lets you describe the data in the fewest bits, counting the bits for the model itself, is the one to trust.
Start here (no maths needed)
The best explanation of some data is the one that lets you write the data down in the fewest bits, counting the explanation itself.
Think of it like this
Think of zipping files on a computer. A file that says "ABABABAB…" a thousand times zips down to almost nothing, because the zip program spots the pattern. A file of random letters hardly shrinks at all. So how much a file shrinks tells you how much pattern is in it. MDL says: finding patterns is learning. But you must also count the size of the rule you used, or you could cheat with a giant rule that just lists every answer.
How it works
- You have some data, like dots on a graph, and several possible explanations, like a straight line or a wiggly curve.
- For each explanation, count the bits needed to describe the explanation itself.
- Then count the bits needed to describe the data's mistakes, given that explanation.
- Add the two numbers together.
- Pick the explanation with the smallest total. A wiggly curve fits better, but it costs more bits to describe.
Why robots care
A robot learning how its own arm moves has to pick a model: a simple one, or a complicated one with lots of extra terms. Too simple, and it misses real effects like friction. Too complicated, and it learns the random wobble in its sensors. MDL gives a fair way to choose.
Try it
- Write down the sequence 2, 4, 6, 8, … up to 100. Now describe it to a friend in as few words as possible ("even numbers up to 100"). Then try the same with 10 dice rolls. You can't shrink the dice rolls, because there is no pattern.
- In the demo further down, move the Noise level slider right and the Data points n slider left. Watch the highlighted bar: with noisy, small data, MDL picks a simpler curve. Training error alone always picks the most wiggly one.
Words to know
- Compress
- Make data take up fewer bits by using its patterns, like a zip file.
- Model
- An explanation or rule for the data.
- Overfitting
- Choosing an over-complicated explanation that fits random noise.
- Code length
- The number of bits used to write something down.
Going deeper: everything below is the full version, with some maths. On a first read, skim the headings and the "Why it matters for robotics" box, and come back for the rest later.
1. Summary
TL;DR
Grünwald's tutorial is the standard introduction to Rissanen's Minimum Description Length principle. Any regularity in data can be used to compress it, so the more you can compress, the more you have learned. Chapter 1 is a non-technical tour. Chapter 2 makes it precise: code lengths are log-probabilities, crude MDL adds model bits to data bits, and refined MDL replaces hand-made model codes with a single, provably good code per model family (normalised maximum likelihood). It ties MDL to Bayes, to cross-validation-like prediction, and to Kolmogorov complexity.
- Codes = probabilities. The Kraft inequality means every prefix code corresponds to a distribution, with length
−log₂ P(x). - Crude MDL: pick the hypothesis H minimising
L(H) + L(D|H). Overfitting is penalised automatically. - Refined MDL: pick the model with the shortest NML code length. Model cost becomes "parametric complexity": roughly, how many distinguishable distributions the model contains.
- Four readings of refined MDL: compression, counting, Bayesian, and prequential (sequential prediction).
- No true model needed. MDL makes sense even when every candidate model is wrong, which in practice they all are.
2. The core idea
Crude, two-part MDL for a set of hypotheses:
H* = argmin_H [ L(H) + L(D | H) ]
L(D | H) = −log₂ P(D | H) # bits to code the data with H's help
L(H) ≈ (k/2) · log₂ n # k parameters at optimal precision, n data points
L(D | H)is the misfit. A better fit means fewer bits for the data.L(H)is the cost of stating the hypothesis. Each parameter only needs about½ log₂ nbits, because with n points you can't pin it down finer than about1/√n. This is where the BIC-style penalty comes from.
The trouble is that L(H) depends on an arbitrary choice of code. Refined MDL fixes that with one code per model family M:
P_nml(D | M) = P(D | θ̂(D)) / Σ_{D'} P(D' | θ̂(D'))
−log P_nml(D | M) = −log P(D | θ̂(D)) + COMP_n(M)
COMP_n(M) ≈ (k/2) log(n / 2π) + log ∫ √det I(θ) dθ
θ̂(D)is the maximum-likelihood fit to the data you actually saw.- The denominator sums the best-fit likelihood over every data set the model could have seen. A flexible model fits everything well, so its denominator is large and it pays more.
COMP_n, the parametric complexity, is the log of that sum. It grows with the number of parameters k, but the second term, with the Fisher informationI(θ), also captures how the model's functional form shapes its flexibility. Two models with the same k can have different complexity.
3. Deep dive
Watching MDL choose a polynomial
Grünwald's running example is choosing the degree of a polynomial. Training error alone always prefers the highest degree. Add the cost of the parameters and the minimum lands near the truth.
Interactive: crude two-part MDL for polynomial degree
Data from a cubic plus Gaussian noise (seeded). Right: bits per degree, model L(H) stacked on data L(D|H) (relative to the best fit). The chosen degree has the shortest total. Left: the data and the chosen fit.
Two things to notice. With heavy noise and few points, MDL settles for a simpler model than the truth: the data don't justify the extra parameters, and that's the right call. Training error, meanwhile, always picks degree 8. One caution: the (k/2) log n penalty is an approximation that is only reliable for large n, and it treats every parameter as equally costly. Those small-sample and same-k weaknesses are Grünwald's reasons for refined MDL.
Four ways to read the same number
- Compression: NML gives every distribution in the model equal treatment. Its regret (extra bits over the best fit in hindsight) is the same for every data set.
- Counting:
COMP_nis roughly the log of the number of distributions in the model that data of size n can tell apart. - Bayesian: with Jeffreys' prior, the Bayesian marginal likelihood matches the NML code length to leading order. MDL and Bayes often agree, for different reasons.
- Prequential: predict each point from the ones before, and add up
−log P(x_i | x_1…x_{i−1}). That sum is a valid code length. It is model selection by honest out-of-sample prediction, a close cousin of cross-validation.
Links across the course
- A language model's cross-entropy is literally the code length of the text in bits. Training on next-token loss, as in Day 01, is compression.
- Day 04 applied MDL to the weights of a network. Day 26 covers the ideal, uncomputable version: Kolmogorov complexity.
- The prequential view is also how you should evaluate a model that learns online: score each prediction before it trains on that point. Compare Module 01's tuning without fooling yourself.
Limits Grünwald admits
For many models COMP_n is infinite (the Gaussian with unbounded mean, for example) and needs patching. NML is often hard to compute, so practice falls back on approximations. And MDL's Occam's razor is a claim about codes, not about the world: a short description is a good bet for prediction, not proof that nature is simple.
4. Why it matters for robotics
- System identification. Choosing the order of a dynamics model, the number of friction terms, or how many modes a contact model needs is model selection. MDL gives a principled stopping rule when you can't afford a big held-out set.
- World models are compressors. A model that predicts the next sensor reading well can encode the sensor log in fewer bits. Prequential log-loss is a clean, single number for comparing learned dynamics models.
- Segmenting demonstrations. Splitting a long demonstration into skills is a trade-off between describing many short primitives and one long messy one. Two-part code lengths give a natural way to frame that choice.
- Honest scale note: modern deep robot policies are not chosen by computing NML. The value here is the mindset: always count the cost of the model, not just the fit.
5. How to study it
- Read Chapter 1 in one sitting (about 20 pages, no maths). Then read Chapter 2 Sections 2.2–2.6 slowly, with paper.
- Prove the easy direction of the Kraft inequality yourself for a small code like {0, 10, 110, 111}.
- In the 30u30 Day 5 folder, run
train_minimal.pyand readimplementation.pyto see two-part, prequential and NML code lengths computed side by side. - Do the exercises in order: two-part code, prequential coding, model selection, NML complexity, and MDL vs AIC/BIC.
- Stretch: compute the NML complexity of the Bernoulli model exactly for n = 10, 100, 1000 and compare it with
½ log₂ n.
6. Self-check
Why can code lengths be treated as probabilities?
By the Kraft inequality, the lengths of any prefix code satisfy Σ 2^(−L(x)) ≤ 1, so 2^(−L(x)) behaves like a probability. Conversely, any distribution gives a code with lengths of about −log₂ P(x).
Why does crude MDL charge about ½ log₂ n bits per parameter?
With n data points a parameter can only be estimated to a precision of about 1/√n. Stating it more precisely buys nothing, and stating it to that precision costs about ½ log₂ n bits.
What does the NML denominator measure?
How well the model can fit all possible data sets of size n. Flexible models fit many data sets well, so they get a large denominator and pay a higher complexity.
What is the prequential interpretation?
Code each point using a model fitted only to earlier points. The total log-loss is a code length, so model selection becomes "which model predicted the sequence best, step by step".
Does MDL assume one of the models is true?
No. It picks the model that compresses the data best, which is meaningful even when all candidates are wrong.
7. Further reading
- The original tutorial, and Grünwald's book The Minimum Description Length Principle (MIT Press, 2007) for the full treatment
- 30u30 Day 5: implementation, notebook, cheatsheet, exercises
- Next: Day 06, The First Law of Complexodynamics