mlcolvar.core.stats.LDA¶
- class mlcolvar.core.stats.LDA(in_features: int, n_states: int, mode: str = 'standard')[source]¶
Bases:
StatsFisher’s discriminant class.
- Variables:
in_features (int) – Number of input features
out_features (int) – Number of ouput features (n_states - 1)
n_states (int) – Number of states
evals (torch.Tensor) – LDA eigenvalues
evecs (torch.Tensor) – LDA eigenvectors
S_b (torch.Tensor) – Between scatter matrix
S_w (torch.Tensor) – Within scatter matrix
sw_reg (float) – Regularization to S_w matrix
- __init__(in_features: int, n_states: int, mode: str = 'standard')[source]¶
Initialize a LDA object.
- Parameters:
in_features (int) – number of input features
n_states (int) – number of states
mode (string) – options: {‘standard’,’harmonic’}, standard or harmonic variant
Methods
__init__(in_features, n_states[, mode])Initialize a LDA object.
compute(X, labels[, save_params])Compute LDA eigenvalues and eigenvectors.
compute_scatter_matrices(X, labels[, ...])Compute between scatter and within scatter matrices.
Return the extra representation of the module.
forward(x)Compute linear combination with saved eigenvectors
- compute(X, labels, save_params=True)[source]¶
Compute LDA eigenvalues and eigenvectors. First compute the scatter matrices S_between (S_b) and S_within (S_w) and then solve the generalized eigenvalue problem.
- Parameters:
X (array-like of shape (n_samples, in_features)) – Training data.
labels (array-like of shape (n_samples,)) – states labels.
save_params (bool, optional) – Whether to store parameters in model
- Returns:
eigvals (torch.Tensor) – LDA eigenvalues (n_states-1)
eigvecs (torch.Tensor) – LDA eigenvectors (n_feature,n_states-1)
Notes
The eigenvecs object which is returned is a matrix whose column eigvecs[:,i] is the eigenvector associated to eigvals[i]
- compute_scatter_matrices(X, labels, save_params=True)[source]¶
Compute between scatter and within scatter matrices.
- Parameters:
X (array-like of shape (n_samples, in_features)) – Training data.
labels (array-like of shape (n_samples,)) – states labels.
save_params (bool, optional) – Whether to store parameters in model
- Returns:
S_b,S_w – Between and within scatter matrices
- Return type:
arrays of shape (in_features,in_features)
Attributes
T_destination
call_super_init
dump_patches
training