Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Early Exaggeration and t-SNE Optimization

Dimension Reduction and Embeddings · Tutorial 214 of 700

Early Exaggeration and t-SNE Optimization

Understand how t-SNE optimization moves cell coordinates, why early exaggeration changes the initial forces, and how to distinguish tuning problems from patterns supported by the input similarities.

Intermediate 10 min read

What You'll Learn

  • Interpret the t-SNE gradient as a balance of attractive and repulsive forces.
  • Calculate a coordinate update with and without early exaggeration.
  • Explain why early exaggeration is temporary and does not define a new probability distribution.
  • Diagnose learning rates and iteration counts that make optimization unstable or incomplete.
  • Separate optimization symptoms from evidence of structure in the input similarities.
  • Compare early exaggeration with ordinary gradient descent and PCA.

What Optimization Controls

t-SNE assigns each cell a location in a low-dimensional space so that similarities between cells in that space correspond, as far as possible, to similarities specified by the input. The earlier material on the t-SNE pairwise similarity model and the KL divergence defines the high-dimensional similarities \(p_{ij}\), low-dimensional similarities \(q_{ij}\), and objective \(C=\sum_{i\ne j}p_{ij}\log(p_{ij}/q_{ij})\). This tutorial focuses on how optimization changes the coordinates: the gradient descent update, its learning rate and number of iterations, and the temporary modification called early exaggeration.

The optimization choices matter because a plotted arrangement is the outcome of both the input similarities and a numerical procedure. If the procedure has barely moved the coordinates, or has taken unstable steps, the resulting picture may not reflect a well-optimized embedding. Conversely, changing the optimization settings can change the appearance without changing the input similarities. An embedding is therefore not, by itself, evidence that a particular biological grouping is real.

Definition: For \(n\) cells, let \(y_i\) be the low-dimensional coordinate of cell \(i\), and let \(p_{ij}\) and \(q_{ij}\) be symmetric pairwise similarities with \(p_{ii}=q_{ii}=0\) and \(\sum_{i\ne j}p_{ij}=\sum_{i\ne j}q_{ij}=1\). With \(w_{ij}=(1+\lVert y_i-y_j\rVert^2)^{-1}\), the low-dimensional similarities are \(q_{ij}=w_{ij}/Z\), where \(Z=\sum_{k\ne l}w_{kl}\). The t-SNE gradient for coordinate \(y_i\) is \(4\sum_{j\ne i}(p_{ij}-q_{ij})w_{ij}(y_i-y_j)\).

Why the Gradient Moves Cells

The gradient combines two effects. When \(p_{ij}>q_{ij}\), the pair receives a net attractive contribution: the gradient term points in the direction that gradient descent moves \(y_i\) toward \(y_j\). When \(p_{ij}<q_{ij}\), the contribution is net repulsive. The factor \(w_{ij}\) reduces the contribution of distant pairs. Each cell’s movement reflects the combined contributions from all other cells, not a separate instruction to form a particular cluster.

A short derivation makes the normalization’s role explicit. Since \(q_{ij}=w_{ij}/Z\), the objective can be written as \(\sum_{i\ne j}p_{ij}\log p_{ij}-\sum_{i\ne j}p_{ij}\log w_{ij}+\log Z\). The first term is constant with respect to the coordinates. Differentiating the second term, using symmetry of \(p_{ij}\), gives \(4\sum_{j\ne i}p_{ij}w_{ij}(y_i-y_j)\). Differentiating \(\log Z\), including both appearances of \(y_i\) in the ordered-pair sum for \(Z\), gives \(-4\sum_{j\ne i}q_{ij}w_{ij}(y_i-y_j)\). Adding the two derivatives yields the stated gradient.

In simple gradient descent, a coordinate is updated by subtracting the learning rate times its gradient. The learning rate controls the step size; it does not change which pairs have large or small input similarity. Practical t-SNE implementations may also use momentum or adaptive gains, so an update in a particular software package can be more elaborate than this basic equation.

Worked Example: One Coordinate Update With Exaggerated Similarities

Consider three cells at one-dimensional coordinates \(y_1=0\), \(y_2=1\), and \(y_3=3\). For a transparent calculation, start with six symmetric raw weights: each direction of pair 1–2 has weight 0.4, each direction of pair 1–3 has weight 0.4, and each direction of pair 2–3 has weight 0.1. Their total is \(2(0.4+0.4+0.1)=1.8\), not 1. They are raw weights, so normalize them before treating them as \(p_{ij}\).

