Sub topic 8
The Student-t kernel and the crowding problem
This chapter assumes you know the t-SNE affinities from the previous chapters: the high-dimensional probabilities p_ij built from Gaussians, and the idea of perplexity. It also assumes you know what a probability distribution over pairs of points is. The aim is to explain one design choice: why t-SNE measures similarity in the 2-D map with a Student-t curve instead of a Gaussian.
Where the Gaussian fails: the crowding problem
Symmetric SNE is the method before t-SNE. It used Gaussians on both sides. In the original space, p_ij is large when points i and j are close. In the map, the similarity q_ij was also a Gaussian of the map distance. The map was then moved until q matched p.
This works badly because of geometry. A ball in 10 dimensions has room for many points that are all roughly equally far from a centre point. A 2-D map does not have that room.
import numpy as np
for dim in (2, 5, 10, 50):
inner = 0.5 ** dim
print(f"{dim:>2}-D: {inner:7.2%} of a ball's volume lies within half its radius, "
f"{1 - inner:7.2%} lies in the outer shell")In 10 dimensions, 99.9% of the volume sits in the outer half of the radius. A typical point therefore has a few close neighbours and a huge number of moderately distant points. Moderately distant points cannot all be placed at that same moderate distance in 2-D. There is simply not enough area in the ring around a point.
This is the crowding problem. The map has too little room for the moderately distant points. With a Gaussian kernel, the optimiser pushes those points inward, because they must sit closer than their true distances. Each pair has only a small attractive pull, but there are many such pairs. Together they act like a spring that squeezes the whole map toward its centre. Natural clusters get flattened against each other, and the gaps between them vanish.
The Student-t kernel
van der Maaten and Hinton fixed this by changing only the low-dimensional kernel. In t-SNE the map similarity is
q_ij = (1 + ||y_i - y_j||^2)^-1 / sum over k != l of (1 + ||y_k - y_l||^2)^-1The numerator is a Student-t density with one degree of freedom, which is the same as a Cauchy distribution. The denominator normalises all pair scores so they sum to 1 over the whole map. The high-dimensional side still uses Gaussians, so p_ij is unchanged.
The important property is the tail. A Gaussian falls off exponentially with distance. The Student-t falls off like 1/d², so it decays polynomially and keeps a meaningful value far from the centre.
import numpy as np
d = np.array([0.5, 1, 2, 3, 5, 8])
gauss = np.exp(-d**2) # Gaussian with variance 1/2
student = 1 / (1 + d**2) # Student-t, one degree of freedom
print(f"{'d':>4} {'gaussian':>12} {'student-t':>12}")
for di, g, s in zip(d, gauss, student):
print(f"{di:>4} {g:12.6f} {s:12.6f}")
target = 0.01
print("distance where similarity falls to 0.01:")
print(" gaussian :", round(float(np.sqrt(-np.log(target))), 3))
print(" student-t:", round(float(np.sqrt(1 / target - 1)), 3))A map pair that should have similarity 0.01 sits at about 2.1 map units under the Gaussian, but about 10 units under the Student-t. The same required similarity therefore allows a much larger map distance. The moderately distant points can move out to where there is room for them.
Why this particular kernel
Three properties make the Student-t a good choice.
- Heavy tail. It lets moderately distant points sit far apart in the map, which relieves the crowding.
- Cheap to evaluate.
1 / (1 + d²)needs no exponential. This matters because t-SNE evaluates it for a very large number of pairs on every iteration. - A scale-mixture view. The Student-t can be written as an infinite mixture of Gaussians with different variances. It behaves like many Gaussian kernels of different widths added together. This gives it a good match at several length scales at once.
Effect on the gradient
The gradient of the KL objective for map point y_i is
dC/dy_i = 4 * sum over j of (p_ij - q_ij) * (y_i - y_j) * (1 + ||y_i - y_j||^2)^-1When p_ij is larger than q_ij, the pair is pulled together. When q_ij is larger, the pair is pushed apart. The extra (1 + d²)^-1 factor comes from the kernel and changes the force at two ranges.
- At short range. Two points that are close in the map but have a tiny
p_ijrepel strongly. This opens gaps between clusters, which is why t-SNE plots show clearly separated islands. - At long range. For two far-apart points with
p_ijnear 0, the repulsion shrinks roughly liked^-3. Clusters that are already far apart barely push each other, so the map does not blow up.
The attractive forces are also better behaved. A pair at moderate distance needs only a modest q_ij to match a small p_ij, so it no longer has to be drawn close.
What the kernel costs
The heavy tail fixes crowding but changes what the picture means.
| Consequence | What it means for reading the plot |
|---|---|
| Gaps appear between groups | Visible separation does not show how far apart the groups are in the original space. |
| Dense clusters stay compact | Cluster width is not a reliable measure of spread in the original data. |
| Distant pairs are only loosely constrained | Distances between clusters are weakly tied to the true distances. |
| Local neighbourhoods are emphasised | Neighbour relations are the part of the plot you can trust most. |
The Student-t also has a tendency to break up a continuous structure into separate islands, because the repulsion at short range is strong. A smooth curve of points in the original space can appear as several fragments.
Checking the idea yourself
You can see the crowding effect without writing a new optimiser. Run t-SNE on the digits data and look at how the clusters separate compared with PCA. PCA is linear and has no repulsive kernel, so its clusters overlap heavily. The separated islands in the t-SNE plot come directly from the kernel and the KL objective working together, which the next chapter covers.
Exercise
A colleague replaces the Student-t kernel in the low-dimensional space with a Gaussian and finds that the clusters in the 2-D map crowd together. Explain why this happens in terms of the volume of high-dimensional neighbourhoods.
Show answer
In high dimensions most of a neighbourhood's volume lies in a shell of moderately distant points, so each point has many such neighbours. A 2-D map does not have enough area to place them all at the required moderate distance. With a Gaussian kernel, similarity falls off exponentially, so matching the small p_ij values keeps those points at small map distances. Their many small attractive forces add up and squeeze everything toward the centre. The Student-t kernel has a heavy tail, so a small similarity is matched at a large map distance, and the points can spread out.
Exercise
Using the code in this chapter, a map pair needs an unnormalised similarity of 0.01. At what distances does this occur under the Gaussian exp(-d^2) and under the Student-t 1/(1+d^2)? What does the difference tell you?
Show answer
For the Gaussian, d = sqrt(ln 100), about 2.15. For the Student-t, d = sqrt(99), about 9.95. The same similarity is reached at roughly five times the distance under the Student-t, so moderately related points can sit much farther apart in the map. This is the extra room that relieves crowding.