The Johnson-Lindenstrauss lemma

Randomized approximate distance guarantees

2026-11-18

The Johnson-Lindenstrauss lemma

Fix x_1,\ldots,x_n\in\mathbb R^d and \varepsilon,\delta\in (0,1). Draw G\in\mathbb R^{k\times d} with independent N(0,1) entries and set f(x)=Gx/\sqrt{k}. If k\geq\frac8{\varepsilon^2}\left(2\log n+\log\frac1\delta\right), then with probability at least 1-\delta, simultaneously for every pair i<j, \boxed{(1-\varepsilon)\|x_i-x_j\|^2 \leq\|f(x_i)-f(x_j)\|^2 \leq(1+\varepsilon)\|x_i-x_j\|^2.}

The bound for k is independent of d!

The proof is already in our hands

We did the main body of work in the previous concentration slides. Conceptually, there were two steps. For each fixed u\neq0, \frac{\|f(u)\|^2}{\|u\|^2} \overset{d}{=}\frac1k\sum_{r=1}^kg_r^2, \qquad g_r\overset{\mathrm{iid}}{\sim}N(0,1), so concentration for sums of squared Gaussians gives tail bound of at most 2e^{-k\varepsilon^2/8}.

Apply this to u=x_i-x_j and take a union bound: \Pr(\text{some pair fails}) \leq\binom n2\,2e^{-k\varepsilon^2/8} \leq n^2e^{-k\varepsilon^2/8}\leq\delta.

Documents as word vectors

Discussion posts from 20 Newsgroups.

  • n=300 posts
  • d=130107 vocabulary words

Word counts c_i \rightarrow unit vectors x_i=c_i/\|c_i\|.

Can we preserve distances in fewer coordinates?

Similar words, nearby vectors

Six example coordinates: telescope, satellite, orbit, team, goal, match.

Post Counts c_i Normalized x_i
A: A telescope tracks a satellite in orbit. (1,1,1,0,0,0) \frac{1}{\sqrt3}(1,1,1,0,0,0)
B: A satellite enters orbit. (0,1,1,0,0,0) \frac{1}{\sqrt2}(0,1,1,0,0,0)
C: The team scores a goal in a match. (0,0,0,1,1,1) \frac{1}{\sqrt3}(0,0,0,1,1,1)

Normalized squared distances: \|x_A-x_B\|^2\approx0.37, \qquad \|x_A-x_C\|^2=\|x_B-x_C\|^2=2.

Space posts are closer together.

Compress the document vectors

One Gaussian map for all 300 posts: \underbrace{X}_{300\times130107}\; \underbrace{G^\top/\sqrt{k}}_{130107\times k} =\underbrace{Y}_{300\times k}.

Are the distances preserved?

Each dot is one pair of posts.

Four scatter plots of all document pairs' original and projected squared distances, at 64, 256, 1024, and 2048 dimensions; the points approach the diagonal as dimension increases.

Do nearby posts stay nearby?

Fix k=2048 and find each post’s ten nearest neighbors in the original space (among these 300 posts).

Original versus projected squared distances for pairs selected as original ten-nearest neighbors, using 2048 projection dimensions, with a diagonal and a band marking ten percent relative error.

Among these nearby pairs, 99.7% have squared-distance error at most 10%; the worst error is 11.2%.

Do we find the same neighbors?

Search again in the 2048-dimensional space. For each post, count how many of its original ten nearest neighbors are still in the projected top ten.

Bar chart counting posts by how many of their original ten nearest neighbors remain in the projected top ten at 2048 dimensions.

Small distance errors can reorder nearly tied neighbors.