For symmetric t-SNE with high-dimensional affinities pij (symmetric, with ∑i≠jpij=1) and low-dimensional affinities qij=(1+∥yi−yj∥2)−1∑k≠l(1+∥yk−yl∥2)−1, how do you derive ∂C∂yi=4∑j(pij−qij)(yi−yj)(1+∥yi−yj∥2)−1 for C=KL(P∥Q)? What do the two terms mean, and why does the Student-t kernel help with the crowding problem?

Unsupervised learning, Dimensionality reduction
Level L5 Expert. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can differentiate through a normalised kernel carefully, count each pair of points twice, and read the result as attractive and repulsive forces.

Key idea

Write dkl=∥yk−yl∥2, wkl=(1+dkl)−1 and Z=∑k≠lwkl, so qkl=wkl/Z. Then C=const−∑k≠lpkllog⁡wkl+log⁡Z, and ∂C∂dkl=(pkl−qkl) wkl for each ordered pair. Each dij appears twice, as (i,j) and (j,i), and ∂dij/∂yi=2(yi−yj); together these give the factor 4.

Steps

  1. Split the cost: C=KL(P∥Q)=∑pkllog⁡pkl−∑pkllog⁡qkl. The first sum does not depend on the y's, so it is a constant. Use log⁡qkl=log⁡wkl−log⁡Z and ∑pkl=1 to get C=const−∑k≠lpkllog⁡wkl+log⁡Z.
  2. Differentiate with respect to each dkl first, because C depends on the y's only through these squared distances. From −log⁡wkl=log⁡(1+dkl): ∂∂dkl(−log⁡wkl)=11+dkl=wkl. So the first term contributes pklwkl.
  3. Differentiate log⁡Z: ∂log⁡Z∂dkl=1Z∂wkl∂dkl=−wkl2Z=−qklwkl. Adding the two parts, ∂C∂dkl=(pkl−qkl)wkl.
  4. Apply the chain rule. yi appears in dij and in dji for every j; these are equal and, by symmetry of p and q, have the same derivative. With ∂dij∂yi=2(yi−yj): ∂C∂yi=∑j2(pij−qij)wij⋅2(yi−yj)=4∑j(pij−qij)wij(yi−yj).
  5. Interpret the terms. Gradient descent moves yi against the gradient. The pijwij(yi−yj) part pulls yi towards points that were neighbours in the original space (attraction). The −qijwij(yi−yj) part pushes all points apart (repulsion). At the optimum they balance.
  6. Explain crowding. In 2-D there is not enough room to place moderately distant neighbours at faithful distances, so everything tends to pile up in the middle. The heavy-tailed kernel (1+d)−1 falls off slowly, so moderately similar points can sit much farther apart for the same qij. Its tail follows an inverse-square law, (1+dij)−1≈1/∥yi−yj∥2 at large distances, compared with the Gaussian's e−∥yi−yj∥2. So moderately dissimilar points can sit far apart in 2-D, which relieves the crowding and keeps separate clusters clearly apart.

Common mistakes

How long your answer should be

About a page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: Why is the log-likelihood of a Gaussian mixture unbounded above when each component has its own covariance matrix? How do you show it in one dimension with K=2, and how do EM implementations avoid the problem?
Next in Unsupervised learning: How can the k-means objective be written as a trace problem over cluster indicator vectors, and what lower bound on the optimal SSE do you get by relaxing it to orthonormal matrices when the data are centred?