Tutorials › Statistical Methods for Single-Cell RNA Sequencing › A Worked UMAP Parameter Comparison

Dimension Reduction and Embeddings · Tutorial 220 of 700

A Worked UMAP Parameter Comparison

Compare two UMAP neighbor settings and two minimum-distance settings on one hypothetical cell dataset, tracing what changes in the graph and what changes during embedding.

Intermediate 10 min read

What You'll Learn

  • Trace how increasing the neighbor count can change directed memberships and fuzzy graph weights.
  • Calculate fuzzy-union weights from directed cell-to-cell memberships.
  • Distinguish graph construction effects from low-dimensional spacing effects.
  • Interpret minimum distance through UMAP’s target similarity curve.
  • Diagnose parameter comparisons that confound settings or overstate what an embedding shows.
  • Recognize why changing UMAP parameters does not establish biological structure.

One Dataset, Two Different Kinds of Parameter Change

When a UMAP plot changes after a parameter adjustment, the first question is not simply whether the picture looks better. It is which part of the method changed? The neighbor count changes the construction of the cell-neighbor graph. Minimum distance changes the low-dimensional similarity target used during embedding. These settings can both affect the appearance of the plot, but they act at different stages.

We compare settings on the same hypothetical six-cell dataset. The purpose is to track the logic of the changes, not to predict an exact layout from a particular software implementation. In the hand calculation below, \(k\) denotes the number of other cells considered as neighbors for each cell; software conventions about counting the query cell can differ. Assume the input cell representation, distance definition, initialization, optimization settings, and random seed are held fixed unless stated otherwise.

Definition: In UMAP, \(k\) (often called n_neighbors) controls the size of the neighborhood used to construct the high-dimensional fuzzy graph. Directed memberships are assigned from each cell to its selected neighbors and then combined into undirected fuzzy edge weights. The parameter min_dist controls the target similarity curve in the low-dimensional embedding. It does not change the input-space distances or, by itself, select a different neighbor list.

In the standard construction, each cell has a local offset \(\rho_i\) and a scale \(\sigma_i\). A directed membership for cell \(i\) to a selected neighbor \(j\) has the form

$$ \mu_{i\to j} = \exp\!\left( -\frac{\max(0,d(i,j)-\rho_i)}{\sigma_i} \right), $$

where \(d(i,j)\) is the input-space distance. The local offset accounts for the distance to the nearest neighbors, while \(\sigma_i\) is calibrated so the memberships have a target total related to \(k\), commonly approximately \(\log_2(k)\). The precise numerical graph can depend on implementation details, but the key comparison is stable: changing \(k\) can change both which neighbors are included and the local scale used to assign their memberships.

Worked Example: Changing the Neighbor Count

Worked Example: A New Neighbor Enters the Graph

Suppose cell A has the following increasing input-space distances: B is 1, C is 2, D is 3, E is 4, and F is 5 distance units away. Thus, for \(k=3\), A’s selected neighbors are B, C, and D; for \(k=4\), E is added. The distances and their ordering are unchanged.

For a transparent hand calculation, use a local offset \(\rho_A=1\), and suppose the calibrated scale gives the following illustrative memberships. These values are rounded and are chosen to show the calibration and distance ordering; they are not claimed to be output from a particular software run.

SettingNeighborDistanceDirected membership from A
\(k=3\)B11.000
\(k=3\)C20.414
\(k=3\)D30.172
\(k=4\)B11.000
\(k=4\)C20.544
\(k=4\)D30.296
\(k=4\)E40.161

The \(k=3\) memberships sum to \(1.000+0.414+0.172=1.586\), approximately \(\log_2(3)=1.585\). The \(k=4\) memberships sum to \(1.000+0.544+0.296+0.161=2.001\), approximately \(\log_2(4)=2.000\). In both rows the farther selected neighbors have smaller memberships than closer ones. Under \(k=4\), the memberships of C and D are larger than under \(k=3\), reflecting the changed local calibration as well as the added neighbor E.

