UMAP: Fuzzy Neighbourhood Graphs, Layout Optimisation and New-Point Transforms
Published:
First build a graph, then draw it
UMAP is easiest to understand as two connected stages. The first estimates local relationships in the input representation. The second finds low-dimensional coordinates whose similarities reproduce those relationships as well as possible under its objective.
The mathematical motivation uses manifold and fuzzy-set ideas, but the fitted result depends on concrete choices: input metric, neighbour search, local scale estimates, graph combination, initialisation and stochastic optimisation. Those choices deserve the same attention as the name of the method.
Give each neighbourhood its own scale
For an observation i and a selected neighbour j, a standard directed membership has the form
Here \(\rho_i\) represents a local connectivity offset and \(\sigma_i\) a locally fitted scale. Neighbours inside the offset receive weight one; more distant neighbours receive smaller weights. The precise offset calculation depends on the local-connectivity setting and handling of duplicate distances.
This adjustment allows regions with different sampling density to contribute local structure. It also means the eventual map does not simply preserve raw metric distances or original density. Local normalisation is already changing what the graph records.
Combine the two directed relationships
An observation can regard another as a strong neighbour without the reverse relation having equal strength. A common fuzzy union combines the directed weights as
If the two weights are 0.8 and 0.4, the union is \(0.8+0.4-0.32=0.88\). A mutual intersection would instead multiply them, giving 0.32. These operations encode different preferences for one-sided relationships.
The usual graph construction can interpolate between union- and intersection-like behaviour through a configuration parameter. A sparse nearest-neighbour graph also omits most pairwise relationships. Inspect connected components and weak bridges when they determine the story told by the plot.
Fit a low-dimensional similarity
For map positions y, UMAP uses a smooth distance-decay family such as
with a and b chosen from layout parameters. A fuzzy-set cross-entropy objective contains attractive and repulsive contributions of the form
Pairs with high input membership encourage proximity; non-neighbour relationships contribute separation. Actual training uses stochastic edge sampling and negative sampling rather than evaluating every pair at every step. Sampling choices therefore matter when comparing practical optimisation with the idealised full expression.
The map is a compromise. A low-dimensional space may be unable to preserve every local relation of the original graph simultaneously, especially when the input has higher intrinsic dimension.
Neighbour count and minimum distance do different jobs
The neighbour-count setting affects the input graph. Small values emphasise fine local structure; larger values incorporate relationships over a broader scale. This is not a direct cluster-count parameter.
The minimum-distance setting affects the fitted low-dimensional similarity curve and how tightly groups can pack. Despite the name, it is not a strict rule forbidding all plotted distances below a threshold. Changing it can make islands look much tighter without changing the input graph at all.
This gives a useful diagnostic: if the apparent strength of a cluster changes mainly when a layout parameter changes, the visual change is not new evidence in the original observations. Examine graph connectivity and original-space neighbours separately.
An example of the interpretation trap
Suppose a dataset contains two overlapping populations and one continuous gradient within each. A small neighbour count can emphasise subregions, and a small minimum distance can pack them into distinct-looking islands. Increasing the count and loosening the layout may reveal a more connected arrangement.
Neither plot alone tells you which biological or business categories exist. The graph and layout each contain tunable assumptions. Use external measurements, stability and clustering evaluation to test a population claim.
Basic UMAP is not designed to preserve density exactly. Density-preserving variants change the objective and should be identified explicitly. Likewise, absolute axes and arbitrary map rotations have no intrinsic scientific meaning.
Transforming new observations
A fitted UMAP model can place new observations relative to the learned training structure through its transform procedure. That is useful for a deployment pipeline and differs from rerunning a joint embedding on old and new observations.
Keep training preprocessing, neighbour index and fitted map fixed during held-out evaluation. A new population far from the training support may be attached to the nearest available structure even when no good analogue exists. A successful transform call is not evidence that the new observation belongs to a known group.
If labels are used in supervised UMAP, the representation is supervised. Its evaluation must keep held-out labels outside fitting, and the resulting visual separation cannot be presented as an unsupervised discovery.
Cost, randomness and validation
Approximate nearest-neighbour search and stochastic optimisation make UMAP practical on larger datasets, but runtime and reproducibility depend on the implementation, seed, threading and graph size. Record those settings when exact repeatability matters.
Compare original-space neighbour retention, downstream held-out performance and stability across plausible neighbour counts and seeds. A two-dimensional visualisation is one use; a higher-dimensional embedding for prediction is another and should be tuned for that task.
UMAP is a useful graph-based representation tool when local relationships are meaningful. Compare t-SNE for another neighbourhood-oriented map and PCA for a linear reconstruction baseline. Choose according to the property you need to preserve, not solely the attractiveness of the scatter plot.
Recap
- Understand local scales and fuzzy union of directed neighbours.
- Separate the idealised cross-entropy objective from sampled optimisation.
- Distinguish graph parameters from layout parameters.
- Validate new-point transforms, supervised use and distribution shift explicitly.
References
- McInnes, Healy and Melville. UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction. 2018.
- UMAP authors. Basic UMAP Parameters.
