SNE

class torchdr.SNE(perplexity: float = 30, n_components: int = 2, lr: float | str = 'auto', optimizer: str = 'auto', optimizer_kwargs: dict | str | None = None, scheduler: str = 'constant', scheduler_kwargs: dict | None = None, init: str = 'pca', init_scaling: float = 0.0001, tol: float = 1e-07, max_iter: int = 2000, tolog: bool = False, device: str | None = None, keops: bool = False, verbose: bool = False, random_state: float = 0, early_exaggeration: float = 10.0, coeff_repulsion: float = 1.0, early_exaggeration_iter: int = 250, tol_affinity: float = 0.001, max_iter_affinity: int = 100, metric_in: str = 'sqeuclidean', metric_out: str = 'sqeuclidean')[source]

Bases: SparseNeighborEmbedding

Implementation of Stochastic Neighbor Embedding (SNE) introduced in [H02].

It involves selecting a EntropicAffinity as input affinity \(\mathbf{P}\) and a GaussianAffinity as output affinity \(\mathbf{Q}\).

The loss function is defined as:

\[-\sum_{ij} P_{ij} \log Q_{ij} + \sum_i \log \Big( \sum_{j} Q_{ij} \Big) \:.\]
Parameters:
  • perplexity (float) – Number of ‘effective’ nearest neighbors. Consider selecting a value between 2 and the number of samples. Different values can result in significantly different results.

  • n_components (int, optional) – Dimension of the embedded space (corresponds to the number of features of Z).

  • lr (float or 'auto', optional) – Learning rate for the algorithm. By default ‘auto’.

  • optimizer ({'SGD', 'Adam', 'NAdam', 'auto'}, optional) – Which pytorch optimizer to use. By default ‘auto’.

  • optimizer_kwargs (dict or 'auto', optional) – Arguments for the optimizer. By default None.

  • scheduler ({'constant', 'linear'}, optional) – Learning rate scheduler.

  • scheduler_kwargs (dict, optional) – Arguments for the scheduler.

  • init ({'normal', 'pca'} or torch.Tensor of shape (n_samples, output_dim), optional) – Initialization for the embedding Z.

  • init_scaling (float, optional) – Scaling factor for the initialization.

  • tol (float, optional) – Precision threshold at which the algorithm stops.

  • max_iter (int, optional) – Number of maximum iterations for the descent algorithm.

  • tolog (bool, optional) – Whether to store intermediate results in a dictionary, by default False.

  • device (str, optional) – Device to use, by default “auto”.

  • keops (bool, optional) – Whether to use KeOps, by default False.

  • verbose (bool, optional) – Verbosity, by default False.

  • random_state (float, optional) – Random seed for reproducibility, by default 0.

  • early_exaggeration (float, optional) – Coefficient for the attraction term during the early exaggeration phase. By default 10.0 for early exaggeration.

  • coeff_repulsion (float, optional) – Coefficient for the repulsion term, by default 1.0.

  • early_exaggeration_iter (int, optional) – Number of iterations for early exaggeration, by default 250.

  • tol_affinity (float, optional) – Precision threshold for the entropic affinity root search.

  • max_iter_affinity (int, optional) – Number of maximum iterations for the entropic affinity root search.

  • 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 computation, by default ‘sqeuclidean’.

References

[H02]

Geoffrey Hinton, Sam Roweis (2002). Stochastic Neighbor Embedding. Advances in neural information processing systems 15 (NeurIPS).

Examples using SNE:

Neighbor Embedding on genomics & equivalent affinity matcher formulation

Neighbor Embedding on genomics & equivalent affinity matcher formulation