PACMAP#
- class torchdr.PACMAP(n_neighbors: float = 10, n_components: int = 2, lr: float | str = 1.0, optimizer: str | Type[Optimizer] = 'Adam', optimizer_kwargs: Dict | str | None = None, scheduler: str | Type[LRScheduler] | None = None, scheduler_kwargs: Dict | None = None, init: str = 'pca', init_scaling: float = 0.0001, min_grad_norm: float = 1e-07, max_iter: int = 450, device: str | None = None, backend: str | None = 'faiss', verbose: bool = False, random_state: float | None = None, metric_in: str = 'sqeuclidean', metric_out: str = 'sqeuclidean', MN_ratio: float = 0.5, FP_ratio: float = 2, check_interval: int = 50, iter_per_phase: int = 100)[source]#
Bases:
SampledNeighborEmbedding
PACMAP algorithm introduced in [Wang et al., 2021].
It uses a
PACMAPAffinity
as input affinity. The loss function is defined as:\[w_{\mathrm{NB}} \sum_{i, j \in \mathrm{NB}(i)} \frac{d_{ij}}{10 + d_{ij}} + w_{\mathrm{MN}} \sum_{i,j \in \mathrm{MN}(i)} \frac{d_{ij}}{10^4 + d_{ij}} + w_{\mathrm{FP}} \sum_{i,j \in \mathrm{FP}(i)} \frac{1}{1 + d_{ij}}\]where \(\mathrm{NB}(i)\), \(\mathrm{MN}(i)\) and \(\mathrm{FP}(i)\) are the nearest neighbors, mid-near neighbors and far neighbors of point \(i\) respectively, and \(d_{ij} = 1 + \|\mathbf{z}_i - \mathbf{z}_j\|^2\) (more details in [Wang et al., 2021]).
- Parameters:
n_neighbors (int, optional) – Number of nearest neighbors.
n_components (int, optional) – Dimension of the embedding space.
lr (float or 'auto', optional) – Learning rate for the algorithm, by default 1e0.
optimizer (str or torch.optim.Optimizer, optional) – Name of an optimizer from torch.optim or an optimizer class. Default is “Adam”.
optimizer_kwargs (dict or 'auto', optional) – Additional keyword arguments for the optimizer. Default is None, which sets appropriate momentum values for SGD based on early exaggeration phase.
scheduler (str or torch.optim.lr_scheduler.LRScheduler, optional) – Name of a scheduler from torch.optim.lr_scheduler or a scheduler class. Default is None (no scheduler).
scheduler_kwargs (dict, optional) – Additional keyword arguments for the scheduler.
init ({'normal', 'pca'} or torch.Tensor of shape (n_samples, output_dim), optional) – Initialization for the embedding Z, default ‘pca’.
init_scaling (float, optional) – Scaling factor for the initialization, by default 1e-4.
min_grad_norm (float, optional) – Precision threshold at which the algorithm stops, by default 1e-7.
max_iter (int, optional) – Number of maximum iterations for the descent algorithm, by default 450.
device (str, optional) – Device to use, by default “auto”.
backend ({"keops", "faiss", None}, optional) – Which backend to use for handling sparsity and memory efficiency. Default is “faiss”.
verbose (bool, optional) – Verbosity, by default False.
random_state (float, optional) – Random seed for reproducibility, by default None.
metric_in ({'sqeuclidean', 'manhattan'}, optional) – Metric to use for the input affinity, by default ‘sqeuclidean’.
metric_out ({'sqeuclidean', 'manhattan'}, optional) – Metric to use for the output affinity, by default ‘sqeuclidean’.
MN_ratio (float, optional) – Ratio of mid-near pairs to nearest neighbor pairs, by default 0.5.
FP_ratio (float, optional) – Ratio of far pairs to nearest neighbor pairs, by default 2.
check_interval (int, optional) – Interval for checking convergence, by default 50.
iter_per_phase (int, optional) – Number of iterations for each phase of the algorithm, by default 100.