zero.ProgressTracker

class zero.ProgressTracker(patience, min_delta=0.0)[source]

Tracks the best score, helps with early stopping.

For ProgressTracker, the greater score is the better score. At any moment the tracker is in one of the following states:

  • success: the last update changed the best score

  • fail: last n > patience updates are not better than the best score

  • neutral: if neither success nor fail

Tutorial

progress = ProgressTracker(2)
progress.update(-999999999)
assert progress.success  # the first update always updates the best score

progress.update(123)
assert progress.success
assert progress.best_score == 123

progress.update(0)
assert not progress.success and not progress.fail

progress.update(123)
assert not progress.success and not progress.fail
progress.update(123)
# patience is 2 and the best score is not updated for more than 2 steps
assert progress.fail
assert progress.best_score == 123  # fail doesn't affect the best score
progress.update(123)
assert progress.fail  # still no improvements

progress.forget_bad_updates()
assert not progress.fail and not progress.success
assert progress.best_score == 123
progress.update(0)
assert not progress.fail  # just 1 bad update (the patience is 2)

progress.reset()
assert not progress.fail and not progress.success
assert progress.best_score is None

Attributes

best_score

The best score so far.

fail

Check if the tracker is in the ‘fail’ state.

success

Check if the tracker is in the ‘success’ state.

Methods

__init__

Initialize self.

forget_bad_updates

Reset bad updates and status, but not the best score.

reset

Reset everything.

update

Update the tracker’s state.