Affinity#

class torchdr.Affinity(metric: str = 'sqeuclidean', zero_diag: bool = True, device: str = 'auto', backend: str | FaissConfig | None = None, verbose: bool = False, random_state: float | None = None, compile: bool = False, _pre_processed: bool = False)[source]#

Bases: Module, ABC

Base class for affinity matrices.

Parameters:
  • metric (str, optional) – Distance metric for pairwise distances. Default is “sqeuclidean”.

  • zero_diag (bool, optional) – Whether to set the diagonal to zero. Default is True.

  • device (str, optional) – Device for computation. "auto" uses the input data’s device. Default is “auto”.

  • backend ({"keops", "faiss", None} or FaissConfig, optional) – Backend for handling sparsity and memory efficiency. Default is None (standard PyTorch).

  • verbose (bool, optional) – Verbosity. Default is False.

  • compile (bool, optional) – Whether to compile the affinity computation. Default is False.

  • _pre_processed (bool, optional) – If True, skips to_torch conversion (inputs are already tensors on the correct device). Default is False.

clear_memory()[source]#

Clear non-persistent buffers to free memory.

Examples using Affinity:#

Entropic Affinities can adapt to varying noise levels

Entropic Affinities can adapt to varying noise levels

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