Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Random Seeds and Embedding Variability

Dimension Reduction and Embeddings · Tutorial 226 of 700

Random Seeds and Embedding Variability

Compare repeated embeddings fairly by separating coordinate orientation from meaningful changes in local neighborhoods and overall layout.

Intermediate 10 min read

What You'll Learn

  • Identify which sources of randomness can differ between embedding runs.
  • Explain why translation, rotation, and reflection can change a plot without changing its pairwise geometry.
  • Align two runs without confusing alignment with structural stability.
  • Calculate neighborhood overlap between repeated runs.
  • Interpret changes in neighborhood and island organization cautiously.
  • Recognize when run-to-run comparisons are confounded by changed inputs or settings.

Why Repeat an Embedding?

A t-SNE or UMAP plot is the result of an optimization, not a unique coordinate map guaranteed by the data. Different random seeds can change the starting coordinates, the order of stochastic updates, or other randomized steps. Approximate neighbor-search procedures may introduce further variation. As a result, two runs on the same cells can look different even when the input data and nominal parameters are unchanged.

Some visible differences are only changes of orientation: one plot may be rotated, reflected, or shifted relative to the other. Other differences are more substantive: a cell may acquire different nearby cells, or groups of cells may be arranged or separated differently. A careful comparison distinguishes these cases rather than judging stability by whether two plots look alike on screen.

To attribute differences to random initialization or optimization, hold the cells, input representation, preprocessing, distance metric, parameters, software implementation, and other settings fixed. If any of these change, a difference between plots cannot be attributed to the seed alone. Record the seed and settings for each run. Exact reproducibility may also depend on software versions, hardware, parallel computation, and deterministic implementation details.

Definition: Run-to-run variability is the difference among embeddings produced from the same cells and fixed analysis settings when randomized elements of the algorithm vary. It can appear as a change in coordinates, local neighborhoods, or broader layout. A coordinate difference alone does not establish a structural difference.

Coordinate Symmetries and Meaningful Change

Both t-SNE and UMAP optimize objectives based on relationships among points in the low-dimensional embedding. For their usual Euclidean layouts, translating every point by the same vector, rotating all points, or reflecting them preserves all pairwise distances. A plot can therefore have different coordinates while representing exactly the same geometry. In two dimensions, a rotation or reflection is represented by an orthogonal matrix \(Q\), satisfying \(Q^\mathsf{T}Q=I\). Translation adds a vector \(b\).

$$ y_i' = Qy_i+b $$

Because \(\lVert y_i'-y_j'\rVert=\lVert Q(y_i-y_j)\rVert=\lVert y_i-y_j\rVert\), every pairwise distance is unchanged. The objectives used by t-SNE and UMAP depend on the embedded pairwise relationships, so these rigid transformations do not change the objective value. This explains why orientation and position on the page are not substantive evidence of a changed embedding.

Scaling is different: multiplying all coordinates by a constant generally changes pairwise distances and is not one of these symmetries. Nor does the invariance result imply that two optimization runs will reach the same solution up to a rigid transformation. The objectives can have multiple configurations with different neighborhoods or layouts. Thus, after accounting for translation, rotation, and reflection, remaining differences still need to be assessed rather than automatically dismissed.

Worked Example: Recognizing a Reflected and Shifted Plot

