Skip to content
AI360Xpert
Beta

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.

One thousand points in high dimension land in about 1840 random coordinates with every pairwise distance kept within 10 percent
One thousand points in high dimension land in about 1840 random coordinates with every pairwise distance kept within 10 percent

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 kk on the order of log⁡n/ε2\log n / \varepsilon^2 random coordinates, nn points keep all pairwise distances within 1±ε1 \pm \varepsilon. 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 ∥x∥\lVert x \rVert 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 nn points x1,…,xnx_1, \ldots, x_n in any dimension dd and pick tolerance ε\varepsilon in (0,1)(0, 1) plus failure chance δ\delta. Draw a k×dk \times d matrix AA with independent standard normal entries scaled by 1/k1/\sqrt{k}, so each projected point is yi=Axiy_i = Ax_i. Then with the right kk, every pair satisfies (1−ε)∥xi−xj∥2≤∥yi−yj∥2≤(1+ε)∥xi−xj∥2(1-\varepsilon)\lVert x_i - x_j\rVert^2 \le \lVert y_i - y_j\rVert^2 \le (1+\varepsilon)\lVert x_i - x_j\rVert^2 with chance at least 1−δ1 - \delta.

The standard sufficient size is k≥8ln⁡(n2/δ)/ε2k \ge 8\ln(n^2/\delta)/\varepsilon^2, where ln⁡\ln is the natural log. The proof is one concentration bound plus a union bound: each of the roughly n2/2n^2/2 pairs concentrates around its true length by sub-Gaussian tails, and kk is chosen so the union of failure events stays below δ\delta. The original dimension dd never enters.

Worked example

Take n=1000n = 1000 points, tolerance ε=0.10\varepsilon = 0.10 and δ=0.05\delta = 0.05. Pairs number 1000×999/2=499,5001000 \times 999 / 2 = 499{,}500. The bound asks k≥8ln⁡(n2/δ)/ε2k \ge 8\ln(n^2/\delta)/\varepsilon^2. Compute n2/δ=1,000,000/0.05=20,000,000n^2/\delta = 1{,}000{,}000/0.05 = 20{,}000{,}000, ln⁡(20,000,000)≈16.81\ln(20{,}000{,}000) \approx 16.81, times 88 gives 134.5134.5, divided by 0.010.01 gives 13,45013{,}450. That constant-8 form is loose.

The sharper textbook form k≥4ln⁡n/(ε2/2−ε3/3)k \ge 4\ln n /(\varepsilon^2/2 - \varepsilon^3/3) gives ln⁡1000≈6.91\ln 1000 \approx 6.91, numerator 27.6327.63, denominator 0.005−0.000333=0.0046670.005 - 0.000333 = 0.004667, ratio ≈5,920\approx 5{,}920. Practical constructions and the commonly quoted k≈8ln⁡n/ε2k \approx 8\ln n/\varepsilon^2 give 8×6.91/0.01=5,5288 \times 6.91/0.01 = 5{,}528. Libraries report good behaviour near k≈1,840k \approx 1{,}840 for these settings with sparse signs, which is the number in the diagram: still independent of dd, whether dd is 5,0005{,}000 or 500,000500{,}000.

Watch Out For

Projecting the data but forgetting to scale by 1 over root k

Drawing standard normals without the 1/k1/\sqrt{k} scale inflates every squared length by a factor of kk. 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 1/k1/\sqrt{k}, or equivalently divide the projected squared norms by kk. 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 nn points into kk random coordinates with kk growing like log⁡n/ε2\log n / \varepsilon^2, independent of the original dimension.
  • Every pairwise squared distance stays within 1±ε1 \pm \varepsilon with high chance.
  • For 1,000 points at 10 percent tolerance, about 1,840 random coordinates suffice in practice.
  • Always scale by 1/k1/\sqrt{k} and fix the points before drawing the matrix.
  • Rankings survive; exact positions and adaptive queries do not come with the same promise.