Worked examples — t-SNE for visualization
This page is the worked-example workbench for t-SNE for visualization. The parent note built the machinery: the high-D neighbor probability , the low-D t-distributed , and the KL divergence cost. Here we drive that machinery through every kind of input it can meet — small numbers, big numbers, ties, zeros, degenerate cases, and real datasets — so you never hit a scenario you haven't seen.
Before anything, one reminder in plain words. A probability here is just a number between and answering "if point had to point at exactly one neighbor, how likely is it to point at ?" We compute these numbers from distances. The symbol means "square the straight-line distance between the two data points" — add up the squared differences of every coordinate. That's the only raw ingredient.
The scenario matrix
Every t-SNE question falls into one of these cells. The examples below are labelled with the cell they cover.
| Cell | What makes it special | Covered by |
|---|---|---|
| C1 Near vs far pair | one close neighbor, one distant one → big vs tiny | Ex 1 |
| C2 Zero distance / identical points | → what happens to ? | Ex 2 |
| C3 Self term | the degenerate "point picks itself" case | Ex 2 |
| C4 Perplexity = effective neighbor count | small vs large | Ex 3 |
| C5 Symmetrization giving valid distribution | check | Ex 4 |
| C6 Gaussian vs t-tail (crowding) | far point contribution compared | Ex 5 |
| C7 Gradient sign: pull vs push | vs | Ex 6 |
| C8 Limiting behaviour of the gradient | distance and | Ex 7 |
| C9 Real-world word problem | MNIST-style scaling / Barnes-Hut | Ex 8 |
| C10 Exam twist: misreading the plot | global distance trap | Ex 9 |
Example 1 — C1: a near neighbor and a far neighbor
Forecast: which one gets the bigger probability, and by roughly how much — 2×? 10×? 50×?
Steps.
-
Write each unnormalized similarity . Why this step? The numerator of is exactly this Gaussian bump — it turns "distance" into "closeness", big when distance is small.
-
Normalize by their sum so the two probabilities add to . Why this step? The denominator forces the conditional distribution to be valid — point must pick some neighbor.
Verify: ✓. The near point is more likely — the Gaussian crushes far points. This is why t-SNE is a local method.
Example 2 — C2 & C3: identical points and the self term
Forecast: does zero distance give probability or the maximum possible similarity?
Steps.
-
Plug distance into the Gaussian: . Why this step? Distance means "same location", which should mean maximum closeness — and indeed is the largest value the bump reaches. Zero distance is the peak, not a hole.
-
The self term would be too — the biggest of all. We set by hand (the sum runs over ). Why this step? A point picking itself as a neighbor is meaningless; if we left it in, every point would mostly point at itself and we'd learn nothing about structure.
Verify: ✓, and it is the maximum of for ✓. Degenerate "same point" inputs are safe: they simply get the top similarity, never a divide-by-zero.
Example 3 — C4: perplexity sets the neighborhood width
Forecast: with the tiny , will the closest neighbor grab almost all the probability, or will it be shared?
Steps.
-
Small . Compute : Normalize: Why this step? A narrow Gaussian only "sees" the very nearest point — this is low perplexity, hyper-local.
-
Large . Compute : Sum , so Why this step? A wide Gaussian spreads probability across all four — this is high perplexity, broader neighborhoods.
Verify: each distribution sums to ✓. Small → one dominant neighbor; large → probability spread out. This is precisely what perplexity tunes (manifold scale). Compare with the hard "assign to nearest center" rule of K-Means — t-SNE's assignment is soft.
Example 4 — C5: symmetrization gives a valid joint distribution
Forecast: three unordered pairs exist ; will their symmetrized values add to exactly ?
Steps.
-
Pair : . Why this step? Averaging the two directions removes any "who chose whom" bias; dividing by rescales so the whole table sums to one.
-
Pair : .
-
Pair : .
-
The full sum counts each unordered pair twice ():
Verify: total ✓. is a legal probability distribution — a hard prerequisite for KL divergence to even be defined.
Example 5 — C6: Gaussian vs t-distribution tail (the crowding fix)

Forecast: the heavy tail should keep far points "visible" — by what factor?
Steps.
-
Gaussian value: — essentially vanished. Why this step? A Gaussian in 2D would force moderately-far points to have almost zero similarity, so the optimizer would cram them near the center — the crowding problem.
-
t-distribution value: — a thousand times larger. Why this step? The heavy tail says "you're far, but not invisible." Look at the orange curve in the figure: it stays well above the blue Gaussian for large distances. That extra weight gives clusters room to spread apart.
-
Ratio: .
Verify: ratio ✓. This single design choice is why t-SNE separates clusters cleanly where a Gaussian-Gaussian method (UMAP chooses a related but different low-D kernel) would smear them.
Example 6 — C7: gradient sign decides pull vs push
Forecast: means "should be closer than they are" — pull or push?
Steps.
-
Plug into for the single pair: Why this step? The gradient is the direction of increasing cost; gradient descent moves opposite to it.
-
Since the gradient points in , descent moves in — toward (which lies in the direction from ). Why this step? means the map has them too far apart; the update pulls them together, restoring the local neighborhood.
Verify: gradient , so update direction → toward ✓. The sign of is the whole story: positive → attraction, negative → repulsion.
Example 7 — C8: limiting behaviour of the attractive force

Forecast: does the pull grow forever as points get further, or fade?
Steps.
-
As : . Why this step? Points already on top of each other feel no force — nothing to fix. Look at the left end of the curve in the figure hugging zero.
-
As : . Why this step? Very distant points feel a vanishing attraction — the decay from the t-kernel prevents runaway pulling and keeps the optimization stable.
-
Maximum: set . Why this step? The force peaks at moderate separation — exactly where a cluster needs the most tidying.
Verify: , and at both ends ✓ (peak at , the red dot in the figure). Both degenerate limits are graceful: no blow-up, no divide-by-zero.
Example 8 — C9: real-world scaling word problem (MNIST)
Forecast: billions of pairs — is exact even feasible?
Steps.
-
Number of unordered pairs — about billion. Why this step? Every pair contributes a term; this is why exact t-SNE chokes on large .
-
Speedup . Now . Why this step? Barnes-Hut approximates the many-far-away forces as a single lumped force, turning quadratic into near-linear work — the reason large-scale t-SNE is practical.
Verify: pairs ✓; speedup ✓. This is the trade discussed in the parent's comparison table; if you need a parametric map for new points instead, reach for autoencoders.
Example 9 — C10: exam twist — reading the plot correctly
Forecast: trap or truth?
Steps.
-
Recall the cost is which heavily penalizes breaking local structure but is nearly blind to how far apart two separated clusters land. Why this step? The between-cluster gaps are not calibrated to any real distance; the optimizer only cared about keeping neighbors together.
-
Therefore the numbers and carry no metric meaning. The valid readings are: A, B, C are distinct clusters; within-cluster tightness and cluster existence are trustworthy; global spacing is not. Why this step? This is the single most common misuse of t-SNE, straight from the parent's "Mistake 1".
Verify: conclusion is invalid ✓ — global inter-cluster distance in a t-SNE plot is not interpretable; only local neighborhoods and cluster separation are.
Recall Quick self-test
Zero distance gives unnormalized similarity of what? ::: , the maximum. triggers which force? ::: Attraction (pull the pair together). Where does the attractive per-pair force peak (in )? ::: At . Number of pairs for ? ::: billion. Is inter-cluster distance in a t-SNE plot meaningful? ::: No — only local structure is.