Sub topic 2
Perplexity as an Effective Neighbourhood Size
Assume you know Euclidean distance, probability distributions, and the fit/transform pattern. This chapter focuses on how t-SNE and UMAP preserve local structure.
Perplexity as an effective neighbourhood size
For each point, t-SNE converts distances to conditional probabilities. Nearby points receive larger probabilities. The Gaussian width changes until the distribution has a chosen perplexity:
perplexity(P_i) = 2^H(P_i)
where H(P_i) is the entropy of point i's neighbour distribution. Perplexity is therefore an effective neighbourhood size, not an exact count.
Small values emphasise very local structure. Large values use broader neighbourhoods and can reveal larger-scale organisation. The useful range depends on the dataset size and density. Always compare several values rather than treating one setting as universally correct.
The Student-t kernel and the crowding problem
In the two-dimensional map, t-SNE converts distances into similarities with a Student-t distribution with one degree of freedom. Its heavy tails let moderately distant points remain separated without requiring excessive space.
This addresses the crowding problem. A high-dimensional neighbourhood can have many points at different distances, but a two-dimensional map has less room. The heavy-tailed kernel gives distant points more probability mass than a Gaussian would.
The KL divergence objective
t-SNE minimises:
KL(P || Q) = sum p_ij log(p_ij / q_ij)
This asymmetric objective strongly penalises pairs that are close in the original space but far apart in the map. It is less concerned when distant points become close. Consequently, t-SNE is mainly a local-neighbourhood visualisation method. Inter-cluster distances and cluster areas do not automatically have a meaningful interpretation.
Optimising t-SNE
t-SNE uses gradient descent. PCA initialisation often gives a stable, faster starting layout; random initialisation can expose different arrangements. During early exaggeration, t-SNE temporarily multiplies high-dimensional similarities, helping local groups form. The learning rate controls how far coordinates move per update. A rate that is too small can create cramped layouts; one that is too large can produce unstable or scattered results.
> callout warning > A visually separated cluster is not proof that the underlying groups are well separated. Check multiple seeds and parameter values.
Scaling and UMAP
Barnes-Hut t-SNE reduces repulsive-force calculations to roughly O(n log n). FFT-based implementations approximate these forces on an interpolation grid and can scale further. These methods improve speed, not the meaning of the resulting map.
UMAP first builds a weighted k-nearest-neighbour graph. n_neighbors controls how much local or global structure enters the graph. Distances are adjusted for each point's local connectivity and converted into edge weights.
UMAP then optimises two-dimensional coordinates so connected points attract and unconnected points repel. min_dist controls how tightly connected points may pack. Its layout uses a cross-entropy-like objective, so it is also primarily a neighbourhood-preserving visualisation.
Exercise
What usually happens when t-SNE perplexity or UMAP n_neighbors increases?
Show answer
Each point uses a broader neighbourhood, so the map may show more large-scale structure and less fine local detail.