After dividing each entry by 1.8, the directed similarities are \(p_{12}=p_{21}=0.2222\), \(p_{13}=p_{31}=0.2222\), and \(p_{23}=p_{32}=0.05556\). These six normalized entries sum to 1. The low-dimensional unnormalized weights for pairs 1–2, 1–3, and 2–3 are respectively \(1/2=0.5\), \(1/10=0.1\), and \(1/5=0.2\). Thus \(Z=2(0.5+0.1+0.2)=1.6\), giving \(q_{12}=0.3125\) and \(q_{13}=0.0625\).

For cell 1, the ordinary gradient is \(4[(0.2222-0.3125)(-1)(0.5)+(0.2222-0.0625)(-3)(0.1)]\). The two terms inside the brackets are approximately \(0.04514\) and \(-0.04792\), so \(g_1\approx-0.01111\).

Now use exaggeration factor \(\alpha=4\), which replaces \(p_{1j}\) by \(\alpha p_{1j}\) in the attractive part of the gradient. The cell-1 gradient becomes \(4[(0.8889-0.3125)(-1)(0.5)+(0.8889-0.0625)(-3)(0.1)]\approx-2.144\). With learning rate \(\eta=0.1\), the basic update for this coordinate is \(y_1^{\mathrm{new}}=0-0.1(-2.144)=0.2144\). This is just the cell-1 component of an update: a full iteration updates all coordinates. It illustrates how exaggeration can substantially strengthen the attractive contribution while leaving the repulsive \(q\) term in place.

Early Exaggeration Is Temporary

Early exaggeration multiplies the attractive high-dimensional similarities by a factor \(\alpha>1\) during an initial phase. In the gradient, the change is from \(p_{ij}-q_{ij}\) to \(\alpha p_{ij}-q_{ij}\). It is a temporary optimization device, commonly used to encourage strongly similar points to move together early in the run. The factor and duration vary across implementations and analyses; they are settings to report, not universal constants.

The exaggerated values \(\alpha p_{ij}\) do not sum to 1 when \(\alpha>1\). They are not a new probability distribution. Early exaggeration modifies the attractive force in the optimization; after the designated initial phase, the usual gradient with \(p_{ij}\) is used. Continuing to exaggerate throughout the run changes the optimization rather than simply giving it more time.

Worked Example: How Exaggeration Changes One Pair’s Force

Suppose a pair has \(p_{ij}=0.20\) and \(q_{ij}=0.10\) at a particular iteration. Ignoring the common positive factor \(4w_{ij}\), the coefficient in the ordinary gradient is \(p_{ij}-q_{ij}=0.20-0.10=0.10\). With \(\alpha=4\), it is \(\alpha p_{ij}-q_{ij}=4(0.20)-0.10=0.70\). The pair’s attractive contribution is therefore seven times as large at this fixed configuration.

This calculation is conditional on the coordinates being fixed. As optimization proceeds, \(q_{ij}\), distances, and the gradients change, so the force does not remain seven times larger at every later step. It also does not establish that the pair belongs to a biological group; it only shows how the chosen optimization phase changes the update.

Learning Rate and Iteration Count

A learning rate that is too small can make coordinate movement negligible over the available iterations. A rate that is too large can overshoot, cause oscillation, or produce unstable movement. The appropriate scale depends on the implementation, the data size, initialization, and other optimizer settings; a numerical value should not be treated as universally safe.

A one-dimensional quadratic provides a controlled illustration of step size, not a replacement model for t-SNE. Let \(f(x)=(x-2)^2/2\), whose gradient is \(x-2\), and start at \(x_0=0\). With \(\eta=0.5\), \(x_1=0-0.5(-2)=1\), and \(x_2=1-0.5(-1)=1.5\): the steps approach the minimum at 2. With \(\eta=2\), \(x_1=4\) and \(x_2=0\), so the iteration oscillates instead of settling. The example shows why more iterations cannot necessarily rescue an unstable step size.

Iteration count controls how long the optimizer runs, not how many clusters the data contain. Too few iterations may leave coordinates in an early transient configuration; a large iteration count does not guarantee a global optimum or a biologically meaningful picture. Assess progress using optimization diagnostics, such as the objective and coordinate or gradient movement, rather than stopping solely because a plot looks separated.

