2.5.12 · D5Unsupervised Learning

Question bank — UMAP for dimensionality reduction

2,325 words11 min readBack to topic

Before we start, a few plain-word reminders so no symbol below is a surprise.

Recall What

is (the number of neighbours) is just a nickname for the hyperparameter n_neighbors — the number of nearest neighbours each point is allowed to look at when we build the graph. So "sum to " means "sum to ". Small = very local view; large = broader, more global view.

Recall What

and mean = distance () from point to its closest neighbour (a floor we subtract off). = a per-point "stretch" tuned so the point's outgoing edge weights sum to — this makes dense and sparse regions get treated fairly.

Recall What

, , and are in the low-D kernel In , the distance is the straight-line distance between the two points in the 2-D picture. The two constants and are shape knobs fitted once (numerically, giving roughly for the default min_dist) so the kernel's flat-then-falling curve matches the min_dist you asked for. You never tune by hand — UMAP solves for them from min_dist.

Recall What

min_dist is and its valid range min_dist sets how tightly points are allowed to pack in the picture: it is the effective minimum gap the low-D kernel encourages. Valid range is (typically ; default ). At points may sit right on top of each other (tight, dense clusters); near they are pushed apart into an airy, spread-out layout. It only reshapes — it never touches the high-D graph.

The figure below shows both kernels together so you can see how a distance becomes a weight before you tackle the traps.

Figure — UMAP for dimensionality reduction

Figure s01. Horizontal axis = distance between two points; vertical axis = the resulting edge weight (0 to 1). The pale-yellow curve is the high-D map : flat at 1 until the nearest-neighbour floor (pink dashed line), then exponential decay set by . The blue curve is the low-D kernel : notice its heavy tail — far-apart points in the picture still feel a faint pull, which is what prevents the "crowding problem".


True or false — justify

TF — "UMAP preserves the actual distances between clusters, so a gap twice as wide means twice as different."
False. UMAP preserves ordering and connectivity of structure, not metric distances; inter-cluster gaps are qualitatively meaningful but not quantitatively to scale.
TF — "Because UMAP keeps some global structure, cluster sizes in the plot reflect how spread-out those groups are in high-D."
False. Cluster size in the embedding is mostly an artefact of min_dist and the repulsion dynamics, not high-D variance — a tiny plotted blob can be a huge manifold region.
TF — "By default (parallel threads, no fixed seed) UMAP gives an identical layout every run."
False. Default runs are non-deterministic — parallelism and random negative sampling make each layout differ (often just a rotation/reflection); you must fix the random seed and run single-threaded to reproduce a layout exactly.
TF — "The high-D weight is symmetric before we symmetrize it."
False. (how much sees ) differs from because and are per-point; that is exactly why the fuzzy-union step exists.
TF — "The fuzzy-union weight can exceed 1 if both directions are strong."
False. The correction term caps it: even with you get , so it stays a valid membership in .
TF — "Increasing n_neighbors always improves the embedding."
False. Large buys global structure but blurs fine local clusters and costs more; the 'best' depends on whether you care about micro-clusters or the macro-layout.
TF — "min_dist changes what UMAP thinks the data is."
False. min_dist only shapes the low-D kernel (how tightly points may pack); it never touches the high-D graph , so it is purely a cosmetic/visualisation knob.
TF — "UMAP only works if you feed it Euclidean distances."
False. Euclidean is the default for , but the fuzzy-graph construction accepts any metric (cosine, Manhattan, etc.); only the low-D distance is fixed to Euclidean because it's a plot.
TF — "UMAP can embed a brand-new point without re-running the whole optimisation."
True. Once trained, UMAP can transform new points into the existing embedding — something t-SNE fundamentally cannot do without refitting.
TF — "Setting min_dist=0.0 guarantees clusters that touch will merge visually."
False. min_dist=0 only allows points to pack tightly; the attractive/repulsive forces from still keep genuinely different clusters apart.

Spot the error

