UMAP first builds a k-nearest-neighbor graph in the original high-dimensional space (here: 4 synthetic Gaussian blobs in 5D, k = n_neighbors). It then optimizes a low-dimensional layout — 3D in this demo — so that the graph's structure survives the drop in dimension, using two competing forces applied every epoch:
attractive (per graph edge i–j):
F = k_a · (d(i,j) − restLength) · û(i→j)
restLength ∝ min_dist (small min_dist ⇒ tighter clusters)
repulsive (every pair i,j — negative sampling in real UMAP):
F = k_r / (d(i,j)² + ε) · û(j→i) (inverse-square push-apart)
centering: a weak pull toward the origin keeps the cloud in view.
This mirrors the real UMAP objective at a qualitative level: attraction shrinks connected pairs toward a target separation set by min_dist, while the inverse-square repulsion term has the same leading-order shape as UMAP's actual negative-sampling gradient, which pushes unrelated points apart everywhere in the embedding. Increasing n_neighbors connects more distant points, favoring global structure over fine local detail; increasing min_dist relaxes how tightly connected points are allowed to pack.
- Layout stress — mean squared deviation of each edge's current length from its target; falls as the layout converges.
- Neighbor preservation — of each point's original k nearest neighbors (measured in the true 5D data), the fraction still among its k nearest neighbors in the current 3D embedding. A well-converged UMAP layout keeps this high even though 2 dimensions were discarded.
- New Data resamples four fresh 5D Gaussian blobs and restarts the embedding from random noise; Reset Layout keeps the same data but re-randomizes only the embedding positions.