Foundations to Frontier
Tests
D. Classical Machine Learning › D9 Dimensionality Reduction and Manifold Learning

UMAP

Uniform Manifold Approximation and Projection (McInnes, Healy and Melville, 2018) is a fast neighbour-embedding method that has largely joined t-SNE as the default for visualising and compressing high-dimensional data. It builds a weighted k-nearest-neighbour graph in which each point's edge weights decay from its nearest neighbour at a locally adapted rate, combines the directed weights by a fuzzy union, and lays the graph out in low dimensions by stochastic gradient descent on a fuzzy cross-entropy, with sampled edges for attraction and random pairs for repulsion. It scales to millions of points, supports any embedding dimension and new-point transforms, and its parameters (n_neighbors, min_dist) are intuitive. Its claimed advantage in preserving global structure over t-SNE comes largely from its default spectral initialisation rather than from the objective. This page covers the fuzzy simplicial-set construction, the low-dimensional curve and its a, b parameters, the cross-entropy and its sampling-based optimisation, connections to t-SNE and Laplacian eigenmaps, and how to read UMAP plots. In the exercises you implement a compact UMAP; then you test which method and initialisation preserve the order of clusters along a line.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

A neighbour graph, pulled and pushed into shape

UMAP works like t-SNE but thinks in terms of a graph. It connects every point to its nearest neighbours, with strong links to the closest and weak links further out. Then it drops the points onto a flat sheet and lets linked points pull together while random pairs push apart, until the layout settles. Groups of mutually linked points end up as islands, and points with no links between them have no reason to sit in any particular arrangement.

UMAP: fuzzy neighbour graph, attraction and repulsion
epoch 0/300 · graph weight between clusters 0.0% · a = 1.58, b = 0.90 · global order score 0.00 (1 = cluster distances in the right order)
Colours run red → purple along the line. Each cluster has only 26 points, so with k below 26 the neighbour graph has no edges between clusters (0% weight): UMAP then knows nothing about how clusters are arranged, and with random initialisation they land anywhere (score near 0). Start from PCA and the line's order survives, because nothing in the graph pulls it apart. From random starts the score swings from run to run (try new data), anywhere from about −0.3 to 0.6. Raising k above the cluster size adds only a sliver of between-cluster weight (0.1–0.2% at k = 40), too little to fix the arrangement. min_dist only changes how tightly each cluster packs.
Why engineers care

UMAP is fast enough for millions of points, can embed into more than two dimensions as features for downstream models, and can place new data into an existing map. That makes it the common choice for monitoring embedding drift, exploring large telemetry or image datasets, and building cluster-friendly representations. Knowing what its layout does and does not mean is as important as with t-SNE.

📝 Quick check (Level 0)
0/3 answered
  1. 1. UMAP first builds…
  2. 2. During layout, linked points…
  3. 3. If no graph edges join two clusters, their relative position is set mostly by…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Memberships, union and the output curve by hand

Local memberships. For point i with neighbours at distances d₁ ≤ … ≤ d_k, set ρᵢ = d₁ (the nearest-neighbour distance) and choose σᵢ so that Σⱼ exp(−(dⱼ − ρᵢ)/σᵢ) = log₂ k. For k = 15 that sum is 3.907. The membership of neighbour j is exp(−(dⱼ − ρᵢ)/σᵢ):

  • the nearest neighbour always gets 1, so no point is isolated;
  • with ρ = 1 and σ = 0.5, a neighbour at 1.5 gets e⁻¹ = 0.368.

Fuzzy union. The directed weights are combined with the probabilistic t-conorm wᵢⱼ = a + b − ab. Weights 0.5 and 0.4 give 0.7; if either is 1, the union is 1.

Low-dimensional similarity. vᵢⱼ = 1/(1 + a‖yᵢ − yⱼ‖^(2b)), with a and b fitted so the curve is about 1 up to min_dist and then decays like exp(−(d − min_dist)). For min_dist = 0.1 the fit gives a ≈ 1.58, b ≈ 0.89, and at distance 1, v = 1/2.58 = 0.388. With a = b = 1 this is exactly t-SNE’s Student-t kernel, before normalisation.

Objective. The fuzzy cross-entropy Σ [w log(w/v) + (1 − w) log((1 − w)/(1 − v))]. The first term attracts linked pairs; the second repels pairs that should not be close. For w = 1 and v = 0.5 it is ln 2 = 0.693.

