Logarithm::EarlyStopping
Early stopping mechanism to prevent overfitting during training.
This class monitors the validation loss during training and stops the training process when the loss stops improving, helping to prevent overfitting.
Example usage:
early_stopping = EarlyStopping.new(patience: 10, min_delta: 0.001)
loop do
train_epoch()
val_loss = validate()
break if early_stopping.should_stop?(val_loss)
end
Constructors
Initialize early stopping mechanism.
Parameters:
- patience: Number of epochs to wait for improvement before stopping
- min_delta: Minimum change in loss to qualify as an improvement
- restore_best_weights: Whether to restore the best weights when stopping
Instance methods
min_delta
Sourcepatience
Sourcerestore_best_weights?
SourceCheck if training should stop based on current validation loss.
Parameters:
- current_loss: Current validation loss
- current_weights: Optional model weights to save (for restoration)
Returns: True if training should stop, false otherwise