EarlyStopping<T>

Models & Types · AiDotNet.HyperparameterOptimization

Provides early stopping functionality for hyperparameter optimization and training.

How It Works

For Beginners: Early stopping is a technique to:

  • Stop training when performance stops improving
  • Prevent overfitting by not training too long
  • Save compute resources by terminating hopeless trials

Key concepts:

  • Patience: How many checks without improvement before stopping
  • Min Delta: Minimum improvement to count as “better”
  • Best Value: The best score seen so far
  • Counter: Tracks consecutive non-improvements

Early stopping is essential for efficient hyperparameter search because it allows quick termination of poor configurations.

Constructors

Constructor Summary
EarlyStopping(int patience, double minDelta, bool maximize, EarlyStoppingMode mode) Initializes a new instance of the EarlyStopping class.

Properties

Property Summary
IReadOnlyList<double> History { get; } Gets the history of values that were checked.
bool ShouldStop { get; } Gets whether early stopping has been triggered.
double BestValue { get; } Gets the best value observed.
int BestEpoch { get; } Gets the epoch at which the best value was observed.
int EpochsSinceBest { get; } Gets the number of epochs since the best value was observed.

Methods

Method Summary
EarlyStoppingState GetState() Gets a summary of the early stopping state.
bool Check(T value, int epoch) Checks if training should stop based on the new value.
bool Check(double value, int epoch) Checks if training should stop based on the new value.
void Reset() Resets the early stopping state.