The steps in plain English:

  1. Optionally reduce to about 50 dimensions with PCA, then find k nearest neighbours (approximate search, such as NN-descent, for large n).
  2. Compute ρᵢ and σᵢ, the memberships and their fuzzy union.
  3. Initialise the layout, by default with a spectral embedding of the graph.
  4. Optimise by SGD: sample edges in proportion to their weight and pull their ends together; for each, push a few random points away; decay the learning rate.
  5. Check stability across seeds, n_neighbors and initialisations.
📝 Quick check (Level 1)
0/3 answered
  1. 1. ρᵢ in UMAP is…
  2. 2. Fuzzy union of weights a and b is…
  3. 3. min_dist controls…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 30 minUndergraduate students and practising engineers.

Optimisation, and the relation to t-SNE

Gradients. For an edge with weight w, the attractive force on yᵢ is −2ab d^(2(b−1)) (yᵢ − yⱼ)/(1 + a d^(2b)). For a negative sample, the repulsive force is 2b (yᵢ − yⱼ)/((ε + d²)(1 + a d^(2b))). Both are clipped to ±4 for stability. Edges are sampled with probability w, which is equivalent in expectation to weighting the attraction by w, and each sampled edge brings a few random negatives.

UMAP versus t-SNE.

  • Normalisation: t-SNE normalises Q over all pairs, which couples every point; UMAP’s per-edge cross-entropy has no global normalisation, so SGD with sampling suffices. This is a major reason for its speed.
  • Graph: UMAP’s input graph is sparse, with k neighbours (k = 15 by default) and nothing else. t-SNE’s P is dense in principle and has mass on roughly 3 × perplexity neighbours.
  • Repulsion: UMAP repels more weakly, which gives tighter, more separated clusters. Böhm, Berens and Kobak (2022) showed that t-SNE with exaggeration of about 4 looks like UMAP.

Exercise 1 (6 clusters in 10-D, 150 points, k = 15, PCA initialisation):

  • memberships summed to log₂ k exactly;
  • the fitted curve had a = 1.58, b = 0.89 for min_dist 0.1, matching umap-learn’s values;
  • 97.4% of the graph weight was inside clusters, and the graph fell into 4 separate components;
  • 5-NN accuracy in 2-D was 0.987, against 0.813 for PCA.

A spectral initialisation, UMAP’s default, is degenerate on a disconnected graph: each component contributes a zero eigenvalue, and the eigensolver returns an arbitrary mix of component indicators. A first version of this exercise used it and scored 0.967 natively but 0.88 in the browser, because the two eigensolvers chose different mixes and stacked different clusters on top of each other. umap-learn avoids this by laying out components separately.

import umap                                      # package umap-learn
Y = umap.UMAP(n_neighbors=15, min_dist=0.1, init="spectral", random_state=0).fit_transform(X)
Y_new = umap.UMAP(n_neighbors=15).fit(X).transform(X_new)     # place new points
🐍 Exercise 1: a compact UMAP
Build the fuzzy k-NN graph (ρ, σ by binary search so memberships sum to log₂ k, fuzzy union), fit the output curve's a and b for min_dist, and optimise the layout with edge sampling and negative sampling from a PCA initialisation; count the graph's components and compare 5-NN accuracy with PCA.
📝 Quick check (Level 2)
0/3 answered
  1. 1. UMAP avoids t-SNE's global normalisation, so it can use…
  2. 2. With a = b = 1, UMAP's output kernel equals…
  3. 3. t-SNE with exaggeration of about 4 looks like…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Topological motivation. UMAP’s paper builds the graph as a fuzzy simplicial set: local metric spaces, one per point, each normalised so that its nearest neighbour is at distance ρᵢ, glued by a fuzzy union. The layout then minimises the cross-entropy between the fuzzy sets in the input and output spaces. In practice, the algorithm is a sparse, locally normalised neighbour graph plus a sampling-based attraction–repulsion layout, and most of its behaviour is explained by that view.

What the loss actually optimises. Damrich and Hamprecht (2021) showed that, because of negative sampling, UMAP’s SGD does not minimise the stated cross-entropy but an objective with much weaker, effectively normalised repulsion. The original fuzzy weights matter less than expected, and the graph’s binary structure dominates.