Worked Example: Recognizing Incomplete Optimization

For the same quadratic \(f(x)=(x-3)^2/2\), start at \(x_0=0\) and use \(\eta=0.5\). The updates are \(x_{t+1}=x_t-0.5(x_t-3)\). Thus \(x_1=1.5\), \(x_2=2.25\), and \(x_3=2.625\). The objective values are \(f(x_0)=4.5\), \(f(x_1)=1.125\), \(f(x_2)=0.2813\), and \(f(x_3)=0.07031\).

The objective decreases at each shown step, but after three iterations the coordinate is still not at the minimum \(x=3\). In an embedding, a rapidly changing objective or substantial coordinate movement at termination is a reason to check whether the run was long enough. Conversely, a stable objective alone is not proof that the embedding has found a unique or globally optimal arrangement.

Diagnostics, Alternatives, and Limits

Optimization diagnostics help distinguish a computational problem from a pattern in the similarities. A useful check is to inspect the objective trajectory and coordinate movement over iterations, including the transition out of early exaggeration. Large oscillations or unusually large steps suggest that the learning rate or other optimizer settings may be unsuitable. Minimal movement together with little progress can indicate a rate that is too small or an insufficient iteration count. If an implementation reports numerical warnings or non-finite coordinates, the run should not be interpreted as a valid embedding.

When a display looks surprising, first check that the intended input similarities and settings were used, that exaggeration ended as intended, and that optimization had sufficient opportunity to progress. Then distinguish what the display can support: t-SNE optimizes local similarity representation, not a hypothesis test for cell types, and it does not establish causation. The embedding coordinates and inter-island distances should not be treated as direct measurements in the original gene-expression space.

ApproachWhat changesKey consideration
Ordinary t-SNE gradient descentUses \(p_{ij}-q_{ij}\) throughout optimizationDoes not have the temporary increase in attractive force used by early exaggeration.
t-SNE with early exaggerationTemporarily uses \(\alpha p_{ij}-q_{ij}\), then returns to the ordinary gradientCan change the optimization trajectory; it does not add evidence to the input similarities.
PCAFinds linear directions of high variance rather than optimizing the t-SNE similarity objectiveProvides a different representation and objective; it is not a t-SNE convergence diagnostic.

A practical limitation is that these optimization settings interact: the same learning rate and iteration count need not behave identically for different inputs or implementations. There is no universal visual criterion for a correct embedding. Report the relevant optimization settings and use the input similarities and scientific context, rather than the appearance alone, to evaluate a pattern.

Common pitfall: “The points separated during early exaggeration, so the data prove that they form distinct biological clusters.” The reasoning confuses an optimization phase with evidence about biology. Early exaggeration changes attractive forces temporarily; separation in a two-dimensional embedding is not a statistical test. Check optimization progress and interpret the display alongside evidence in the original data.

Check Your Understanding

Try each problem, then compare your reasoning with the solutions.

  1. If \(p_{ij}=0.15\), \(q_{ij}=0.05\), and \(\alpha=3\), what is the pair’s gradient coefficient before and during exaggeration, excluding the common factor \(4w_{ij}\)?
  2. A run ends while coordinates are still moving substantially and the objective is changing. What is one reasonable next diagnostic step, and why is “the plot looks clustered” not enough to establish convergence?
  3. Explain why multiplying all \(p_{ij}\) by an exaggeration factor does not create a probability distribution when that factor exceeds 1.
  4. In the quadratic example \(f(x)=(x-2)^2/2\), starting at \(x_0=0\) with \(\eta=0.5\), compute \(x_1\) and \(x_2\). What do they show?

Solutions. (1) Before exaggeration the coefficient is \(0.15-0.05=0.10\); during exaggeration it is \(3(0.15)-0.05=0.40\). (2) Inspect the objective and coordinate movement and consider whether the run needs more iterations or a different learning rate; a visual arrangement is not an optimization diagnostic and does not validate biological groupings. (3) The original \(p_{ij}\) sum to 1, so the exaggerated values sum to \(\alpha\), which exceeds 1; they are temporary force weights, not normalized probabilities. (4) \(x_1=0-0.5(0-2)=1\), and \(x_2=1-0.5(1-2)=1.5\). The updates approach the minimum at 2, illustrating how step size and iteration count jointly determine progress.

Clinical Biostats