API and Modules#

This page provides a complete reference of all TorchDR classes and functions. For conceptual background, see the User Guide.

Dimensionality Reduction Methods#

TorchDR provides sklearn-compatible estimators that work seamlessly with both NumPy arrays and PyTorch tensors. All methods support GPU acceleration via device="cuda" and can scale to large datasets using backend="faiss" or backend="keops".

Neighbor Embedding#

UMAP([n_neighbors, n_components, min_dist, ...])

UMAP introduced in [McInnes et al., 2018] and further studied in [Damrich and Hamprecht, 2021].

TSNE([perplexity, n_components, lr, ...])

t-Stochastic Neighbor Embedding (t-SNE) introduced in [Van der Maaten and Hinton, 2008].

InfoTSNE([perplexity, n_components, lr, ...])

InfoTSNE algorithm introduced in [Damrich et al., 2022].

LargeVis([perplexity, n_components, lr, ...])

LargeVis algorithm introduced in [Tang et al., 2016].

SNE([perplexity, n_components, lr, ...])

Stochastic Neighbor Embedding (SNE) introduced in [Hinton and Roweis, 2002].

TSNEkhorn([perplexity, n_components, lr, ...])

TSNEkhorn algorithm introduced in [Van Assel et al., 2024].

COSNE([perplexity, lambda1, gamma, ...])

Implementation of the CO-Stochastic Neighbor Embedding (CO-SNE) introduced in [Guo et al., 2022].

PACMAP([n_neighbors, n_components, lr, ...])

PACMAP algorithm introduced in [Wang et al., 2021].

Spectral Methods#

PCA([n_components, device, distributed, ...])

Principal Component Analysis module.

IncrementalPCA([n_components, copy, ...])

Incremental Principal Components Analysis (IPCA) leveraging PyTorch for GPU acceleration.

ExactIncrementalPCA([n_components, device, ...])

Exact Incremental Principal Component Analysis.

KernelPCA([affinity, n_components, device, ...])

Kernel Principal Component Analysis module.

PHATE([k, n_components, t, alpha, ...])

Implementation of PHATE introduced in [Moon et al., 2019].

Affinities#

Affinities are the building blocks for constructing the input similarity matrix \(\mathbf{P}\). See User Guide for details on how affinities are used in DR methods.

Adaptive Affinities#

Affinities that adapt bandwidth based on local neighborhood structure.

EntropicAffinity([perplexity, max_iter, ...])

Solve the directed entropic affinity problem introduced in [Hinton and Roweis, 2002].

SymmetricEntropicAffinity([perplexity, lr, ...])

Compute the symmetric entropic affinity (SEA) introduced in [Van Assel et al., 2024].

UMAPAffinity([n_neighbors, max_iter, ...])

Compute the input affinity used in UMAP [McInnes et al., 2018].

PACMAPAffinity([n_neighbors, metric, ...])

Compute the input affinity used in PACMAP [Wang et al., 2021].

SelfTuningAffinity([K, normalization_dim, ...])

Self-tuning affinity introduced in [Zelnik-Manor and Perona, 2004].

MAGICAffinity([K, metric, zero_diag, ...])

Compute the MAGIC affinity with alpha-decay kernel introduced in [Van Dijk et al., 2018].

PHATEAffinity([metric, device, backend, ...])

Compute the potential affinity used in PHATE [Moon et al., 2019].

Other Normalized Affinities#

Other normalized affinity kernels.

NormalizedGaussianAffinity([sigma, metric, ...])

Compute the Gaussian affinity matrix which can be normalized along a dimension.

NormalizedStudentAffinity([...])

Compute the Student affinity matrix which can be normalized along a dimension.

SinkhornAffinity([eps, tol, max_iter, ...])

Compute the symmetric doubly stochastic affinity matrix.

DoublyStochasticQuadraticAffinity([eps, ...])

Compute the symmetric doubly stochastic affinity.

Base Classes#

These classes provide the foundation for implementing custom DR methods.

Core Base Classes#

DRModule([n_components, device, backend, ...])

Base class for DR methods.

AffinityMatcher(affinity_in[, affinity_out, ...])

Perform dimensionality reduction by matching two affinity matrices.

Neighbor Embedding Base Classes#

Base classes for neighbor embedding methods. SparseNeighborEmbedding leverages input affinity sparsity for efficient attractive term computation. NegativeSamplingNeighborEmbedding adds approximate repulsive term computation via negative sampling.

NeighborEmbedding(affinity_in[, ...])

Solves the neighbor embedding problem.

SparseNeighborEmbedding(affinity_in[, ...])

Solves the neighbor embedding problem with a sparse input affinity matrix.

NegativeSamplingNeighborEmbedding(affinity_in)

Solves the neighbor embedding problem with both sparsity and sampling.

Evaluation Metrics#

silhouette_score(X, labels[, weights, ...])

Compute the Silhouette score as the mean of silhouette coefficients.

silhouette_samples(X, labels[, weights, ...])

Compute the silhouette coefficients for each data sample.

knn_label_accuracy(X, labels[, k, metric, ...])

Compute k-NN label accuracy to evaluate class structure preservation.

neighborhood_preservation(X, Z, K[, metric, ...])

Compute K-ary neighborhood preservation between input data and embeddings.

kmeans_ari(X, labels[, n_clusters, niter, ...])

Perform K-means clustering and compute Adjusted Rand Index.

Utils#

pairwise_distances(X[, Y, metric, backend, ...])

Compute pairwise distances between two tensors or from a DataLoader.

binary_search(f, n[, begin, end, max_iter, ...])

Batched binary search root finding.

false_position(f, n[, begin, end, max_iter, ...])

Batched false-position root finding.