Early Stopping

class neuro_fuzzy_toolbox.training.early_stopping.EarlyStopping(patience, delta=0, last_state=False)[source]

Bases: object

Early stopping mechanism for halting the training of a machine learning model (torch.nn.Module) when no sufficient improvement is observed.

__call__(model, loss, verbose=False)[source]

Evaluates whether training should be stopped. If the stopping criterion is met, the stop attribute is updated to True.

Parameters:
  • model (torch.nn.Module) – Model to evaluate.

  • loss (float) – Current loss value of the model.

  • verbose (bool) – If True, prints a warning message when early stopping is triggered. Defaults to False.

__init__(patience, delta=0, last_state=False)[source]

Initializes a new EarlyStopping instance.

Parameters:
  • patience (int) – Number of epochs without improvement before stopping training.

  • delta (float) – Minimum improvement required to consider that the model has improved. Defaults to 0.

  • last_state (bool) – If True, restores the last model state when stopping instead of the best state found during training. Defaults to False.

reset()[source]

Resets the early stopping mechanism to its initial state.

property stop

Indicates whether training should be stopped.

Returns:

True if the stopping criterion has been met, False otherwise.

Return type:

bool