mlcolvar.core.stats.PCA¶
- class mlcolvar.core.stats.PCA(in_features: int, out_features: int = None)[source]¶
Bases:
StatsPrincipal Component Analysis class.
- Variables:
in_features (int) – Number of features
out_features (int) – Number of output features
evals (torch.Tensor) – PCA eigenvalues
evecs (torch.Tensor) – PCA eigenvectors
- __init__(in_features: int, out_features: int = None)[source]¶
Initialize a PCA object. If out_features (<in_features) is given a low rank approximation will be performed.
- Parameters:
in_features (int) – number of input features
out_features (int, optional) – number of principal components, by default None (equal to in_features)
Methods
__init__(in_features[, out_features])Initialize a PCA object.
compute(X[, save_params])Compute PCA eigenvalues and eigenvectors via torch.pca_lowrank method.
Return the extra representation of the module.
forward(x)Compute linear combination with saved eigenvectors.
- compute(X, save_params=True, **kwargs)[source]¶
Compute PCA eigenvalues and eigenvectors via torch.pca_lowrank method.
- Parameters:
X (array-like of shape (n_samples, in_features)) – Training data.
save_params (bool, optional) – Whether to store parameters in model
kwargs (optional) – Keyword arguments passed to torch.pca_lowrank (e.g. center)
- Returns:
eigvals (torch.Tensor) – PCA eigenvalues
eigvecs (torch.Tensor) – PCA eigenvectors
Notes
The eigenvecs object which is returned is a matrix whose column eigvecs[:,i] is the eigenvector associated to eigvals[i]
- property cumulative_explained_variance¶
Cumulative explained variance.
- Returns:
cumulative variance ratio
- Return type:
cum_exp_var, torch.Tensor
- property explained_variance¶
Explained variance ratio of the principal components selected.
- Returns:
explained variance ratio
- Return type:
exp_var, torch.Tensor
Attributes
T_destination
call_super_initCumulative explained variance.
dump_patchesExplained variance ratio of the principal components selected.
training