Error — "We compute so that (the number of neighbours)."
The target is , not . Summing to would ignore the information-theoretic perplexity idea and over-connect every point.
Error — " is subtracted so that even a point's farthest neighbour gets weight 1."
No — is the nearest-neighbour distance, so only the closest neighbour () gets weight ; farther ones still decay.
Error — "Cross-entropy here only rewards putting connected points close together."
It has two halves. The second term punishes putting unconnected points close — that repulsion is what stops everything collapsing to one dot.
Error — "Negative sampling picks the closest non-neighbours to push apart."
Negative sampling picks random pairs (mostly far ones, so ) to cheaply and unbiasedly approximate the repulsive term; picking closest non-neighbours would be the wrong statistic and slow.
Error — "The low-D kernel uses the same exponential form as the high-D weight."
No — high-D uses an exponential decay in ; low-D uses a rational, heavy-tailed (Student-t-like) kernel in to avoid the crowding problem.
Error — "The constants and in the low-D kernel are hyperparameters you set by hand."
No — they are derived from min_dist by a one-time curve fit, so the knob you actually turn is min_dist; follow from it automatically.
Error — "Since UMAP models a manifold, it must fail on data with no manifold (pure noise)."
It won't fail to run; it will happily produce a blob or spurious clusters. The trap is trusting structure that the algorithm invented from noise.
Error — "We use spectral embedding as the final answer, then polish with SGD."
Spectral embedding is only the initialisation (a good starting layout); SGD on the cross-entropy loss is what actually produces the result.

Why questions

Why — Why does UMAP subtract inside the exponent at all?
To enforce local connectivity: every point is guaranteed at least one full-strength edge (), preventing isolated points and making the graph a single connected structure.
Why — Why specifically, rather than any constant?
It ties the summed weight to perplexity (effective neighbour count), so dense and sparse regions of the manifold are modelled with matching "local scale" — this is what gives density-aware normalisation.
Why — Why cross-entropy instead of the KL-divergence that t-SNE uses?
Cross-entropy's two-sided form (attraction and repulsion, summed over all pairs) penalises both false-attraction and false-repulsion, which is what lets UMAP preserve global layout; KL in t-SNE mainly rewards local attraction and lets global distances drift.
Why — Why can UMAP afford to sum the repulsion over "all pairs" when that is ?
It doesn't compute them all — negative sampling replaces the exact all-pairs repulsion with a few random draws per edge, giving an unbiased gradient estimate at near-linear cost. See Cross-Entropy Loss.
Why — Why does UMAP need a repulsive term when we already reward keeping neighbours close?
Without repulsion the loss is trivially minimised by piling all points on top of each other; the term supplies the spreading force.
Why — Why is UMAP roughly rather than like naive t-SNE?
A brute-force pairwise graph is , but UMAP builds the neighbour graph with approximate nearest-neighbour descent (see Nearest Neighbors Algorithms): it starts from a rough graph and iteratively refines "my neighbour's neighbour is probably my neighbour," touching only a near-constant number of candidates per point. That empirically scales like (the exponent is measured, not exact), and negative sampling makes the optimisation cost roughly linear too.
Why — Why does min_dist affect visual density but not which clusters appear?
Cluster membership is decided by the high-D graph , which min_dist never touches; min_dist only sets how much the attractive low-D force is capped at short range.

Edge cases

Edge — What happens for a point that is a total outlier, far from everything?
The rule still forces one weight-1 edge to its nearest (though distant) neighbour, so it is tethered in — it won't be dropped, but it may sit at the periphery.
Edge — What if two points are identical ()?
They become -nearest with weight and are pulled essentially on top of each other; duplicate rows just stack, no division-by-zero because handles it.
Edge — What does n_neighbors=1 do, and how does it differ from n_neighbors=2?
With each point connects only to its single nearest neighbour, so the directed graph is essentially a matching — extremely fragmented, with making the calibration degenerate. With there is finally overlap between neighbourhoods, so small chains/clusters can begin to form; is effectively unusable while is merely very local.
Edge — What if n_neighbors is set larger than the number of points ?
The algorithm clamps to at most neighbours; effectively every point sees every other and you lose all locality, approaching a near-global (almost linear-projection-like) embedding.
Edge — What happens at the extremes of min_dist (0 versus close to 1)?
At min_dist=0 the kernel lets even as , giving tight, dense clusters that preserve local density; near the upper end (approaching 1) points are strongly repelled at short range, producing an inflated, evenly spread layout that trades density info for readability.
Edge — What if the data is genuinely linear (a flat plane in high-D)?
UMAP will still work, but this is exactly the case where a linear method like PCA or Random Projection is cheaper and gives a faithful, interpretable result.
Edge — What if you feed UMAP a distance metric that violates the triangle inequality?
UMAP tolerates arbitrary metrics for graph construction, but the manifold assumption weakens; interpret the layout cautiously since the "geodesic" reasoning behind Isomap-style methods no longer holds cleanly.