mlcolvar.core.loss.FisherDiscriminantLoss

class mlcolvar.core.loss.FisherDiscriminantLoss(n_states: int, lda_mode: str = 'standard', reduce_mode: str = 'sum', lorentzian_reg: float | None = None, invert_sign: bool = True)[source]

Bases: Module

Fisher’s discriminant ratio.

Computes the sum (or another reducing functions) of the eigenvalues of the ratio between the Fisher’s scatter matrices. This is the same loss function used in DeepLDA.

__init__(n_states: int, lda_mode: str = 'standard', reduce_mode: str = 'sum', lorentzian_reg: float | None = None, invert_sign: bool = True)[source]

Constructor.

Parameters:
  • n_states (int) – The number of states. Labels are in the range [0, n_states-1].

  • lda_mode (str) – Either 'standard' or 'harmonic'. This determines how the scatter matrices are computed (see also LDA). The default is 'standard'.

  • reduce_mode (str) – This determines how the eigenvalues are reduced, e.g., sum, sum2 (see also ReduceEigenvaluesLoss). The default is 'sum'.

  • lorentzian_reg (float, optional) – The magnitude of the regularization for Lorentzian regularization. If not provided, this is automatically set.

  • invert_sign (bool, optional) – Whether to return the negative Fisher’s discriminant ratio in order to be minimized with gradient descent methods. Default is True.

Methods

__init__(n_states[, lda_mode, reduce_mode, ...])

Constructor.

forward(x, labels)

Compute the value of the loss function.

forward(x: Tensor, labels: Tensor) Tensor[source]

Compute the value of the loss function.

Parameters:
  • x (torch.Tensor) – Shape (n_batches, n_features). Input features.

  • labels (torch.Tensor) – Shape (n_batches,). Classes labels.

Returns:

loss – Loss value.

Return type:

torch.Tensor

Attributes

T_destination

call_super_init

dump_patches

training