This comparison shows why increasing \(k\) is not necessarily equivalent to adding one faint edge while leaving every existing edge unchanged. The neighbor list can expand, and the local membership scale can also change. The example holds distances fixed, so the graph difference is attributable to the neighbor setting and its calibration, not to a change in the cell data.

From Directed Memberships to Fuzzy Edges

UMAP combines the two directed memberships for an unordered pair using the fuzzy union

$$ w_{ij} = \mu_{i\to j}+\mu_{j\to i} -\mu_{i\to j}\mu_{j\to i}. $$

This expression is the probability-style union formula: if the two directed memberships are treated as fuzzy strengths, the combined strength is the first plus the second, minus the overlap counted twice. It is symmetric in \(i\) and \(j\), and it is at least as large as either directed membership when both are between zero and one.

Worked Example: Comparing Fuzzy Edge Weights

Continue the hypothetical calculation. Suppose the reverse directed memberships are \(0.600\) for C to A at \(k=3\), \(0.650\) for C to A at \(k=4\), \(0.300\) for D to A at \(k=3\), and \(0.400\) for D to A at \(k=4\). These values are illustrative and held consistent with the comparison.

For edge A–C at \(k=3\),

$$ w_{AC} = 0.414+0.600-(0.414)(0.600) = 1.014-0.2484 = 0.7656. $$

At \(k=4\),

$$ w_{AC} = 0.544+0.650-(0.544)(0.650) = 1.194-0.3536 = 0.8404. $$

For edge A–D, the corresponding calculations are \(0.172+0.300-(0.172)(0.300)=0.4204\) at \(k=3\), and \(0.296+0.400-(0.296)(0.400)=0.5776\) at \(k=4\). The new A–E edge at \(k=4\), if E’s reverse membership to A is \(0.200\), has weight \(0.161+0.200-(0.161)(0.200)=0.3288\). The arithmetic makes two distinct graph changes visible: an edge can appear because a neighbor is newly selected, and weights on already present edges can change.

These graph weights are inputs to the embedding optimization, not distances in the final plot. A larger fuzzy edge weight gives the optimization a stronger incentive to represent the pair as similar in the low-dimensional space. It does not prescribe a unique coordinate pair or guarantee a particular final separation.

Minimum Distance Changes the Low-Dimensional Target

The low-dimensional part of UMAP assigns similarities to pairs of embedded points according to their separation. A standard form is \(q(d)=1/(1+a d^{2b})\), where \(d\) is low-dimensional distance and the curve parameters \(a\) and \(b\) are fitted to a target controlled by minimum distance \(m\). Conceptually, the target is near one for distances up to \(m\), then decreases as distance grows. The fitted curve is a smooth approximation; the software does not impose a literal hard constraint that every pair of points must be at least \(m\) units apart.

A larger \(m\) keeps the target similarity high over a wider range of low-dimensional distances. In standard UMAP usage, increasing minimum distance generally discourages very tight packing and tends to produce more spread-out groups. That is a tendency of the optimization target, not a guarantee about every realized layout: the graph, optimization, and other settings also matter.

Worked Example: Comparing Two Minimum-Distance Targets

To isolate the target’s direction, use the simple illustrative target \(t_m(d)=1\) for \(d\leq m\), and \(t_m(d)=\exp(-(d-m))\) for \(d>m\). This is a convenient piecewise target for hand calculation, not the exact fitted curve used by every UMAP implementation. Compare \(m=0.05\) and \(m=0.30\), with distances measured in the same arbitrary embedding units.

At \(d=0.20\), the smaller-minimum-distance target is \(t_{0.05}(0.20)=\exp(-(0.20-0.05))=\exp(-0.15)=0.8607\). Since \(0.20\leq0.30\), the larger-minimum-distance target is \(t_{0.30}(0.20)=1.000\). Thus, at this distance the higher-\(m\) target assigns greater similarity.

At \(d=0.50\), the values are \(t_{0.05}(0.50)=\exp(-0.45)=0.6376\) and \(t_{0.30}(0.50)=\exp(-0.20)=0.8187\). Again, the higher-\(m\) target maintains greater similarity at the same distance. The practical interpretation is that larger minimum distance generally discourages extremely tight packing; it is not that the setting directly changes the input graph or guarantees an exact spacing between every pair.

