Johnson-Lindenstrauss Lemma
Random projections squash high-dimensional points into few dimensions while barely distorting distances. A few hundred random coordinates preserve the geometry of thousands of points.
Why Does This Exist?
Nearest neighbours, clustering and retrieval all depend on distances, and distances in 50,000 dimensions are expensive. The hope is that far fewer coordinates suffice, but PCA needs a full eigendecomposition and a data-dependent basis. What you want is a dimension reduction that is oblivious: draw one random matrix, apply it to every point, and keep the geometry with high chance.
The Johnson-Lindenstrauss lemma says that matrix exists and randomness finds it. With on the order of random coordinates, points keep all pairwise distances within . The target dimension depends on the number of points and the tolerance, not on the original dimension. That logarithmic dependence is the surprise that powers sketching, fast approximate search and compressed features.
Prerequisite in one paragraph. You need norms and projections: the length measures size and a projection drops a vector onto fewer coordinates. A Gaussian entry has mean zero and unit variance. Refreshers are in norms and orthogonality and projections.
Think of It Like This
Shadows of a mobile on three walls
A hanging mobile has beads at many positions in 3D. Its shadow on one wall collapses depth, and two beads can overlap. But look at shadows on three walls at odd angles and the full layout is recoverable: beads far apart in space are far apart in almost every shadow.
Random projection is many such shadows at once. Each random coordinate is one viewing angle. One angle can lie, but with enough independent angles every pair of points is honestly represented in the typical view. The lemma counts how many walls you need.
Where the analogy stops: shadows are two-dimensional and hand-picked. JL projections are one-dimensional each, fully random, and the guarantee is about relative distances, not exact positions.
How It Actually Works
Fix points in any dimension and pick tolerance in plus failure chance . Draw a matrix with independent standard normal entries scaled by , so each projected point is . Then with the right , every pair satisfies with chance at least .
The standard sufficient size is , where is the natural log. The proof is one concentration bound plus a union bound: each of the roughly pairs concentrates around its true length by sub-Gaussian tails, and is chosen so the union of failure events stays below . The original dimension never enters.
Worked example
Take points, tolerance and . Pairs number . The bound asks . Compute , , times gives , divided by gives . That constant-8 form is loose.
The sharper textbook form gives , numerator , denominator , ratio . Practical constructions and the commonly quoted give . Libraries report good behaviour near for these settings with sparse signs, which is the number in the diagram: still independent of , whether is or .
Watch Out For
Projecting the data but forgetting to scale by 1 over root k
Drawing standard normals without the scale inflates every squared length by a factor of . Distances look preserved up to a global scale, so a downstream threshold or radius check silently breaks while relative rankings look fine.
Fix: scale the matrix by , or equivalently divide the projected squared norms by . Check one known distance end to end before trusting the sketch.
Reusing one projection across adaptively chosen queries
The lemma fixes the points before drawing the matrix. If queries adapt to the sketch, for example by following up on neighbours the sketch returned, the union bound no longer covers the new points and distances can distort badly.
Fix: freeze the point set the guarantee covers, or redraw and pay fresh randomness for adaptive rounds. For live query streams use a method with an adaptive guarantee.
The Quick Version
- JL projects points into random coordinates with growing like , independent of the original dimension.
- Every pairwise squared distance stays within with high chance.
- For 1,000 points at 10 percent tolerance, about 1,840 random coordinates suffice in practice.
- Always scale by and fix the points before drawing the matrix.
- Rankings survive; exact positions and adaptive queries do not come with the same promise.