Tuning the perplexity for and computing sampling-based t-SNE embeddings

Martin Skrodzki, Nicolas F. Chaves-de-Plaza, Klaus Hildebrandt, Thomas Höllt, Elmar Eisemann

Abstract

Widely used pipelines for analyzing high-dimensional data utilize two-dimensional visualizations created via t-distributed stochastic neighbor embedding (t-SNE). A crucial element of the t-SNE embedding procedure is the perplexity hyperparameter, which dictates the balance between local and global structure. A suitable perplexity choice depends on the data set and the intended usage, often requiring heuristics or trial and error. This paper uncovers a linear relationship between perplexity and the data set size, showing that embeddings remain structurally consistent across data set samples when perplexity is adjusted proportionally. Qualitative and quantitative experimental results support these findings, guiding users in choosing perplexity values and enabling efficient visualization of massive high-dimensional data sets.

Introduction: The Perplexity Challenge

t-distributed Stochastic Neighbor Embedding (t-SNE) is a cornerstone of high-dimensional data visualization. However, its effectiveness is heavily dependent on the perplexity hyperparameter. Perplexity serves as a soft measure of the number of effective neighbors for each point.

The challenge for researchers is twofold:

  1. Sensitivity: Small adjustments in perplexity can radically alter the resulting 2D map, potentially creating artifacts or merging distinct clusters.
  2. Computational Cost: For large datasets, running t-SNE is computationally expensive. Finding the optimal perplexity through trial and error on millions of points is often practically impossible.

While common heuristics suggest setting perplexity to $N/100$, there has lacked a formal understanding of how this parameter should scale when analyzing subsets of data.

The Linear Scaling Law

The core contribution of this work is the proposal and proof of a linear scaling relationship. Specifically, if a dataset $D$ is sampled at a rate $ ho$ to create a subset $D'$, the visual characteristics of the embedding are preserved if the perplexity is scaled as:

$$Perp' = \rho \cdot Perp$$

This logic is grounded in neighborhood geometry. If you sample 10% of your data, the neighborhood around a point that previously contained 100 neighbors will now contain approximately 10 neighbors within the same spatial radius. To maintain a consistent Gaussian bandwidth ($\sigma_i$) and preserve the structural "feel" of the visualization, the perplexity must scale down by that same factor.

Geometric intuition of neighborhood density under sampling, where grayed-out points represent the reduction in local density that necessitates a lower perplexity.

Experimental Validation

The authors validated this scaling law using diverse datasets, including MNIST (handwritten digits), CIFAR-100 (images), WONG (mass cytometry), and C.Elegans (gene expression).

Quantitative Results

Using Monte Carlo simulations, the researchers statistically estimated the "ideal" perplexity for various sampling rates. As shown in the boxplots below, the median estimated perplexity for samples follows a remarkably linear trend as the sampling rate $\rho$ increases from 0.1 to 0.9 across multiple data domains.

The linear relationship between sampling rate and per-point perplexity is consistently observed across MNIST, CIFAR-100, and WONG datasets.

Visual Consistency

Qualitative comparisons further supported the theory. In tests on MNIST and C.Elegans, embeddings where perplexity was scaled linearly with the sampling rate (e.g., $Perp=7$ for $\rho=0.1$ vs. $Perp=70$ for $\rho=1.0$) exhibited nearly identical cluster shapes and relative spatial positions. This suggests that the structural information captured by t-SNE is invariant under this linear transformation.

Key Insights and Applications

  • Efficient Parameter Tuning: Users can find an ideal perplexity on a 10% sample in seconds, then simply multiply that value by 10 for the full-scale run, avoiding the need for expensive re-tuning on the full dataset.
  • Hardware-Aware Visualization: The linear relationship allows users to optimize their hardware usage. By understanding the scaling, one can calculate the largest possible sample size that maintains desired structural detail within a machine's memory and processing limits.
  • Structural Stability: The findings demonstrate that while increasing perplexity on a fixed dataset size changes the view (e.g., merging clusters), increasing perplexity in tandem with dataset size keeps the view stable.

Limitations and Future Work

While the linear scaling law is robust, it has boundaries. Very small samples may fail to represent rare clusters; if a cluster's size is smaller than the perplexity value, it may disappear. Additionally, the relationship holds only within a reasonable regime; if scaled perplexity drops below a certain threshold (e.g., $< 2$), Gaussian bandwidths become too narrow to establish meaningful relationships. Future research may explore integrating these findings into multigrid methods to progressively refine embeddings from coarse to fine scales.

Summary updated

BibTeX
@misc{skrodzki2023tuning,
  author = {Martin Skrodzki and Nicolas F. Chaves-de-Plaza and Klaus Hildebrandt and Thomas Höllt and Elmar Eisemann},
  title = {{Tuning the perplexity for and computing sampling-based t-SNE embeddings}},
  year = {2023},
  eprint = {2308.15513},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.15513},
}
Figure