Part VI — Unsupervised Learning, Clustering, Dimensionality & Time Series · Chapter 6

UMAP (Uniform Manifold Approximation & Projection)

Hook

Five points trace an L-shaped bend through space. Point C sits right at the corner — closer, in a straight line, to both ends of the L than plain distance would suggest. How do you build a map of "who's really a neighbor of whom" that respects the bend instead of cutting across it?

Intuition
A1.0B1.0C1.0D1.0E1.0
C's neighbor(s) at k=1: B — the number under each point is its own distance to its nearest neighbor

C sits at the elbow of the path. Even though A and E are only two hops away along the bend, C's actual nearest neighbors are always B and D — never A or E — no matter whether you ask for its 1 or 2 closest points. The neighbor graph tracks the path, not a straight ruler laid across the page.

Formalize

UMAP builds a fuzzy neighbor graph: instead of a hard yes/no "is this a neighbor," every pair of points gets a membership strength between 0 and 1.

ρi=minjid(xi,xj),vji=exp ⁣(d(xi,xj)ρiσ)\rho_i = \min_{j \neq i} d(x_i, x_j), \qquad v_{j \mid i} = \exp\!\left(-\frac{d(x_i, x_j) - \rho_i}{\sigma}\right)
  • ρi\rho_i — point ii's local radius: the distance to its single closest neighbor.
  • d(xi,xj)d(x_i, x_j) — the distance between points ii and jj.
  • σ\sigma — a bandwidth controlling how fast membership decays with distance (fixed here for exact arithmetic; real UMAP solves for it per point).
  • vjiv_{j \mid i} — the directed membership of jj in ii's neighborhood: 11 at the local radius, decaying beyond it, and exactly 00 once jj isn't among ii's kk nearest neighbors at all.
  1. Every point gets a full-strength connection to its nearest neighbor

    Subtracting ρi\rho_i shifts the exponential so that jj's membership is exactly 11 right at ii's local radius — regardless of whether ii lives in a dense or sparse region. That's what makes this "uniform": density doesn't change how strongly a point connects to its own closest neighbor.

  2. Membership is directed, and can disagree in each direction

    vjiv_{j\mid i} answers "how much does ii consider jj a neighbor" — which need not match vijv_{i \mid j}, the reverse question. C might see B as an obvious neighbor while B has closer points of its own to worry about.

  3. Symmetrize with a fuzzy-set union, not an average

    vij=vji+vijvjivijv_{ij} = v_{j\mid i} + v_{i\mid j} - v_{j\mid i}\, v_{i\mid j} An edge counts as long as either direction sees it — the same logic as a union of probabilities of independent events. A plain average would let one side's "no" cancel out the other side's "yes."

Play
ABCDE
after 0 step(s): A↔B = 0.16, A↔D = 0.22

Starting from a random-looking jumble, the same attract-along-edges, repel-everywhere-else rule that drives the real optimizer pulls A and B — connected at full strength — together almost immediately, while A and D — never neighbors — drift apart. Step forward and watch the gap between "A to B" and "A to D" open up.

Worked example

Point A's true nearest neighbor is B, one unit away; C sits two units from A, and A doesn't make C's own shortlist:

  1. A's local radius

    ρA=d(A,B)=1\rho_A = d(A, B) = 1 — A's nearest neighbor is exactly one unit away, so full-strength membership starts there.

  2. A's view of C

    d(A,C)=2d(A, C) = 2, so vCA=exp((21)/1)=exp(1)0.368v_{C \mid A} = \exp(-(2 - 1)/1) = \exp(-1) \approx 0.368. A genuinely considers C a neighbor — just a weaker one than B.

  3. C's view of A — nothing at all

    C's two nearest neighbors are B and D, not A — so vAC=0v_{A \mid C} = 0. From C's side, A isn't close enough to register.

  4. The symmetrized edge survives on A's vote alone

    vAC=0.368+0(0.368)(0)=0.368v_{AC} = 0.368 + 0 - (0.368)(0) = 0.368. The fuzzy union means A's "yes" is enough to create a real, if partial, edge — even though C's own answer was "no."

Checkpoint

Drag the steps slider until A is at least 1.5 units closer to its true neighbor B than to the unconnected D. (Watch out — one lone step can briefly make things worse before they settle.)

ABCDE
steps=0 — A↔B = 0.16, A↔D = 0.22, gap = 0.06
Drag steps to try it
Summary
vji=exp ⁣(d(xi,xj)ρiσ),vij=vji+vijvjivijv_{j \mid i} = \exp\!\left(-\frac{d(x_i, x_j) - \rho_i}{\sigma}\right), \qquad v_{ij} = v_{j\mid i} + v_{i\mid j} - v_{j\mid i}\, v_{i\mid j}

UMAP turns raw distances into a fuzzy graph — full strength at each point's own local radius, decaying beyond it, symmetrized by a union rather than an average — and then lays that graph out in low dimensions by pulling connected points together and pushing everything else apart. The result preserves local neighbor structure (who's close to whom) even when the manifold itself bends through the original space, the way C's true neighbors stayed B and D no matter how the raw straight-line distances to A and E looked.