Preserving all pairs: the final JL guarantee
On this page 11 headings
Learning goal: Choose a target dimension that preserves every pair with high probability.
Conditions and notation
- There are n(n−1)/2 distinct unordered pairs.
- Use both tails and the union bound; pair failures need not be independent.
- The target dimension is an integer, so round the final requirement upward.
- The ideaOne coin lands heads with probability ½, but two coins both landing heads is only ¼.
- Likewise, knowing that one distance survives the squeeze is not enough: we need every one of the ~n²/2 distances to survive at the same time.
- The union bound adds up all the small failure chances, and because each one is exponentially small, k only needs to grow like log n to pay for all of them.
Step 1: what we have so far
Key statement
Picture: n points in , one pair joined by the difference vector u, mapped by to the pair in joined by .
Take any two points x, y and let .
Because M is linear, .
So for one fixed pair, the chance that its squared distance grows by more than (1 + ε) is at most .
This is true for any fixed vector u.
Step 2: the real bad event
What do we really want
[UNION BOUND]
- If even one pair is distorted, the lemma's promise fails, so the real bad event is "there exists a bad pair".
- Its complement (Toolkit 0.7) is the good event: all pairs are preserved.
"There exists a bad pair" is the union of the per-pair bad events.
We don't know how these events overlap, so we use the union bound (Week 1, the union-bound lesson) and simply add their probabilities.
Step 3: add up and solve for k
Key statement
.
Why n²? There are pairs, each failing with probability at most .
Writing n² instead of is slightly loose but simpler.
- Solving for k: take log of both sides (log is increasing), move terms across, multiply by .
Reading the result: if k is at least this big, then with probability at least 1 − δ, all pairwise distances are preserved.
If k is smaller, the proof can't promise it.
Why it's O(log(n/δ)/ε²): (when δ ≤ 1).
When δ is treated as a fixed constant, this is the familiar .
Step 4: both sides
- Key statement"Similar analysis can be done to show" .
- Then:
A distance can fail in two ways, too big or too small.
Each is bad, so a second union bound doubles the per-pair failure chance.
- The extra 2 only adds to k, which changes nothing in big-O.
- This is the complete JL lemma: with this k, preserves all distances within with probability at least 1 − δ.
Worked example 1: a realistic data set
n = 10,000 documents, ε = 0.2 (20 % distortion allowed), δ = 0.05 (95 % confidence).
- .
- .
- 4,422.
- If each document is a bag-of-words vector with d = 100,000 words, every distance becomes about 23× cheaper (100,000 ÷ 4,422 ≈ 22.6) to compute, with a 95 % guarantee on all ~50 million pairs at once.
Worked example: one million points
- Given: and δ .
- Substitute the parameters and round the target dimension upward.
- This exceeds , so the guarantee offers no dimension reduction for that input dimension.
- With , the same formula requires . A much larger original dimension makes the reduction useful.
Worked example 3: how δ affects k
- n = 1,000, ε = 0.2.
- For δ = 0.1: .
- For δ = 0.01: .
- For δ = 0.001: .
- Each 10× improvement in confidence costs only about +460 dimensions ().
- Confidence is cheap.
Does it really work? A simulation
- 40 random points in d = 3,000 dimensions (780 pairs), ε = 0.3.
- For each k we drew 200 independent random matrices and counted how often at least one pair was distorted by more than 30 %.
Check yourself
Why can't we just multiply the per-pair success probabilities?
- That needs the pairs' events to be independent, and they aren't: all pairs share the same matrix R (and the same points).
- The union bound needs no independence.
n = 100, ε = 0.5, δ = 0.01. What k does the final formula give?
.
Round the exact requirement upward: choose k = 465.
Where in the final formula does d appear?
Nowhere. k depends only on n, ε and δ.
Rewrite "P(all pairs preserved) ≥ 0.99" in terms of the bad event.
P(at least one pair distorted) ≤ 0.01, so δ = 0.01.
Key points to remember
- There are n(n−1)/2 distinct unordered pairs.
- Use both tails and the union bound; pair failures need not be independent.
- The target dimension is an integer, so round the final requirement upward.
