Random Projections & Johnson–Lindenstrauss
Why random directions preserve distances.
Multiply your data by a matrix of random numbers and every pairwise distance survives, nearly unchanged. The Johnson–Lindenstrauss lemma says how few dimensions this needs, about , whatever the original dimension. This lesson proves it, makes the projection sparse and fast, shows that the bound cannot be beaten, and puts random sketches to work in least squares, low-rank approximation, clustering and sparse recovery.
What you’ll learn
- State the Johnson–Lindenstrauss lemma in its distributional and -point forms, and prove it for Gaussian matrices with explicit constants from a Chernoff bound for .
- Explain why sparse sign matrices and the fast Johnson–Lindenstrauss transform work, and what each costs per vector.
- State the lower bound that makes optimal, and connect it to families of nearly orthogonal vectors.
- Use subspace embeddings to sketch least squares, and relate random projections to randomized SVD, -means and compressed sensing through Gordon's set-dependent bound.
The lemma: dimension without d
Take points in , with perhaps in the millions. A random projection maps them to by a matrix drawn without looking at the data. The Johnson–Lindenstrauss lemma says that every one of the distances survives within a factor once is of order . The ambient dimension does not appear at all. Johnson & Lindenstrauss (1984) proved it with a random orthogonal projection, on the way to a theorem about extending Lipschitz maps. Indyk & Motwani (1998) showed that a matrix of independent Gaussians works too, and Dasgupta & Gupta (2003) gave an elementary proof with explicit constants; the Gaussian version below is the cleanest.
Using the bound above, how many dimensions guarantee that all pairwise squared distances among points stay within () with probability at least 99% ()?
Show the answer
13816 dimensions
and , while , so , whether is or . Without the term, the bound is what scikit-learn's johnson_lindenstrauss_min_dim uses; there the union bound only guarantees success with probability at least , which is still enough to show that a good map exists.
| 0.5 | 0.2 | 0.1 | 0.05 | 0.01 | |
|---|---|---|---|---|---|
| for , | 774 | 3,720 | 13,816 | 53,357 | about 1.3 million |
The proof: concentration of a chi-squared variable
Fix . Each coordinate of is , independently, so the normalized squared length is a sum of independent squared standard Gaussians: a variable with mean . The proof is a concentration inequality for it.
Upper tail. Markov's inequality applied to , minimized at , gives
Use for (the difference vanishes at 0 and has derivative ):
Lower tail. The same argument with , minimized at , and give a bound at least as strong:
All pairs. The map is linear, , so apply the distributional bound to the difference vectors and take a union bound. The failure probability is below under the stated condition on :
Nothing in the proof needs Gaussians beyond the tail bound. Any matrix with independent, mean-zero, unit-variance sub-Gaussian entries (tails at least as light as a Gaussian's) satisfies the distributional form with different constants (Matoušek, 2008), and so does a uniformly random orthogonal projection, scaled by , the original construction. Achlioptas (2003) proved exactly the bound above, with , for two "database-friendly" choices: random signs , and the sparse distribution with probabilities , which skips two thirds of the work and needs only additions. Indyk & Motwani (1998) used random projections to make approximate nearest-neighbor search fast in high dimension.
Faster, sparser, and no better possible
A dense projection costs operations per vector, about in the example above. Making the matrix sparse helps, but taken too far it fails on sparse inputs: if , only the few nonzeros in the first column of the matrix see it, and their number does not concentrate. The fix is to precondition. The fast Johnson–Lindenstrauss transform of Ailon & Chazelle (2009) is : flips the sign of each coordinate at random, is the normalized Walsh–Hadamard matrix, applied in time like an FFT, and is a sparse random projection. is orthogonal, so it preserves lengths, and it spreads every vector's mass over all coordinates: each coordinate of is a random-sign sum, and Hoeffding's inequality with a union bound gives with probability . On such flat vectors the sparse concentrates well, and the whole map takes time per vector, against for a dense projection.
Sparsity can also be designed in. Kane & Nelson (2014), improving on Dasgupta, Kumar & Sarlós (2010), built matrices with the optimal rows in which only an fraction of each column is nonzero. At the extreme, CountSketch puts a single random sign in each column: too weak for the -point lemma with logarithmically many rows, but strong enough for the subspace embeddings of the next step.
A random matrix has independent entries that are nonzero with a small probability , scaled to have unit variance, and no preconditioning. For which inputs is least reliably preserved?
- Dense vectors with all coordinates of similar size
- Vectors with a very large norm
- Vectors orthogonal to the all-ones vector
- Sparse vectors such as , which only the few nonzeros of one column ever see
Show the answer
D. Sparse vectors such as , which only the few nonzeros of one column ever see
For , the output is the first column, whose squared norm is a scaled count of about nonzeros: unless is large, that count fluctuates wildly. Dense vectors average over many independent entries and concentrate. The randomized Hadamard step of the fast transform turns every input into a dense one before the sparse projection.
Where does come from? Apply a JL map to the points . The images satisfy and , so by polarization : nearly orthogonal vectors in dimensions. High-dimensional space holds exponentially many nearly orthogonal directions, about , and Alon's lower bound is essentially the converse: up to a factor in the exponent, it holds no more.
The phenomenon is special to Euclidean geometry. In there are -point sets for which any embedding with distortion needs dimensions (Brinkman & Charikar, 2005).
Sketching: least squares, low rank, clustering, sparse recovery
Solve the least-squares problem with , . Every residual lies in , of dimension at most . Let be an -subspace embedding for , and compare the small sketched problem with the original:
Chain the embedding inequalities through the optimality of for the sketched problem:
So the sketched solution's residual is within a factor about of optimal, from a problem with rows instead of . The guarantee is on the residual: by Pythagoras , which bounds only through the conditioning of .
A Gaussian sketch costs to apply, more than the of solving directly, so sketching pays with fast sketches: Hadamard-based transforms (Sarlós, 2006) or CountSketch, applied in time proportional to the number of nonzeros of (Clarkson & Woodruff, 2013). Woodruff (2014) surveys the field. The same idea runs through other algorithms:
- Randomized SVD. The Gaussian test matrix of Halko, Martinsson & Tropp (2011) is a sketch: captures the dominant column space of (its error bound is in Linear Algebra for ML: Eigenvectors & the SVD).
- Clustering. Projecting to dimensions preserves the cost of every k-means clustering within (Makarychev, Makarychev & Razenshteyn, 2019): the dimension depends on the number of clusters, not on .
- Compressed sensing. The distributional lemma plus a union bound over all -sparse supports shows that a Gaussian matrix with of order has the restricted isometry property of order (Baraniuk, Davenport, DeVore & Wakin, 2008), which compressed sensing needs (Sparse Recovery Guarantees).
Key takeaways
- Johnson–Lindenstrauss: a Gaussian matrix with rows, scaled by , keeps all squared distances within with probability , independently of ; for , , that is about 13,800.
- The proof is a Chernoff bound for , , plus a union bound over the difference vectors; any sub-Gaussian entries work, including Achlioptas's sparse matrices.
- The fast JL transform flattens every vector with a randomized Hadamard transform so that a sparse projection works, in about time per vector; sparse JL matrices need only an fraction of nonzeros per column.
- is optimal for any map (Larsen & Nelson), mirroring the roughly nearly orthogonal directions that fit in ; nothing similar holds in .
- Subspace embeddings with rows give near-optimal least squares from a small problem; random projections also drive randomized SVD, -means reduction to dimensions and the restricted isometry property, all instances of Gordon's bound .
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
With , the JL bound is . If points need at some , about how many dimensions do points need at the same ?
- About 2,000: does not depend on
- About 4,000
- About 20,000
- About 20 million
Show the answer
B. About 4,000
is proportional to , and , so doubles. Ten thousand times more points cost only twice the dimension, and the original dimension never enters.
For fixed and , you tighten the distortion from to . By about what factor does the bound on grow?
- About 2
- About 8
- It does not change
- About 4
Show the answer
D. About 4
The denominator behaves like for small , so halving multiplies by about 4; for and the exact values are 13,816 and 53,357, a factor 3.86. Precision, not the number of points, is what makes random projections expensive.
You solve least squares on the sketch , where is an -subspace embedding for the column space of . What is guaranteed about the solution ?
- exactly
- , whatever is
- Its residual is within a factor of the optimal residual
- Nothing, unless has Gaussian entries
Show the answer
C. Its residual is within a factor of the optimal residual
Every residual lies in the embedded subspace, so . The argument only uses the embedding property, which fast and sparse sketches also provide.
Could a cleverly designed nonlinear map embed every set of points from a high-dimensional space into far fewer than dimensions, keeping squared distances within ?
- Yes: nonlinear maps are strictly more powerful than linear ones
- No: some point sets need dimensions for any map, linear or not
- Yes, provided the map is chosen after seeing the points
- No, but only because random matrices cannot be derandomized
Show the answer
B. No: some point sets need dimensions for any map, linear or not
Larsen & Nelson (2017) exhibit -point sets for which every embedding into has , for above . The oblivious random linear map is optimal up to a constant.
Further reading
- W. B. Johnson & J. Lindenstrauss, "Extensions of Lipschitz mappings into a Hilbert space," Contemporary Mathematics 26, 189–206 (1984).
- S. Dasgupta & A. Gupta, "An elementary proof of a theorem of Johnson and Lindenstrauss," Random Structures & Algorithms 22(1), 60–65 (2003).
- N. Ailon & B. Chazelle, "The fast Johnson–Lindenstrauss transform and approximate nearest neighbors," SIAM Journal on Computing 39(1), 302–322 (2009).
- K. G. Larsen & J. Nelson, "Optimality of the Johnson–Lindenstrauss lemma," Proceedings of the 58th IEEE Symposium on Foundations of Computer Science (FOCS), 633–638 (2017).
- D. P. Woodruff, "Sketching as a tool for numerical linear algebra," Foundations and Trends in Theoretical Computer Science 10(1–2), 1–157 (2014).