t-SNE: Neighbour Probabilities, Perplexity and Reading the Map Correctly

5 minute read

Published:

TL;DR: t-SNE places observations in a low-dimensional map by matching neighbourhood probabilities. Its objective strongly penalises separating pairs that were close in the original representation. It is useful for exploration, but distances between islands, apparent density and cluster sizes are not generally preserved measurements.

A map for neighbourhood inspection

Suppose an embedding has hundreds of coordinates. A two-dimensional scatter plot can help inspect nearby examples, possible subgroups and obvious errors. t-SNE creates such a plot by translating distances into probabilistic neighbourhood relationships and then fitting a low-dimensional arrangement.

The representation supplied to t-SNE already defines similarity. If it encodes acquisition batch or document length more strongly than semantics, the plot can reveal those properties very clearly. The embedding algorithm cannot decide which relationships are scientifically meaningful.

High-dimensional neighbours receive probabilities

For distinct observations i and j, define a conditional affinity

\[ p_{j\mid i}=\frac{\exp(-\|x_i-x_j\|^2/(2\sigma_i^2))} {\sum_{l\ne i}\exp(-\|x_i-x_l\|^2/(2\sigma_i^2))}, \qquad p_{i\mid i}=0. \]

Each observation has its own bandwidth. The symmetric joint probability is \(p_{ij}=(p_{j\mid i}+p_{i\mid j})/(2n)\). Dense and sparse regions can therefore be assigned different local scales before the two-dimensional optimisation begins.

This adaptive scaling is part of why apparent plot density is not a direct estimate of original-space density. A dense region can be expanded and a sparse one compressed to make their local neighbourhood structures comparable.

Perplexity controls effective neighbourhood size

The conditional distribution’s perplexity is

\[ \operatorname{Perp}(P_i)=2^{H(P_i)},\qquad H(P_i)=-\sum_jp_{j\mid i}\log_2p_{j\mid i}. \]

If four neighbours have equal probability 1/4, entropy is two bits and perplexity is four. A peaked distribution can have lower perplexity even when many neighbours have nonzero probability.

The algorithm adjusts bandwidths toward a requested perplexity. It is an effective neighbourhood scale, not an exact count of edges and not the expected number of clusters. It must be sensible relative to sample size, and no single value is universally correct.

Low-dimensional affinities use a heavy tail

For map coordinates \(y_i\), t-SNE uses a Student-t-style kernel with one degree of freedom:

\[ q_{ij}=\frac{(1+\|y_i-y_j\|^2)^{-1}} {\sum_{a\ne b}(1+\|y_a-y_b\|^2)^{-1}}. \]

The heavy tail helps address the crowding problem: many moderately distant high-dimensional neighbours cannot all fit at comparable radii around one point in two dimensions. The kernel allows a broader range of low-dimensional separations than a Gaussian affinity would.

The map is fitted by minimising

\[ \operatorname{KL}(P\|Q)=\sum_{i\ne j}p_{ij}\log\frac{p_{ij}}{q_{ij}}. \]

If a pair has substantial p but tiny q, its loss contribution is large. Pairs with tiny p receive much less direct weight. The asymmetric objective therefore focuses on retaining important neighbours rather than uniformly preserving every pairwise distance.

A probability mismatch example

For a pair with p=0.2, reducing q from 0.2 to 0.02 changes its contribution from zero to \(0.2\log10\approx0.461\). For a pair with p=0.002, the same factor-of-ten discrepancy contributes only about 0.00461.

Individual terms can be negative when q exceeds p; the full KL divergence remains nonnegative for properly normalised distributions. Looking at one attractive or repulsive interaction alone does not explain the complete optimisation, because q’s denominator couples every pair.

Optimisation and reproducibility

The objective is nonconvex. Initialisation, learning rate, early exaggeration, iteration count and approximation settings can affect the result. Early exaggeration temporarily increases attractive affinity weights to help organise the map; it is an optimisation phase, not an additional observed relationship.

Repeat plausible settings and seeds. A low reported loss is useful for diagnosing optimisation under fixed conditions, but losses across different perplexities or datasets are not directly interchangeable because the target distribution P has changed.

Exact pairwise calculations are expensive. Tree-based or interpolation-based approximations reduce cost with their own accuracy and dimensionality constraints. Record the implementation and method rather than treating every plot labelled t-SNE as computationally identical.

What a plotted island does not prove

Separated islands can suggest examples worth inspecting. Their separation is not a calibrated inter-cluster distance, their area does not measure original variance, and their point density is not generally original probability density. Rotations and translations of the entire map have no meaning.

A continuous manifold can appear fragmented, especially under some neighbourhood and optimisation choices. Conversely, local structure can be hard to see when the input representation loses it. Do not choose a cluster count solely by counting islands and then present the same plot as independent validation of that choice.

A responsible workflow

Fit preprocessing on the intended population and preserve the original features. Inspect plots across perplexities, use labels only as explicitly disclosed annotations, and compare neighbourhood preservation with quantities such as trustworthiness plus original-space examples.

If evaluating a predictive pipeline, do not embed training and held-out data jointly and then call the downstream score an ordinary inductive test without acknowledging the transductive use of held-out inputs. Standard t-SNE does not automatically provide a simple fixed transform for new points; parametric and interpolation extensions need separate validation.

Use PCA for linear variance and reconstruction questions, and compare UMAP for a different neighbourhood-based construction. A useful t-SNE figure is a diagnostic accompanied by its settings and original-space evidence, not a standalone proof of natural groups.

Key Insight: t-SNE preserves a probability model of local relationships, not a ruler for all original distances. Its adaptive bandwidths and asymmetric loss explain both the useful detail and the misleading visual cues.
Common pitfall: Do not infer population density, exact cluster count or quantitative inter-group distance from island size and spacing. Check those claims in the original representation.

Recap

  • Derive conditional affinities and entropy-based perplexity.
  • Understand the heavy-tailed low-dimensional kernel and asymmetric KL loss.
  • Repeat plausible optimisation settings and inspect original examples.
  • Separate exploratory maps from predictive evaluation and quantitative geometry.

References

  1. van der Maaten and Hinton. Visualizing Data using t-SNE. JMLR, 2008.
  2. scikit-learn. Manifold learning.