Global structure. Kobak and Linderman (2021) found that UMAP’s reputation for better global structure than t-SNE disappears when both use the same initialisation. Spectral or PCA initialisation carries the global layout, and the optimisation mostly refines local structure. When the k-NN graph is disconnected, nothing in the loss constrains the relative positions of the components.

Interview questions.

  • What do n_neighbors and min_dist do? n_neighbors sets the graph’s locality: small values give fine detail and fragmented islands, large values more global structure. min_dist only controls packing in the output. Neither turns gaps or sizes into faithful quantities.
  • Can I cluster on UMAP output? Often in practice (UMAP + HDBSCAN), but validate the clusters in the original space; UMAP can split continuous structures and merge unrelated ones near the graph’s resolution limit.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Kobak and Linderman attribute UMAP's global-structure advantage mainly to…
  2. 2. Because of negative sampling, UMAP's SGD effectively optimises…
  3. 3. Large n_neighbors tends to…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Which method keeps the clusters in order?

History.

  • L. McInnes, J. Healy and J. Melville (2018) introduced UMAP.
  • E. Becht et al. (2019) popularised it for single-cell biology.
  • D. Kobak and G. Linderman (2021) traced global structure to initialisation.
  • S. Damrich and F. Hamprecht (2021) analysed what UMAP’s optimisation actually minimises.
  • J. Böhm, P. Berens and D. Kobak (2022) placed t-SNE, UMAP and Laplacian eigenmaps on one attraction–repulsion spectrum.

Exercise 2. Seven clusters of 26 points along a line in 10-D, at positions 0, 10, 20, 30, 50, 80 and 120, 3 datasets. The score is the rank correlation between the true and embedded distances of the 21 pairs of cluster centres (1 = perfect order).

method global order score
PCA 0.996
t-SNE, random initialisation 0.746
t-SNE, PCA initialisation 0.837
UMAP, random initialisation 0.121†
UMAP, PCA initialisation 0.677†

† UMAP’s layout is stochastic and sensitive to rounding, so these two values differ between platforms: the in-browser Python gives 0.192 and 0.585. The t-SNE and PCA rows are identical on both.

  • UMAP from a random start lost the order almost completely (0.12). Its k = 15 graph had exactly 0% of its weight between clusters, because each cluster has 26 points, so nothing in the objective constrains where clusters go.
  • PCA initialisation restored much of the order for UMAP (0.68) and improved t-SNE too (0.84 against 0.75). Initialisation, not the algorithm, carried the global layout.
  • t-SNE kept the order better than UMAP here even from random starts, contrary to folklore. The reason is specific: its perplexity of 30 exceeds the cluster size, so about 5% of its P mass links neighbouring clusters and encodes their order. With smaller perplexity or bigger clusters, t-SNE would lose it too.
  • The demo shows the run-to-run spread: UMAP with random initialisation scored anywhere from about −0.3 to 0.65.
🐍 Exercise 2 (research): global order and initialisation
Seven clusters along a line in 10-D: compare how well PCA, t-SNE (random or PCA initialisation) and UMAP (random or PCA initialisation) preserve the order of the distances between cluster centres.

UMAP in AI, robotics and aerospace

  • Embedding drift monitoring: fit UMAP on reference perception embeddings and transform new flight data to spot distribution shift.
  • Large-scale telemetry exploration: visualise millions of time windows from fleet sensors to find rare regimes, then confirm them in the original features.
  • Feature compression: 5–10-D UMAP features feeding clustering or anomaly detectors, validated against the raw features.

References

  1. L. McInnes, J. Healy, J. Melville (2018). “UMAP: Uniform manifold approximation and projection for dimension reduction.” arXiv:1802.03426.
  2. D. Kobak, G. C. Linderman (2021). “Initialization is critical for preserving global data structure in both t-SNE and UMAP.” Nature Biotechnology 39.
  3. S. Damrich, F. A. Hamprecht (2021). “On UMAP’s true loss function.” Advances in NeurIPS 34.
  4. J. N. Böhm, P. Berens, D. Kobak (2022). “Attraction-repulsion spectrum in neighbor embeddings.” Journal of Machine Learning Research 23.
  5. E. Becht et al. (2019). “Dimensionality reduction for visualizing single-cell data using UMAP.” Nature Biotechnology 37.