t-SNE

t-SNE (t-distributed stochastic neighbor embedding) is a method by van der Maaten and Hinton (2008). It maps points to points in or for plotting. It tries to keep each point’s near neighbors near in the plot. First it turns distances into neighbor probabilities. Point picks point as its neighbor with probability

a Gaussian centered at with its own bandwidth . A binary search sets each so that the perplexity of point equals a value the user chooses:

Here is the Shannon entropy in bits of point ‘s neighbor probabilities. Perplexity is the effective number of neighbors, typically between and . Points in dense regions get a small , and points in sparse regions get a large one. The method then builds two sets of pair probabilities:

  • Input affinities: , symmetric in and . They sum to over all pairs .
  • Map affinities: . This is a Student-t kernel with one degree of freedom. Its tail falls like one over the squared distance, far slower than a Gaussian.

t-SNE places the to minimize the Kullback-Leibler (KL) divergence

which is positive unless , where it is zero. Gradient descent with momentum follows the gradient

Each term acts along the line between and . Pairs with pull together, and pairs with push apart. During the first iterations, early exaggeration multiplies every by a factor such as , which helps clusters form. Each exact iteration costs , and the Barnes-Hut approximation (van der Maaten 2014) cuts this to . PCA is a linear map that keeps the directions of largest variance across the whole data set. t-SNE is nonlinear and keeps local neighborhoods.

Intuition

The name lists the parts. “Stochastic neighbor” means each point picks its neighbors at random, with nearer points more likely. “Embedding” means placing the points in a low-dimensional map. “t-distributed” means the map measures similarity with a Student-t kernel. Hinton and Roweis (2002) introduced the earlier SNE, which used Gaussians in the map as well. t-SNE changed the map kernel and made the probabilities symmetric.

Perplexity reads as a neighbor count. If point spreads its probability evenly over neighbors, its entropy is bits and its perplexity is . A perplexity of gives each point about effective neighbors, whatever the local density. The optimization then moves the map points. Pairs that sit too far apart for their attract, and pairs that sit too close repel. Points from one tight group in end up in one blob in the plot.

Properties

(Heavy Tail Fixes Crowding) The Student-t kernel lets moderately distant points sit far apart in the map, which leaves room for clusters to separate.

High-dimensional space has far more room at moderate distances than a plane has. In dimensions, the shell between radius and holds a fraction of a ball’s volume. That is in two dimensions, in ten and in fifty. A point can therefore have many moderately distant neighbors, and a plane cannot hold them all at their true distances. Van der Maaten and Hinton call this the crowding problem, a form of the curse of dimensionality. A Gaussian map kernel, as in SNE, places these points too far away. Each of them then pulls back weakly, but together the many small pulls squeeze all points toward the center. Clusters then merge into one ball. The Student-t kernel falls off slowly, so a small matches a much larger map distance. Dissimilar points move far apart, and gaps open between clusters. The kernel also needs no exponential, so it is cheaper to evaluate.

(Sizes and Gaps Mean Little) Cluster sizes and distances between clusters in a t-SNE plot carry little information.

Each adapts to the local density, so a dense cluster and a sparse cluster come out at similar sizes. The cost term is large when is large and is small. When is near zero, the term stays near zero whatever is. t-SNE therefore keeps neighbors together but places distant points almost freely. Two clusters far apart in the plot need not be farther apart in than two clusters that sit close. Wattenberg, Viégas and Johnson (2016) show these effects on synthetic data. A low perplexity can even show clusters in pure noise. Readers should trust only which points group together.

(Runs Disagree) Different random seeds and different perplexities give different pictures of the same data.

The cost is not convex, so gradient descent stops at a local minimum that depends on the starting map. Any run can also rotate or reflect the map, since depends only on distances. A small perplexity stresses very local structure and can split one group into fragments. A large perplexity merges nearby groups and shows more of the global layout. Perplexity must stay well below , since a point has only possible neighbors. Analysts should run several seeds and perplexities and trust only the structure that persists. Kobak and Linderman (2021) start from the top two principal components instead of random points. This keeps the global layout more stable across runs.

(No Out-of-Sample Map) t-SNE returns coordinates for the given points only, with no function that maps a new point.

The optimization moves the directly, and no formula comes out of it. A new point needs a fresh run, or an optimization of that one point with the others held fixed. Parametric t-SNE (van der Maaten 2009) trains a neural network on the same cost. The network plays the role of an autoencoder’s encoder. Feeding t-SNE coordinates to a classifier is risky for a related reason. A joint run on training and test points lets the test points shape the training coordinates. This is data leakage, described in 2.3. Generalization.

(Quadratic Cost) Exact t-SNE uses every pair of points at every iteration, which limits it to several thousand points.

The normalizer of sums over all ordered pairs, so each gradient step costs . For , that is about pairs per iteration. Barnes-Hut t-SNE keeps only for about times the perplexity nearest neighbors of each point. It treats a far group of map points as one point at the group’s center when it computes repulsion. A quadtree, which splits the plane into quarters recursively, finds these groups. Each iteration then costs . FIt-SNE (Linderman et al. 2019) uses interpolation and the fast Fourier transform and handles millions of points. A common pipeline first reduces the data to about dimensions with PCA. This removes noise and speeds up the neighbor search.

(UMAP) UMAP is the common alternative, faster than t-SNE and able to place new points into an existing map.

UMAP (uniform manifold approximation and projection, McInnes, Healy and Melville 2018) follows the same plan with different parts. It builds a weighted -nearest-neighbor graph in , with a per-point scale set from the distance to the nearest neighbor. Its map similarity is , where is the map distance and set the shape. With , this is the t-SNE kernel. UMAP minimizes a cross-entropy between the two weighted graphs by stochastic gradient descent, sampling non-neighbor pairs at random. Its run time grows roughly linearly in . Its main settings are the neighbor count , by default, and a minimum distance between map points. UMAP plots often keep more of the global layout. Kobak and Linderman (2021) traced much of that difference to the starting map. The warnings above about sizes, gaps and run-to-run changes apply to UMAP too.

Examples

(Easy) Gaussian Versus Student-t Tails

In a map of handwritten digits, one pair of points sits at distance and another pair at distance . SNE measures map similarity with the Gaussian kernel , and t-SNE with the Student-t kernel .

(Medium) Neighbor Probabilities of One Song

A music service describes songs by audio features. A small data set has four songs. One song sits at distances , and from the other three.

See Also