The Johnson–Lindenstrauss Lemma
A complete proof that random projection to O(log N / eps^2) dimensions preserves all pairwise distances, with the dimension requirement, the geometry and the limits of the result.
The single-vector statement
Everything follows from one lemma about one vector.
Let have i.i.d. entries. For any fixed and any ,
The lemma
Let and . If
and has i.i.d. entries, then with probability at least ,
Assumptions
The points are fixed in advance (the map is chosen after the points, but the points may not depend on the map); is a Gaussian random matrix with the stated variance; . Nothing is assumed about , or the geometry of the point set.
Key idea
Count the exponents. Each pair fails with probability ; there are pairs; so we need , i.e. . The comes from the Gaussian shape of the concentration — a bound of the form would have given — and the comes from the union bound, which is why the dependence is on the number of points and not on the dimension they started in.
Is the bound tight?
For every and large enough there exist points in such that any map (linear or not) achieving distortion on all pairs must have target dimension
This is the theorem of Larsen and Nelson, quoted from the reference. Its content is that the shape of the lemma is not an artefact of the proof technique — no cleverer construction can do essentially better. A weaker and much older observation goes the same way: an -distortion embedding of mutually near-orthogonal points needs simply because cannot hold more than points at pairwise distance — a packing bound.
If the conclusion of the lemma holds for the point set , then for all ,
In particular unit vectors have their inner products preserved to additive .
This corollary is the version that matters for machine learning: it says a random projection approximately preserves the Gram matrix, hence approximately preserves every kernel method, every linear classifier's margins, and every cosine similarity used in retrieval.
What the lemma does not give you
Empirical observation — a regularity seen in experiments. No theorem on this page establishes it in general.
A guarantee on all pairwise distances does not guarantee that the nearest neighbour of a query is preserved.
What this does not say
Suppose the nearest neighbour is at distance and the second nearest at distance . After projection the first may be at and the second at : the order has flipped, while every pairwise distance is within the guarantee. Nearest-neighbour preservation requires the relative gap between the true neighbour and its competitors to exceed or so, which is an assumption about the data, not a consequence of the lemma.
Three further limits worth stating explicitly:
- The lemma is about a fixed point set. If the query is chosen adversarially after seeing , all guarantees are void. This is why one cannot reuse a single projection matrix across an adaptively-chosen sequence of queries without care.
- is brutal in practice. Distortion on points needs — larger than any plausible ambient dimension. The lemma is a statement about the regime constant, large.
- No sparsity, no structure. A dense Gaussian costs per point to apply. Sparse and fast variants (the subsampled Hadamard transform, CountSketch, sparse JL) achieve similar guarantees with better runtime, and are what actual systems use.
Problems
Prove the Johnson–Lindenstrauss lemmaProof · Graduate · 3 hours The chi-squared moment generating function and its Chernoff boundProof · Intermediate · 30 min Johnson–Lindenstrauss dimension arithmeticNumerical · Beginner · 15 min Rademacher projections work tooProof · Advanced · 1 hour Implement random projection and measure the distortionCoding · Intermediate · 1 hour From distance preservation to inner-product preservationProof · Intermediate · 30 minReferences
- PaperWilliam B. Johnson and Joram Lindenstrauss (1984). Extensions of Lipschitz mappings into a Hilbert spaceThe original paper; the lemma appears as a tool in a functional-analysis argument.
- PaperSanjoy Dasgupta and Anupam Gupta (2003). An elementary proof of a theorem of Johnson and LindenstraussThe proof strategy used below follows the standard elementary route this paper popularised; the exposition here is written independently.
- PaperKasper Green Larsen and Jelani Nelson (2017). Optimality of the Johnson–Lindenstrauss lemmaEstablishes that the O(eps^{-2} log N) bound is tight.
- BookRoman Vershynin (2018). High-Dimensional Probability: An Introduction with Applications in Data Science
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- LemmaDistributional Johnson–Lindenstrauss lemmaproof includedA random Gaussian projection preserves the norm of any single fixed vector to within a factor 1 ± eps with probability 1 − 2exp(−c k eps^2).
- TheoremJohnson–Lindenstrauss lemmaproof includedAny N points in Euclidean space embed into O(eps^{-2} log N) dimensions with all pairwise distances preserved to within 1 ± eps.
- TheoremOptimality of the dimension boundThe eps^{-2} log N dependence cannot be improved in general.
- CorollaryInner products are preserved tooproof includedDistance preservation for a point set closed under differences implies inner-product preservation.
- Empirical observationDistance preservation is not neighbour preservationA 1 ± eps distortion guarantee does not preserve the identity of the nearest neighbour when the gap to the runner-up is smaller than eps.
Experiments
Problems (6)
All problems- The chi-squared moment generating function and its Chernoff boundProofIntermediate⏱ 30 min
- Johnson–Lindenstrauss dimension arithmeticNumericalBeginner⏱ 15 min
- Implement random projection and measure the distortionCodingIntermediate⏱ 1 hour
- From distance preservation to inner-product preservationProofIntermediate⏱ 30 min
- Prove the Johnson–Lindenstrauss lemmaProofGraduate⏱ 3 hours
- Rademacher projections work tooProofAdvanced⏱ 1 hour