Exercises — t-SNE for visualization
Quick symbol refresher so line one makes sense:
- = a data point in high dimensions; = its picture in 2D.
- = "how much points and look like neighbors" in high-D (a probability, so a number between 0 and 1 across all pairs summing to 1).
- = the same neighbor-probability but measured in the 2D map.
- = a single number scoring how badly the 2D probabilities disagree with the true ones (see 1.3.5 KL Divergence).
Level 1 — Recognition
Exercise 1.1
Which quantity does t-SNE try to make small, and what does making it small achieve? (a) The variance of ; (b) ; (c) the reconstruction error ; (d) the number of clusters.
Recall Solution
Answer: (b). t-SNE minimizes the cost . Making this number small forces the 2D neighbor-probabilities to imitate the high-D neighbor-probabilities , so points that were neighbors in high-D stay neighbors in the picture. (a) is what PCA maximizes; (c) is what an autoencoder minimizes; (d) is a K-Means idea, see 2.4.3 K-Means Clustering.
Exercise 1.2
True or false: In t-SNE, a large gap between two clusters in the final 2D plot means those clusters are very far apart in the original high-D space.
Recall Solution
False. t-SNE only preserves local structure. The KL objective barely penalizes far-apart points being placed at any particular far distance, so the size of the gap between clusters is essentially arbitrary. Read gaps as "these are separate groups", never as "twice as far = twice as different".
Level 2 — Application
Exercise 2.1
Two points sit at squared distance in the 2D map. Compute the unnormalized low-D affinity , and compare it to the Gaussian value that a Gaussian kernel would give. Which is larger, and why does t-SNE prefer the larger one?
Recall Solution
- t-distribution: .
- Gaussian: .
The t-value (0.25) is about 5× larger. This is the whole point of the heavy tail: moderately distant points still get a non-tiny affinity, so they are allowed to sit further apart in 2D without their similarity "vanishing". This directly fights the crowding problem described in the parent note. See the tail comparison in the figure below.
Exercise 2.2
A conditional distribution around point has only two neighbors with non-negligible probability, each getting (all others ). Compute the entropy and then the perplexity .
Recall Solution
Perplexity . Interpretation: perplexity is the effective number of neighbors. Here two equally-weighted neighbors give perplexity exactly 2 — the formula returns the honest count. This is why perplexity is set as a target and is binary-searched to hit it.
Exercise 2.3
For a point with four equally-likely neighbors ( each), what is the perplexity?
Recall Solution
A uniform distribution over neighbors always has perplexity exactly . Perplexity is literally "how many neighbors am I effectively looking at".
Level 3 — Analysis
Exercise 3.1
In the gradient suppose for one pair and . Is the resulting force attractive (pulling toward ) or repulsive? Explain using the sign.
Recall Solution
. Gradient descent moves against the gradient: . The term points away from ; a positive coefficient means the gradient points away from , so stepping against it moves toward . → Attractive. Meaning: says "these two are more similar in high-D than the map currently shows", so the map is too spread out here → pull them together. The figure shows both force directions.
Exercise 3.2
Explain why t-SNE minimizes and not . Which failure mode does each direction tolerate?
Recall Solution
Write . Each term is weighted by (the true similarity).
- When is large (true neighbors) but is small (map put them far), blows up and the large weight amplifies it → huge penalty. So true neighbors are strongly protected.
- When is near 0 (unrelated points) but is large (map put them close), the weight makes the penalty tiny → cheap mistake.
This asymmetry says: "never tear apart real neighbors; occasionally letting strangers sit close is fine." That is exactly the local-structure priority we want. would flip these priorities (weight by ), protecting empty space instead of neighborhoods. See 1.3.5 KL Divergence for the general asymmetry.
Exercise 3.3
You initialize all from — essentially a tiny blob at the origin. At iteration 0, compute (qualitatively) what looks like for every pair, and argue why early gradients are dominated by the term.
Recall Solution
With every crammed near the origin, all pairwise distances , so every unnormalized affinity . After normalizing over pairs, every is nearly identical and tiny, . Therefore . Pairs with large (true neighbors) get a strong positive coefficient → strong attraction; unrelated pairs get . So the early motion is driven almost entirely by the high-D structure , which is precisely why the layout organizes into meaningful clumps first. Early exaggeration (multiply all by 4) supercharges exactly this phase.
Level 4 — Synthesis
Exercise 4.1
A student runs t-SNE on MNIST with perplexity = 2, and again with perplexity = 500 (on 60,000 points). Predict qualitatively what each plot looks like and explain via the entropy/neighbor-count meaning of perplexity.
Recall Solution
- Perplexity 2: each point effectively looks at ~2 neighbors. The Gaussian shrinks so only the 1–2 nearest points matter. Result: many tiny fragmented sub-clusters, broken threads, lots of noise-driven micro-structure. Global digit clusters may shatter.
- Perplexity 500: each point averages over ~500 neighbors, grows large, so becomes smooth and broad. Local detail is washed out; you get a few big diffuse blobs with digits smeared together, closer to a PCA-like global view.
- Sweet spot (~30): enough neighbors to define genuine local manifolds without drowning them — this is why 5–50 is the standard range. Perplexity is a smoothness / scale knob, tied directly to and thus .
Exercise 4.2
You have data that is genuinely 5-dimensional and want a 2D scatter. Argue whether t-SNE is the right tool, referencing the crowding problem and the comparison to 2.5.10 UMAP / PCA.
Recall Solution
t-SNE is overkill / risky here.
- The crowding problem (heavy-tail t-distribution) is a cure for high-D geometry, where huge numbers of points can be near-equidistant. In 5D there is no severe crowding, so the heavy tail can invent separation that isn't real, distorting simple structure.
- t-SNE is stochastic and slow ( ish); for 5D you can just plot pairs of features, run PCA, or use 2.5.10 UMAP if a smoother/faster embedding is desired.
- t-SNE's strength (rescuing local structure from 50+ dimensions) has nothing to buy you at 5D. Match the tool to the dimensionality.
Exercise 4.3
Symmetrization uses . Suppose and the conditionals are . Compute the symmetric , and state the two properties symmetrization guarantees.
Recall Solution
Guaranteed properties:
- Symmetry: (no arbitrary direction of "who chose whom").
- Valid joint distribution: , and crucially every point contributes at least of total mass, so no outlier gets ignored (a raw conditional could leave a lonely point invisible).
Level 5 — Mastery
Exercise 5.1
A colleague builds a pipeline: run t-SNE → take the 2D coordinates as features → train a logistic-regression classifier, and plans to apply it to new incoming data. List every reason this breaks, and propose the correct replacement.
Recall Solution
Why it breaks:
- Non-parametric: t-SNE learns positions for these specific points, not a function . There is no way to map a new into the existing map without re-running everything.
- Stochastic: random init + gradient descent means two runs give different (rotated, reshaped) layouts, so "feature 1" and "feature 2" have no stable meaning.
- Distorted global geometry: distances are unreliable, so a linear classifier on them learns artifacts.
- Cost: per fit; you cannot cheaply embed streaming data.
Correct replacements: use a parametric embedder — PCA (deterministic, projects new data instantly), an autoencoder (learns a reusable encoder ), or 2.5.10 UMAP (has a transform for new points and is faster). Reserve t-SNE for one-off visualization only.
Exercise 5.2
Design a small sanity experiment to demonstrate to a skeptic that t-SNE cluster sizes and gaps are not quantitatively meaningful. Describe data, expected plot, and the takeaway.
Recall Solution
Data: Generate three Gaussian blobs in high-D with equal spread, but place them at very different mutual distances — e.g. A–B far apart, A–C and B–C moderate. Also make one blob denser (smaller ) than the others. Run: t-SNE at a fixed perplexity. Expected plot: Three well-separated clusters, but the gaps between them will NOT reflect the true ratio of high-D distances, and the on-screen cluster sizes will look roughly comparable regardless of the true density differences — because the t-distribution normalizes each region's spread locally. Takeaway: Re-running with a different seed or perplexity shuffles gaps and sizes while keeping membership stable. This visually proves: trust which points group together; distrust how big or how far apart the groups appear. Ties directly to 2.5.9 Manifold Learning — t-SNE recovers the neighborhood graph, not a metric embedding.
Exercise 5.3
The KL cost for a single mismatched pair is . For a true-neighbor pair with , compare the penalty when the map underestimates () versus overestimates () the closeness. Interpret.
Recall Solution
- Underestimate: .
- Overestimate: .
The underestimate penalty (+0.230) is a large positive cost; the overestimate term is negative (it actually reduces this pair's contribution). Concretely, t-SNE pays dearly for tearing true neighbors apart and pays little (or is even rewarded per-term) for keeping them slightly too close. This is the same asymmetry from Exercise 3.2, now with numbers — the mechanism that makes t-SNE guard local neighborhoods above all else.
Recall One-line self-check before you leave
What is the single quantity t-SNE minimizes, and what one thing should you never read off its plot? ::: It minimizes ; never read quantitative meaning into cluster gaps or sizes — only trust which points cluster together.