bird_cloud_gnn.early_stopper

Module for early stopping class

Module Contents

Classes

EarlyStopper

Early stopper check.

class bird_cloud_gnn.early_stopper.EarlyStopper(patience=3, min_abs_delta=0.01, min_rel_delta=0.0)[source]

Early stopper check.

This class is used to stop the training process if the validation loss starts increasing. The validation loss is considered to be increasing if it is greater than the minimum validation loss found so far plus an absolute and/or relative tolerance. The class keeps track of the minimum validation loss found so far and the number of consecutive iterations where the validation loss has increased. If the number of consecutive iterations where the validation loss has increased exceeds a certain threshold, the training process is stopped.

patience

How many consecutive iterations to wait before stopping.

Type:

int

min_abs_delta

Absolute tolerance to the increase.

Type:

float

min_rel_delta

Relative tolerance to the increase.

Type:

float

counter

Number of consecutive iterations where the validation loss has increased.

Type:

int

min_validation_loss

Minimum validation loss found so far.

Type:

float

__init__(self, patience=3, min_abs_delta=1e-2, min_rel_delta=0.0)[source]

Initializes the EarlyStopper object.

early_stop(self, validation_loss)[source]

Checks whether it is time to stop, and updates the internal state of the EarlyStopper object.

Example usage:

early_stopper = EarlyStopper(patience=5, min_abs_delta=0.1, min_rel_delta=0.01) for epoch in range(num_epochs):

train_loss = train(model, train_loader) val_loss = validate(model, val_loader) if early_stopper.early_stop(val_loss):

print(f”Validation loss has been increasing for {early_stopper.patience} consecutive epochs. “

f”Training stopped.”)

break

early_stop(validation_loss)[source]

Checks whether it is time to stop, and updates the internal state of the EarlyStopper object.

Parameters:

validation_loss (float) – Current validation loss

Returns:

Whether it is time to stop (True) or not (False).

Return type:

stop (boolean)