trainers.base.EarlyStopping

Contents

trainers.base.EarlyStopping#

class EarlyStopping(params, criterion, pq_window_size=5)[source]#

A class that saves the best parameter obtained so far based on the validation loss and determines whether the optimization can be stopped based on some stopping criterion.

The following criteria are implemented:

  • "window_median": 2 windows are placed at the end of the loss history. Stops when the median of the latter window of size “thresh” exceeds the median of the prior window of the same size.

  • "PQ": Stops when the PQ criterion exceeds thresh

  • "max_loss": Stops when the loss decreased below the maximum allowed loss specified via thresh.

Parameters:
  • criterion – Convergence criterion to employ

  • pq_window_size – Window size for PQ method

Variables:
  • best_loss – Loss of the best performing parameters

  • best_params – Parameters with best performance

Methods

__init__(params, criterion[, pq_window_size])

early_stopping(curr_epoch_loss, thresh[, ...])

Estimates whether the convergence criterion was met and keeps track of the best parameters obtained so far.

move_to_device()

Moves best_params to device to use them after loading trainer.

reset_convergence_losses()

Resets loss history used for convergence estimation, e.g., to avoid early stopping when loss increases due to on-the-fly changes in the dataset or the loss function.