xnn.common.train.losses.UncertaintyWeights#

class xnn.common.train.losses.UncertaintyWeights(names)[source]#

Bases: Module

Learned weights of the loss terms, after Kendall, Gal and Cipolla (CVPR 2018).

Every term L_k (already times its config weight) enters the training objective as L_k / (2 sigma_k^2) + log sigma_k with a trainable log sigma_k, which starts at zero. The weights settle where each term is balanced by its own noise level, so they need no hand tuning.

Parameters:

names (sequence of str) – The log keys of the weighted terms ("energy_mse", "charge_mse", …).

Variables:

log_sigma (torch.nn.ParameterDict) – log sigma_k per term.

forward(parts)[source]#

The objective of the terms in parts (a term without a weight adds as it is).

Parameters:

parts (dict of str to Tensor) – The weighted terms of weighted_loss() (its parts).

Returns:

The scalar objective.

Return type:

Tensor

sigmas()[source]#

sigma_k of every term.

Return type:

dict[str, float]