netket.callbacks.EarlyStopping#
- class netket.callbacks.EarlyStopping[source]#
Bases:
AbstractCallbackA simple callback to stop NetKet if there are no more improvements in the training. based on driver._loss_name.
- Inheritance

- __init__(min_delta=0.0, min_reldelta=0.0, patience=0, baseline=None, start_from_step=0, monitor='mean')[source]#
Construct an early stopping callback.
- Parameters:
min_delta (
float) – Minimum change in the monitored quantity to qualify as an improvement.min_reldelta (
float) – Minimum relative change in the monitored quantity to qualify as an improvement.patience (
int|float) – Number of epochs with no improvement after which training will be stopped.baseline (
float|None) – Baseline value for the monitored quantity. Training will stop if the driver does not drop below the baseline.monitor (
str) – Loss statistic to monitor. Should be one of ‘mean’, ‘variance’, ‘error_of_mean’.start_from_step (
int) – Number of steps to wait before the callback has any effect. Defaults to 0.
- Attributes
- callback_order#
- min_reldelta: float#
Minimum relative change in the monitored quantity to qualify as an improvement.
This behaves similarly to min_delta but is more useful for intensive quantities that converge to 0, where absolute tolerances might not be effective.
- baseline: float | None#
Baseline value for the monitored quantity. Training will stop if the driver is above the baseline.
- Methods
- before_parameter_update(step, log_data, driver)[source]#
Called after all update logic has been computed and the step has been accepted, but before the driver applies the parameter update.
At this point:
The loss and its gradient have been computed by
compute_loss_and_update().The step has been accepted (not rejected by
on_compute_update_end()).driver.step_countstill refers to the current step — it has not yet been incremented.The variational state parameters have not yet changed.
This is the right place to estimate additional observables, add data to
log_data, or take a snapshot of the state for logging. Callbacks with a lowercallback_orderrun first, so observables callbacks (order 0) are guaranteed to populatelog_databefore logger callbacks (order 10) read it.
- on_compute_update_end(step, log_data, driver)[source]#
Callback called at the end of the compute update phase, after computing the loss and its gradient.
This is called before the parameters are updated, so it can be used to implement custom logic for rejecting a step based on the computed loss or gradient.
- Return type:
- Returns:
A boolean indicating whether to reject the step (i.e. repeat it with the same parameters). If it returns None, it is treated as False.