mlcolvar.core.loss.ReduceEigenvaluesLoss

class mlcolvar.core.loss.ReduceEigenvaluesLoss(mode: str = 'sum', n_eig: int = 0, invert_sign: bool = True)[source]

Bases: Module

Calculate a monotonic function f(x) of the eigenvalues, by default the sum.

By default it returns -f(x) to be used as loss function to maximize eigenvalues in gradient descent schemes.

The following reduce functions are implemented:
  • sum : sum_i (lambda_i)

  • sum2 : sum_i (lambda_i)**2

  • gap : (lambda_1-lambda_2)

  • its : sum_i (1/log(lambda_i))

  • single : (lambda_i)

  • single2 : (lambda_i)**2

__init__(mode: str = 'sum', n_eig: int = 0, invert_sign: bool = True)[source]

Constructor.

Parameters:
  • mode (str, optional) – Function of the eigenvalues to optimize (see notes). Default is 'sum'.

  • n_eig (int, optional) – Number of eigenvalues to include in the loss (default: 0 –> all). In case of 'single' and 'single2' is used to specify which eigenvalue to use.

  • invert_sign (bool, optional) – Whether to return the opposite of the function (in order to be minimized with GD methods). Default is True.

Methods

__init__([mode, n_eig, invert_sign])

Constructor.

forward(evals)

Compute the loss.

forward(evals: Tensor) Tensor[source]

Compute the loss.

Parameters:

evals (torch.Tensor) – Shape (n_batches, n_eigenvalues). Eigenvalues.

Returns:

loss

Return type:

torch.Tensor

Attributes

T_destination

call_super_init

dump_patches

training