Random Projections That Preserve Distance
Imagine photographing a three-dimensional sculpture. One photograph loses depth, yet several carefully chosen views preserve enough geometry to compare shapes. A random projection applies the same idea to data in (\mathbb R^d): it maps every vector to (\mathbb R^m), with (m\ll d), while approximately preserving the distances among a finite collection of points.
For a linear map (A\in\mathbb R^{m\times d}), the desired event for points (x_1,\ldots,x_N) is \[ (1-\varepsilon)\lVert x_i-x_j\rVert_2^2 \le \lVert A(x_i-x_j)\rVert_2^2 \le (1+\varepsilon)\lVert x_i-x_j\rVert_2^2 \] for every pair. The Johnson–Lindenstrauss lemma says a random map can achieve this with (m=O(\varepsilon^{-2}\log N)). The original dimension (d) does not appear in the target dimension bound.
For a tiny example, take (u=(1,0,1,0)), (v=(0,1,0,1)), so (u-v=(1,-1,1,-1)) and (\lVert u-v\rVert_2^2=4). If a particular projection gives (A(u-v)=(1.2,-1.5)), its squared norm is (3.69), a relative distortion of (-7.75\%\). This one calculation verifies one pair for one realized map; it does not prove that every pair or future point is preserved.
Concentration says a random quantity stays near its mean. With a Gaussian map (A_{rj}\sim N(0,1/m)), (\lVert Ax\rVert_2^2/\lVert x\rVert_2^2) is a normalized chi-square variable for fixed (x). A sub-Gaussian map replaces Gaussian entries with other light-tailed variables such as scaled random signs. An epsilon net is a finite cover used to extend guarantees from finitely many directions to every direction in a subspace. A sparse embedding gives each input column few nonzeros, reducing multiplication work. Feature hashing is the extreme one-nonzero-per-column version. An FJLT first randomizes and spreads energy with a fast orthogonal transform, then samples or projects to fewer coordinates.
This deep dive supplies what a dimensionality-reduction overview usually omits: the fixed-vector tail bound, the all-pairs union bound, and the reasons a faster sparse transform needs more careful parameter choices than a dense Gaussian proof.
A JL map preserves the geometry of a fixed finite data set with high probability, not every vector in all of $\mathbb R^d$ when the target dimension is smaller than the source dimension. Randomness, scaling, the number of protected points, and whether the data were chosen before or after the map are part of the guarantee.
| Concept | Intuitive meaning | Exact example | Non-example or boundary | Main assumption | Question answered |
|---|---|---|---|---|---|
| JL embedding | Compress a fixed finite constellation | All $N(N-1)/2$ squared distances stay within $1\pm\varepsilon$ | Injectively preserve all of $\mathbb R^d$ after reducing dimension | Data fixed independently of map | How small may the ambient dimension become? |
| Chi-square concentration | Gaussian projected energy clusters near its mean | (m\lVert Ax\rVert_2^2/\lVert x\rVert_2^2\sim\chi_m^2) | A heavy-tailed matrix with infinite variance | Independent normalized Gaussian rows | Why is one vector preserved? |
| Sub-Gaussian map | Light-tailed alternative to Gaussian entries | Independent signs (\pm1/\sqrt m) | Arbitrarily dependent signs | Adequate independence and isotropy | Which dense distributions also work? |
| Epsilon net | Finite proxy for infinitely many directions | Cover the unit sphere of a (k)-subspace | Net over data points when only pairwise union bound is needed | Lipschitz extension argument | How can a subspace be preserved? |
| Sparse JL | Few matrix nonzeros per input feature | (s) signed destinations per column | Assuming (s=1) always matches dense JL dimensions | Sparse-JL theorem and valid parameter regime | How can projection be faster? |
| Feature hashing | One signed bucket per input coordinate | (s=1) CountSketch-style transform | Collision-free embedding of arbitrary dense vectors | Hash/sign randomness; data conditions | What is the cheapest sparse multiply? |
| FJLT | Spread energy, then reduce dimension | Random signs + Hadamard + sampling | Sampling raw coordinates of a spiky vector | Fast orthogonal transform and preprocessing | How can dense geometry be projected faster? |
Random Projections That Preserve Distance
Let (p=(1,1,0,0)), (q=(1,-1,0,0)), and \[ A=\frac{1}{\sqrt2}\begin{bmatrix}1&1&0&0\\1&-1&0&0\end{bmatrix}. \]
- Compute (p-q=(0,2,0,0)), so the original squared distance is (4).
- Compute (Ap=(\sqrt2,0)) and (Aq=(0,\sqrt2)).
- The projected squared distance is (2+2=4): this pair is preserved exactly.
- Test (r=(0,0,1,0)). Since (Ar=0), its norm is destroyed.
- Expected conclusion: one favorable deterministic matrix and one pair do not establish a JL guarantee.
Reflection: what randomness and quantifier order change the statement from “this pair worked” to “all pairs in this fixed finite set work with high probability”?
Concentration for One Vector
Fix a nonzero vector (x\in\mathbb R^d) before drawing (A), with independent entries (A_{rj}\sim N(0,1/m)). Rotational invariance gives each row dot product (\langle A_r,x\rangle\sim N(0,\lVert x\rVert_2^2/m)). Therefore \[ Y=\frac{m\lVert Ax\rVert_2^2}{\lVert x\rVert_2^2} =\sum_{r=1}^m g_r^2\sim\chi_m^2, \qquad \mathbb E\lVert Ax\rVert_2^2=\lVert x\rVert_2^2. \]
For the upper tail, Markov's inequality on $e^{\lambda Y}$, where $0\lt\lambda\lt1/2$, uses the moment generating function $\mathbb E e^{\lambda Y}=(1-2\lambda)^{-m/2}$. Optimizing $\lambda$ gives \[ \Pr[Y\ge m(1+\varepsilon)] \le \exp\!\left[-\frac m2\bigl(\varepsilon-\ln(1+\varepsilon)\bigr)\right]. \] A parallel calculation for the lower tail yields an exponential bound. For $0\lt\varepsilon\lt1$, a convenient combined form is \[ \Pr\!\left[\left|\lVert Ax\rVert_2^2-\lVert x\rVert_2^2\right|\gt\varepsilon\lVert x\rVert_2^2\right] \le 2\exp\!\left[-m\left(\frac{\varepsilon^2}{4}-\frac{\varepsilon^3}{6}\right)\right]. \] Thus (m=\Theta(\varepsilon^{-2}\log(1/\delta))) preserves one fixed vector with failure probability at most (delta).
The proof tracks four obligations: isotropy makes the expectation correct; independence factors the moment generating function; light tails make it finite; and $x$ must be independent of the sampled map. If $x$ is chosen afterward, any nonzero nullspace vector of a dimension-reducing map has $Ax=0$, a decisive counterexample.
Scaled random-sign matrices satisfy comparable concentration through sub-Gaussian tools without rotational invariance. Sparse embeddings need separate analyses because collisions create dependencies and higher moments. An epsilon net is unnecessary for a finite set of pair differences, but it becomes essential when preserving every vector in a (k)-dimensional subspace; a net of size exponential in (k) turns the logarithm of its size into an (O(k)) dimension term.
flowchart TD
A[Fix x independently of random map] --> B[Choose isotropic Gaussian rows]
B --> C[Each row dot x is scaled normal]
C --> D[Projected energy is normalized chi square]
D --> E[Apply exponential moment bound]
E --> F[Optimize lambda for upper and lower tails]
F --> G[Failure decays as exp minus c epsilon squared m]
G --> H[Choose m for target delta]
H --> I[Union bound finite differences]
I --> J[All pairwise distances preserved]
A --> K{Vector chosen after seeing A?}
K -->|yes| L[Nullspace vector destroys guarantee]
K -->|no| B
classDef navy fill:#17365D,color:#fff,stroke:#17365D;
classDef teal fill:#147D84,color:#fff,stroke:#0D565B;
classDef purple fill:#6C3BAA,color:#fff,stroke:#472675;
classDef crimson fill:#C6284D,color:#fff,stroke:#861B35;
class A,B,C navy;
class D,E,F,G,H purple;
class I,J teal;
class K,L crimson;
For a Gaussian $m\times d$ matrix with entries $N(0,1/m)$, a fixed vector's squared norm deviates by more than an $\varepsilon$ fraction with probability at most $2e^{-\Theta(\varepsilon^2m)}$. The proof is expectation plus chi-square concentration; it is essentially tight in its $\varepsilon^{-2}\log(1/\delta)$ dependence, but it protects inputs fixed independently of the map.
From One Pair to Every Pair
Distances reduce to norms of differences: preserving $x_i-x_j$ preserves the distance between $x_i$ and $x_j$. There are $M=\binom N2$, fewer than $N^2/2$, nonzero pair differences. If the fixed-vector failure probability is at most $\delta/M$, the union bound gives total failure at most $\delta$, regardless of dependence among pair events. Consequently, \[ m\ge C\varepsilon^{-2}\bigl(\log N+\log(1/\delta)\bigr) \] rows suffice for an absolute constant (C). A conservative implementation may use a larger explicit constant derived from the selected tail inequality; asymptotic notation must not be mistaken for a production parameter.
An epsilon net solves a different quantifier problem. To preserve an entire (k)-dimensional subspace, cover its unit sphere by a finite net, apply concentration to each net point, then extend to all unit vectors via continuity and an operator-norm argument. The net has roughly ((1+2/\eta)^k) points, so its logarithm contributes (O(k)).
From One Pair to Every Pair
Suppose $N=1000$, target distortion $\varepsilon=0.25$, and overall failure $\delta=0.01$. Use the simplified one-vector bound $2e^{-m\varepsilon^2/8}$.
- Pair count: (M=1000\cdot999/2=499{,}500).
- Require (2e^{-m\varepsilon^2/8}\le\delta/M).
- Rearranging gives (m\ge(8/\varepsilon^2)\ln(2M/\delta)).
- Here (8/0.0625=128) and (ln(99{,}900{,}000)\approx18.42), so (m\ge2358).
- This conservative constant produces $m\gt d$ if the source dimension is, say, $d=500$; then use the identity map or a sharper bound instead of pretending reduction occurred.
- Perturbed case: reducing $\varepsilon$ to $0.125$ quadruples the dimension term because of the inverse-square dependence.
Verification: compute all pairwise squared-distance ratios on a held-out finite set. Record the maximum absolute distortion, not just its mean.
| Transform | Assumptions | Rows or structure | Multiply cost | Strength | Failure mode | Prefer when |
|---|---|---|---|---|---|---|
| Dense Gaussian JL | Fixed finite data; independent Gaussian entries | (m=O(\varepsilon^{-2}\log(N/\delta))) | (O(md)) per dense vector | Clean proof and rotational invariance | Expensive multiply and storage | Baseline, moderate dimension |
| Dense random-sign JL | Isotropic sub-Gaussian signs | Same asymptotic (m) | (O(md)) | No Gaussian generation | Insufficient independence or wrong scaling | Simple fast dense arithmetic |
| Sparse JL | Valid sparsity (s) and theorem-specific parameters | (s) nonzeros per column | (O(s\,\mathrm{nnz}(x))) or structure-dependent | Faster on sparse input | Collision-driven distortion | Huge sparse feature vectors |
| Feature hashing | One signed destination per feature | (s=1), often larger (m) or data restrictions | (O(\mathrm{nnz}(x))) | Extremely simple streaming transform | Spiky vectors collide badly | Tolerant ML pipelines and wide sparse data |
| FJLT | Fast orthogonal transform available | Random diagonal, Hadamard/Fourier, sampling | About (O(d\log d)) plus reduction | Spreads spikes before sampling | Padding, constants, dense intermediate | Dense high-dimensional batches |
| Subspace embedding | Preserve every vector in a fixed (k)-subspace | Dimension depends on (k,\varepsilon,\delta) | Transform-dependent | Supports regression and linear algebra | Treating finite-set JL as a subspace theorem | Least squares and numerical linear algebra |
Sparse Embeddings and Fast Geometry
Sparse projections replace dense matrix-vector multiplication with a few signed writes per nonzero input feature. In a common construction, each input coordinate chooses (s) output rows and contributes a scaled signed value. The scaling preserves expected energy; multiple destinations reduce the chance that one collision dominates. Feature hashing sets (s=1), making application linear in the input's number of nonzeros, but arbitrary dense or spiky vectors can require more rows or stronger assumptions than dense JL.
FJLT takes another route: multiply coordinates by random signs, apply a normalized Hadamard or Fourier transform to flatten leverage, then subsample or apply a sparse projection. The spreading step prevents a single source coordinate from controlling one sampled output. It is fast for dense vectors and structured dimensions, though padding, memory layout, batching, and transform constants matter in practice.
In a teaching case, project a fixed point cloud with Gaussian, sign, and one-sparse hashing matrices, then plot the full distribution of pairwise distortion. In a professional nearest-neighbor pipeline, freeze and version the projection, validate recall after projection, and retain exact re-ranking on original vectors. In a scientific least-squares problem, use a subspace-embedding theorem rather than an all-pairs finite-set statement. Reject the method if queries adapt to a public map, if rare spiky vectors dominate, if downstream margins are smaller than allowed distortion, or if dimension reduction saves less than transform overhead.
flowchart TD
A[Define protected points pairs or subspace] --> B[Set distortion epsilon and failure delta]
B --> C{Dense or sparse inputs?}
C -->|dense| D[Benchmark Gaussian sign and FJLT]
C -->|sparse| E[Benchmark sparse JL and feature hashing]
D --> F[Validate maximum distortion and task quality]
E --> F
F --> G{Guarantee and latency pass?}
G -->|yes| H[Freeze seed scale dimension and version]
G -->|no| I[Increase dimension change transform or reject]
H --> J[Monitor drift recall and adaptive exposure]
J --> K{Assumptions remain valid?}
K -->|yes| J
K -->|no| I
classDef navy fill:#17365D,color:#fff,stroke:#17365D;
classDef teal fill:#147D84,color:#fff,stroke:#0D565B;
classDef purple fill:#6C3BAA,color:#fff,stroke:#472675;
classDef crimson fill:#C6284D,color:#fff,stroke:#861B35;
class A,B,C navy;
class D,E,F purple;
class G,H,J teal;
class I,K crimson;
Sparse Embeddings and Fast Geometry: Johnson-Lindenstrauss Proof & Sparse Embeddings
Scenario: a search service stores (N=2\times10^6) documents with (d=10^6) hashed lexical features and a median of 800 nonzeros per document. It needs faster candidate generation while protecting nearest-neighbor recall.
- Define the protected population: the frozen corpus, validation queries, and the distance ranges that affect top-100 retrieval.
- Compare one-sparse feature hashing, a multi-nonzero sparse JL transform, and a dense baseline on a representative sample. Measure transform time, projected storage, maximum and percentile distortion, candidate recall, and exact-reranked recall.
- Choose (m) from a theorem as a safe starting point, then tune only with a held-out validation set. Do not replace a worst-case statement with average distortion.
- Stress spiky one-feature documents, duplicates, near ties, out-of-distribution queries, mixed projection versions, and queries selected after inspecting collisions.
- Expected result: feature hashing wins multiply time, multi-sparse embeddings reduce collision outliers, and exact reranking recovers precision if candidate recall remains high.
- Invalidate deployment if maximum critical-pair distortion breaches tolerance, recall loss concentrates on a protected cohort, seed exposure enables chosen collisions, or transform overhead erases search savings.
- Selection decision: deploy the fastest transform that meets both theorem-aligned distortion checks and end-task recall, with immutable versioned seeds and a rollback path.
Deliverable: a parameter card recording (N,d,m,s,\varepsilon,\delta), seed ownership, input sparsity, p50/p99 transform latency, distortion distribution, candidate recall, and reranked recall.
Prove and Test a JL Dimension
The following lab moves from the fixed-vector proof to production judgment. Keep squared norms and ordinary distances distinct: a (1\pm\varepsilon) guarantee on squared distance translates to square-root factors on distance.
Practice: Prove and Test a JL Dimension
Starter values: $N=500$, $d=4000$, $\varepsilon=0.30$, $\delta=0.05$, plus 500 fixed synthetic points containing Gaussian, sparse, and deliberately spiky groups.
- Recall: state isotropy, the fixed-vector concentration event, and the all-pairs target. Artifact: three quantified statements with randomness identified.
- Derive: use a supplied chi-square tail bound and (M=\binom N2) to solve explicitly for (m). Criterion: the per-pair failure budget is (delta/M), and every logarithm is accounted for.
- Verify: sample 20 projection seeds and compute every protected pair's squared-distance ratio. Artifact: min, max, mean, p99 distortion, and pass/fail per seed.
- Compare: benchmark Gaussian, random-sign, feature-hashing, and multi-sparse transforms at equal (m). Criterion: report both arithmetic time and tail distortion; do not select by mean error alone.
- Debug: omit (1/\sqrt m) scaling, reuse identical Gaussian rows, and hash without signs. Predict the energy inflation, loss of concentration, and collision bias before executing.
- Boundary: after revealing a dimension-reducing map, numerically search for a near-nullspace direction. Explain why this does not contradict the fixed-data JL lemma.
- Extension: replace the finite cloud with a (k=20) subspace. Build an epsilon-net argument outline and identify where its covering number changes the dimension bound.
- Professional judgment: recommend a transform and parameter set for batch dense vectors and another for streaming sparse vectors. Include seed lifecycle, numerical precision, monitoring, and rejection criteria.
Hints: preserve differences rather than points; union bounds do not require independent pair events; sparse transforms need their own theorem; if a conservative bound gives (m\ge d), keeping the original representation may be best.
Rubric: 25% proof and constants, 20% dimension calculation, 20% reproducible experiment, 15% failure diagnosis, 10% transform comparison, 10% deployment argument. Mastery requires at least 80% and correct quantifier order.
Decision checklist: specify the finite set, pair set, or subspace; choose squared- or ordinary-distance distortion; allocate (delta); derive (m) from the matching theorem; select dense, sparse, hashing, or FJLT structure from input sparsity and latency; normalize correctly; freeze seeds; test maximum distortion and downstream quality; and reject adaptive or nullspace claims outside the model. The conceptual bridge is from finite-set JL to oblivious subspace embeddings, randomized least squares, and sketch-based numerical linear algebra.