KernelPCA

class torchdr.KernelPCA(affinity: ~torchdr.affinity.base.Affinity = <torchdr.affinity.unnormalized.GaussianAffinity object>, n_components: int = 2, device: str = 'auto', keops: bool = False, verbose: bool = False, random_state: float = 0, nodiag: bool = False)[source]

Bases: DRModule

Kernel Principal Component Analysis module.

Parameters:
  • affinity (Affinity, default=GaussianAffinity()) – Affinity object to compute the kernel matrix.

  • 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.

  • keops (bool, default=False) – Whether to use KeOps for computations.

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

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

  • nodiag (bool, default=False) – Whether to remove eigenvectors with a zero eigenvalue.

fit(X: Tensor | ndarray)[source]

Fit the KernelPCA model.

Parameters:

X (torch.Tensor or np.ndarray of shape (n_samples, n_features)) – Data on which to fit the KernelPCA model.

Returns:

self – The fitted KernelPCA model.

Return type:

KernelPCA

fit_transform(X: Tensor | ndarray)[source]

Fit the KernelPCA model and project the input data onto the components.

Parameters:

X (torch.Tensor or np.ndarray of shape (n_samples, n_features)) – Data on which to fit the KernelPCA model and project onto the components.

Returns:

X_new – Projected data.

Return type:

torch.Tensor or np.ndarray of shape (n_samples, n_components)

transform(X: Tensor | ndarray)[source]

Project the input data onto the KernelPCA components.

Parameters:

X (torch.Tensor or np.ndarray of shape (n_samples, n_features)) – Data to project onto the KernelPCA components.

Returns:

X_new – Projected data.

Return type:

torch.Tensor or np.ndarray of shape (n_samples, n_components)