Suppose three cells have coordinates in run 1: \(A=(0,0)\), \(B=(2,0)\), and \(C=(0,1)\). In run 2 their coordinates are \(A'=(5,-3)\), \(B'=(5,-1)\), and \(C'=(4,-3)\). Determine whether these coordinates indicate a changed configuration.

The run 2 coordinates arise by reflecting across the vertical axis, then translating by \((5,-3)\): \((x,y)\mapsto(-x,y)+(5,-3)\). For example, \(B=(2,0)\) maps to \((-2,0)+(5,-3)=(3,-3)\), which does not match \(B'\). So that proposed reflection is not the transformation. Instead, use a 90-degree rotation, \((x,y)\mapsto(-y,x)\), followed by translation: \(A\mapsto(0,0)+(5,-3)=(5,-3)\), \(B\mapsto(0,2)+(5,-3)=(5,-1)\), and \(C\mapsto(-1,0)+(5,-3)=(4,-3)\). All three match run 2.

The pairwise distances verify the conclusion: \(AB=2\), \(AC=1\), and \(BC=\sqrt{5}\) in run 1; the corresponding distances in run 2 are also \(2\), \(1\), and \(\sqrt{5}\). The coordinate differences are entirely explained by rotation and translation, so this example shows no change in pairwise geometry.

Comparing Runs Fairly

A useful comparison has two distinct parts. First, determine whether plots differ mainly by a rigid coordinate transformation. Second, compare structural summaries that do not depend on orientation, especially which cells are neighbors. Cell identifiers must match across runs; comparing points by row position is unsafe if cell ordering changed.

One way to assess orientation is to align one set of coordinates to the other using a rigid Procrustes alignment: choose a translation and an orthogonal transformation that minimize the summed squared coordinate differences for corresponding cells. Allowing reflections is appropriate when the purpose is to remove orientation ambiguity. Do not allow arbitrary scaling if the question is whether runs differ only by a distance-preserving symmetry. Small residual differences after alignment are not, by themselves, a complete measure of biological or structural agreement; the scale and geometry of the embedding also affect coordinate residuals.

For a direct local-structure comparison, define the \(k\)-nearest-neighbor set \(N_i^{(r)}(k)\) for cell \(i\) in run \(r\): the \(k\) other cells closest to \(i\) in that run’s embedding. A standard comparison for that cell is the Jaccard similarity, the size of the intersection divided by the size of the union of the two neighbor sets. Averaging this value across cells summarizes neighborhood retention. This is a descriptive comparison for a specified \(k\), not an inferential test or a universal threshold for acceptable stability.

$$ J_i(k)= \frac{\left|N_i^{(1)}(k)\cap N_i^{(2)}(k)\right|} {\left|N_i^{(1)}(k)\cup N_i^{(2)}(k)\right|}, \qquad \overline{J}(k)=\frac{1}{n}\sum_{i=1}^{n}J_i(k) $$

Worked Example: Calculating Neighborhood Agreement

For four hypothetical cells, suppose the neighbor sets for \(k=3\) are as follows. In run 1, \(N_A=\{B,C,D\}\), \(N_B=\{A,C,D\}\), \(N_C=\{A,B,D\}\), and \(N_D=\{A,B,C\}\). In run 2, the respective sets are \(\{B,C,E\}\), \(\{A,C,E\}\), \(\{A,B,E\}\), and \(\{A,E,F\}\). Calculate the mean Jaccard similarity.

For \(A\), the intersection is \(\{B,C\}\), of size 2, and the union is \(\{B,C,D,E\}\), of size 4, giving \(J_A=2/4=0.50\). The same intersection and union sizes apply to \(B\) and \(C\), so \(J_B=J_C=0.50\).

For \(D\), the intersection is \(\{A\}\), of size 1, and the union is \(\{A,B,C,E,F\}\), of size 5, giving \(J_D=1/5=0.20\). Therefore,

$$ \overline{J}(3)=\frac{0.50+0.50+0.50+0.20}{4} =\frac{1.70}{4}=0.425 $$

The mean overlap is 0.425 for these four cells at \(k=3\). It indicates partial neighborhood agreement in this small hypothetical example; it is not a probability that the embeddings are “the same.” The value depends on \(k\), the cells included, and the neighbor sets observed.

What to Compare Beyond Coordinates

Neighborhood overlap is often more informative than visual similarity because it is unchanged by translation, rotation, or reflection. Still, one summary can conceal local differences: a high average may coexist with a small set of cells whose neighbors change substantially. Inspect the distribution of \(J_i(k)\), including low values, and consider whether conclusions change over a small, prespecified range of \(k\). The purpose is to check whether the local pattern of interest persists, not to search for a favorable value.

Island layout also requires care. Compare whether apparent groups contain similar cells and whether separations or mergers recur across runs, but do not treat a change in the page position of an island as a change in the data. Distances between embedding islands are unreliable measures of between-group similarity, so their relative spacing or orientation should not be used as a stability criterion on its own. A split or merge accompanied by changed local neighborhoods is more substantive than a rigid movement of an otherwise unchanged island.

Repeated runs of t-SNE should be compared with other t-SNE runs using the same settings; repeated UMAP runs should likewise be compared within UMAP. Differences between algorithms are not seed variability. The algorithms optimize different objectives, so a cross-method comparison answers a different question and should not be substituted for a controlled seed comparison.

Worked Example: Interpreting Different Repeated-Run Summaries

A researcher runs each method twice on the same hypothetical cell representation with the same within-method settings. After rigid alignment, the t-SNE plots have similar island membership and a mean \(k=10\) neighborhood Jaccard similarity of 0.82. The UMAP plots have visibly similar overall islands, but their mean \(k=10\) neighborhood Jaccard similarity is 0.54; several cells have values below 0.20. What can be concluded?

For t-SNE, the high average overlap and similar island membership support the description that these two runs retain many local neighbors. They do not prove that every cell or every aspect of the embedding is stable; the lower tail of cell-level overlap should still be examined.

For UMAP, similar-looking islands do not establish stable local neighborhoods. An average of 0.54 indicates more disagreement in the selected neighbor sets than in the t-SNE pair, and values below 0.20 flag cells for closer inspection. Because each method is being compared only with its own repeated run, this does not show that t-SNE is generally more stable than UMAP. It describes these particular runs, settings, and \(k\). The researcher should verify cell matching and fixed inputs, then report the method-specific summaries and the variation among cells.

Diagnostics, Pitfalls, and Limits

A run comparison is most useful when it can distinguish random variation from a change in the analysis itself. Check that the same cells and cell identifiers were used, the same features and preprocessing were applied, and all algorithm settings besides the intended seed were held fixed. Then inspect both the aligned plots and neighborhood summaries. If neighbor overlap is poor, determine whether the differences are widespread or concentrated in particular regions or cells; do not explain them away merely because the overall plot appears familiar.

  • Confounded settings: changing perplexity, neighborhood size, metric, input representation, or other parameters alongside the seed prevents attributing the difference to randomness alone.
  • Misleading overlays: plotting raw coordinates without alignment can make a simple rotation or shift look like a major change. Conversely, alignment can make plots look deceptively similar if local neighborhoods have changed.
  • Cell-order errors: matching cells by row number rather than a stable identifier can produce meaningless coordinate residuals and neighbor comparisons.
  • Overinterpreting a single summary: a mean overlap conceals cell-level variability and depends on \(k\); report what was compared and inspect the distribution.
  • Assuming a seed guarantees exact replication: software, hardware, parallel execution, and approximate computations can matter. Record these details when reproducibility is important.

Run-to-run comparisons are diagnostic, not a formal test of a biological hypothesis. A small number of seeds does not define a sampling distribution for the embedding, and a mean overlap does not provide a confidence interval for a population parameter. These checks also cannot establish that a stable pattern is biologically meaningful: they assess reproducibility under chosen computational settings, not scientific validity.

Common mistake: “The second plot is rotated, so the seed produced a different cell structure.” A rotation preserves every pairwise distance and neighbor relation. Align the plots or compare neighbor sets before deciding that structure changed. The reverse mistake is also possible: “The islands look alike, so the runs agree.” Similar island outlines do not ensure that the same cells have the same nearest neighbors.
1
Fix the comparison.
Hold the input cells, representation, preprocessing, metric, parameters, and implementation constant; vary the seed deliberately.
2
Match cells and account for orientation.
Use stable cell identifiers and, if comparing coordinates, align runs with translation and an orthogonal transformation without scaling.
3
Check structure.
Compare neighborhood sets at a stated \(k\), inspect cell-level agreement, and interpret island changes without relying on island distances.
4
Report limitations.
State the number of runs, settings, and comparison summary; distinguish within-method seed variability from between-method differences.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. Why can two embeddings have different coordinates but exactly the same pairwise geometry?
  2. For two cells, the first run has neighbor set \(\{B,C,D\}\) and the second has \(\{B,D,E\}\). Calculate their Jaccard similarity.
  3. Why is a high mean neighborhood overlap not enough to conclude that every cell is stable?
  4. A t-SNE run and a UMAP run look different. Does this establish seed variability? Explain.
  5. What must be held fixed to attribute differences between two runs to the random seed?

Solutions. (1) A shared translation and an orthogonal transformation preserve pairwise distances: \(\lVert Q(y_i-y_j)\rVert=\lVert y_i-y_j\rVert\). (2) The intersection is \(\{B,D\}\), of size 2, and the union is \(\{B,C,D,E\}\), of size 4, so \(J=2/4=0.50\). (3) An average can conceal cells with very low overlap; inspect cell-level values or their distribution. (4) No. The algorithms optimize different objectives, so this is a between-method comparison, not a controlled repeated-seed comparison. (5) Hold the cells, input representation, preprocessing, metric, parameters, software implementation, and other settings fixed, varying only the seed as far as the implementation permits.

Clinical Biostats