A Controlled Parameter Comparison

A useful comparison changes one setting at a time. For instance, compare \(k=3\) with \(k=4\) while holding minimum distance and the rest of the workflow fixed; then compare two minimum distances while holding \(k\) fixed. This separates graph changes from changes to the low-dimensional target. In a real analysis, also keep the input representation, distance definition, initialization, optimization settings, and random seed fixed when the purpose is to attribute a visual change to a particular parameter.

The expected patterns are qualitative, not deterministic rules. Increasing \(k\) tends to incorporate broader neighborhoods and can connect cells through more distant relationships. A smaller \(k\) emphasizes more immediate neighborhoods. Increasing minimum distance tends to make close embedding arrangements less favored, whereas a smaller value permits tighter packing. Neither parameter alone establishes that visible groups are biological cell types or that their apparent separations are meaningful.

Compared with changing the neighbor count, changing minimum distance leaves the high-dimensional neighbor graph construction unchanged when all graph inputs are held fixed. Conversely, changing \(k\) changes the graph input to optimization, even if the low-dimensional curve is unchanged. This distinction is the main interpretive advantage of comparing the settings separately.

Diagnostics, Failure Modes, and Limits

Before interpreting a parameter comparison, check that the comparison is actually controlled. If the selected neighbors are identical and their directed memberships are nearly unchanged, a proposed explanation based on a major graph restructuring is not supported by the recorded graph. If \(k\) changed, inspect both neighbor identities and edge weights rather than looking only at the final coordinates. For minimum distance, verify that the graph was held fixed; otherwise a visual change cannot be attributed to the low-dimensional target alone.

  • Confounded settings: changing \(k\), minimum distance, and initialization together prevents a clean attribution. Change one setting at a time for a parameter comparison.
  • Assuming the graph is unchanged when \(k\) changes: newly selected neighbors and recalibrated memberships can both alter fuzzy edge weights.
  • Reading minimum distance backward: a higher value maintains high target similarity over a wider distance range and generally discourages very tight packing. It does not mean points can be packed more closely.
  • Treating the embedding as a literal map: low-dimensional coordinates are an optimized representation of graph relationships, not measurements in the original gene-expression space.
  • Overinterpreting one plot: a visual difference is evidence that the representation is parameter-sensitive, not by itself evidence for or against a biological grouping.

The numerical calculations above clarify mechanisms, but they do not determine the best parameter values for a dataset. Real embeddings also reflect approximation in nearest-neighbor search, the shape of the input data, optimization behavior, and stochastic variation. A parameter comparison is most informative when it records both the graph-level change and the embedding-level change, while avoiding claims that the plotted geometry alone proves a biological interpretation.

Key takeaway: Neighbor count acts upstream by changing the fuzzy graph, while minimum distance acts in the low-dimensional similarity target. Separate the two changes, check the graph when \(k\) changes, and treat observed spacing as a consequence of optimization rather than a direct measurement of biological distance.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. For A’s \(k=3\) memberships \(1.000, 0.414, 0.172\), calculate their sum and compare it with \(\log_2(3)\).
  2. If \(\mu_{i\to j}=0.40\) and \(\mu_{j\to i}=0.50\), calculate the fuzzy-union weight.
  3. Does increasing minimum distance change the input-space neighbor list by definition? Explain.
  4. At a fixed low-dimensional distance, what does a higher minimum-distance target generally do to similarity?
  5. A comparison changes both \(k\) and minimum distance, and the plot becomes more spread out. Can that change be attributed to minimum distance alone?

Solutions. (1) The sum is \(1.000+0.414+0.172=1.586\), close to \(\log_2(3)=1.585\). (2) The union is \(0.40+0.50-(0.40)(0.50)=0.70\). (3) No. Minimum distance controls the low-dimensional target; the input-space neighbor list is determined upstream. (4) It generally assigns higher target similarity at the same distance over the affected range, discouraging very tight packing. (5) No. Because both settings changed, the comparison is confounded; change one at a time to isolate its effect.

Clinical Biostats