DRModule#

class torchdr.DRModule(n_components: int = 2, device: str = 'auto', backend: str | None = None, verbose: bool = False, random_state: float | None = None, process_duplicates: bool = True)[source]#

Bases: BaseEstimator, ABC

Base class for DR methods.

Each children class should implement the fit_transform method.

Parameters:
  • n_components (int, default=2) – Number of components to project the input data onto.

  • device (str, default="auto") – Device on which the computations are performed.

  • backend ({"keops", "faiss", None}, optional) – Which backend to use for handling sparsity and memory efficiency. Default is None.

  • verbose (bool, default=False) – Whether to print information during the computations.

  • random_state (float, default=None) – Random seed for reproducibility.

  • process_duplicates (bool, default=True) – Whether to handle duplicate data points by default.

fit(X: ArrayLike, y: Any | None = None) DRModule[source]#

Fit the dimensionality reduction model from the input data.

Parameters:
  • X (ArrayLike of shape (n_samples, n_features)) – or (n_samples, n_samples) if precomputed is True Input data or input affinity matrix if it is precomputed.

  • y (None) – Ignored.

Returns:

self – The fitted DRModule instance.

Return type:

DRModule

fit_transform(X: ArrayLike, y: Any | None = None) ArrayLike[source]#

Fit the dimensionality reduction model and transform the input data.

This method handles duplicate data points by default. It performs dimensionality reduction on unique data points and then maps the results back to the original data structure. This behavior can be controlled by the process_duplicates parameter.

Parameters:
  • X (ArrayLike of shape (n_samples, n_features)) – or (n_samples, n_samples) if precomputed is True Input data or input affinity matrix if it is precomputed.

  • y (None) – Ignored.

Returns:

embedding_ – The embedding of the input data in the lower-dimensional space.

Return type:

ArrayLike of shape (n_samples, n_components)

transform(X: ArrayLike | None = None) ArrayLike[source]#

Transform the input data into the learned embedding space.

This method can only be called after the model has been fitted. If X is not provided, it returns the embedding of the training data.

Parameters:

X (ArrayLike of shape (n_samples, n_features), optional) – The data to transform. If None, returns the training data embedding. Not all models support transforming new data.

Returns:

embedding_ – The embedding of the input data.

Return type:

ArrayLike of shape (n_samples, n_components)

Raises:

Examples using DRModule:#

Neighbor Embedding on genomics & equivalent affinity matcher formulation

Neighbor Embedding on genomics & equivalent affinity matcher formulation

PCA via SVD and via AffinityMatcher

PCA via SVD and via AffinityMatcher

TSNE embedding of the swiss roll dataset

TSNE embedding of the swiss roll dataset

TSNE vs COSNE : Euclidean vs Hyperbolic

TSNE vs COSNE : Euclidean vs Hyperbolic