peal.training.criterions

Loss functions (“criterions”) used by PEAL’s predictor trainers.

A criterion is a callable criterion(model, y_pred, y_target, latent_code) returning a scalar tensor. model is passed so a criterion can read the training config (model.config.task / model.config.data) or, for the weight regularisers, iterate over the parameters. ModelTrainer.run_epoch looks every key of config.task.criterions up in available_criterions and sums the results weighted by the configured factors. l1, l2 and orthogonality are weight regularisers; the others are data losses.

Functions

cross_entropy_criterion

Cross-entropy for hard or soft targets.

cross_entropy_loss

Cross-entropy between logits and a soft (one-hot or mixed) target.

focal_criterion

Focal loss on every output column.

get_criterions

Select the criterions named in config.task.criterions.

l1_criterion

Mean absolute value over all parameters of model (L1 weight decay).

l2_criterion

Mean squared value over all parameters of model (L2 weight decay).

latent_convexity_criterion

Mixup in the penultimate feature space (latent-convexity regulariser).

mixed_bce_mse_criterion

BCE on the discrete outputs plus weighted MSE on the continuous ones.

mixed_focal_mse_criterion

Focal loss on the discrete outputs plus weighted MSE on the continuous.

orthogonality_criterion

Penalise non-orthogonal weight matrices of model.

Classes

FocalLoss

Binary focal loss on logits (Lin et al., 2017).

OnehotCrossEntropyLoss

Callable wrapper around cross_entropy_loss().