nlsq.callbacks.EarlyStopping

class nlsq.callbacks.EarlyStopping(patience=10, min_delta=1e-06, verbose=True)[source]

Bases: CallbackBase

Stop optimization early if no improvement for patience iterations.

Parameters:
  • patience (int, optional) – Number of iterations with no improvement to wait before stopping. Default: 10

  • min_delta (float, optional) – Minimum change in cost to qualify as an improvement. Default: 1e-6

  • verbose (bool, optional) – Whether to print messages. Default: True

Examples

>>> from nlsq.callbacks import EarlyStopping
>>> callback = EarlyStopping(patience=5, min_delta=1e-4)
>>> popt, pcov = curve_fit(f, x, y, callback=callback)

Notes

Raises StopOptimization exception when patience is exceeded, which will be caught by the optimizer and treated as successful convergence.

__init__(patience=10, min_delta=1e-06, verbose=True)[source]
__call__(iteration, cost, params, info)[source]

Check for improvement and stop if patience exceeded.