Using Dimensionality Reduction to Optimize t-SNE

Rikhav Shah, Sandeep SilwalarXiv 2019

Abstract

t-SNE is a popular tool for embedding multi-dimensional datasets into two or three dimensions. However, it has a large computational cost, especially when the input data has many dimensions. Many use t-SNE to embed the output of a neural network, which is generally of much lower dimension than the original data. This limits the use of t-SNE in unsupervised scenarios. We propose using random projections to embed high dimensional datasets into relatively few dimensions, and then using t-SNE to obtain a two dimensional embedding. We show that random projections preserve the desirable clustering achieved by t-SNE, while dramatically reducing the runtime of finding the embedding.

Introduction

Visualizing high-dimensional data, such as images or gene expression profiles, is a critical task in data science. t-distributed Stochastic Neighborhood Embedding (t-SNE) has become the gold standard for this purpose, as it excels at preserving local structures by squashing data into two or three dimensions. However, t-SNE's computational complexity is a significant hurdle. The runtime scales linearly with the number of dimensions ($d$) of the input data because the algorithm must repeatedly calculate distances between points in that high-dimensional space.

While previous optimization efforts have focused on reducing the number of distance calculations (e.g., using GPUs or tree-based algorithms), this research explores reducing the cost of each individual distance calculation by shrinking the input dimensionality $d$ before applying t-SNE.

Methods

The proposed approach utilizes a two-step pipeline:

  1. Initial Dimensionality Reduction: The high-dimensional input data is first projected into an intermediate, significantly smaller subspace ($d'$). Two primary methods are evaluated:
  2. Random Projections: Utilizing a random Gaussian matrix, a method supported by the Johnson-Lindenstrauss Lemma, which guarantees distance preservation in a data-oblivious manner.
  3. Principal Component Analysis (PCA): A standard linear technique that projects data onto the directions of maximum variance.
  4. t-SNE Embedding: The standard t-SNE algorithm is then applied to this intermediate $d'$-dimensional data to generate the final 2D visualization.

To quantify performance, the authors use an accuracy score: a point is considered "correctly clustered" if its nearest neighbor in the 2D embedding shares the same label as in the original high-dimensional space.

Key Insights and Results

The core finding is the existence of a "sweet spot" in dimensionality reduction. Accuracy scores for the final t-SNE embedding recover to near-100% (relative to the full-dimensional baseline) very quickly as the intermediate dimension $d'$ increases. Crucially, this recovery happens well before the runtime significantly increases.

Accuracy and runtime ratios for random projections across four datasets.

As shown in the figure above, for random projections, the accuracy ratio reaches a plateau near 1.0 at relatively low dimensions, while the runtime ratio remains significantly lower than 1.0, indicating substantial speedups without quality loss. This trend was consistent across the MNIST, KMnist, Fashion-MNIST, and Small Norb datasets.

Furthermore, while random projections are theoretically robust, PCA performs even better in practice. Across all datasets, projecting down to just $d=25$ using PCA was sufficient to maintain an accuracy ratio close to 1.0.

Accuracy ratios for PCA projection as a function of dimension.

This suggests that t-SNE does not require the full resolution of the original data to identify local neighborhoods. As long as the initial projection preserves the relative order of nearest neighbors, t-SNE can effectively perform its clustering task. The benefits were observed across different software implementations, including the standard scikit-learn version and the highly optimized openTSNE.

Conclusion and Future Work

This research demonstrates that pre-reducing data dimensionality using PCA or random projections can significantly optimize t-SNE's performance. By reducing input dimensions to as little as 5% of their original size, researchers can achieve major speedups with minimal impact on visualization quality.

Future work could explore non-linear pre-reduction techniques, such as autoencoders, although their computational overhead might offset the gains in t-SNE runtime. Additionally, investigating how these heuristics scale to noisier or more complex datasets remains an open area for exploration.

Summary updated

BibTeX
@misc{shah2019using,
  author = {Rikhav Shah and Sandeep Silwal},
  title = {{Using Dimensionality Reduction to Optimize t-SNE}},
  year = {2019},
  eprint = {1912.01098},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1912.01098},
}
Figure