class_docstr: Early stopping to avoid overfitting during training.
  
  The following example stops training early if the difference between losses
  recorded in the current epoch and previous epoch is less than 1e-3
  consecutively for 2 times::
  
    >>> from flax.training.early_stopping import EarlyStopping
  
    >>> def train_epoch(optimizer, train_ds, batch_size, epoch, input_rng):
    ...   ...
    ...   loss = [4, 3, 3, 3, 2, 2, 2, 2, 1, 1][epoch]
    ...   return None, {'loss': loss}
  
    >>> early_stop = EarlyStopping(min_delta=1e-3, patience=2)
    >>> optimizer = None
    >>> for epoch in range(10):
    ...   optimizer, train_metrics = train_epoch(
    ...       optimizer=optimizer, train_ds=None, batch_size=None, epoch=epoch, input_rng=None)
    ...   early_stop = early_stop.update(train_metrics['loss'])
    ...   if early_stop.should_stop:
    ...     print(f'Met early stopping criteria, breaking at epoch {epoch}')
    ...     break
    Met early stopping criteria, breaking at epoch 7
  
  Attributes:
    min_delta: Minimum delta between updates to be considered an
        improvement.
    patience: Number of steps of no improvement before stopping.
    best_metric: Current best metric value.
    patience_count: Number of steps since last improving update.
    should_stop: Whether the training loop should stop to avoid
        overfitting.
    has_improved: Whether the metric has improved greater or
      equal to the min_delta in the last ``.update`` call.
class_docstr_tok: ["Early","stopping","to","avoid","overfitting","during","training",".","The","following","example","stops","training","early","if","the","difference","between","losses","recorded","in","the","current","epoch","and","previous","epoch","is","less","than","1e-3","consecutively","for","2","times",":",":",">",">",">","from","flax.training.early_stopping","import","EarlyStopping",">",">",">","def","train_epoch","(","optimizer",",","train_ds",",","batch_size",",","epoch",",","input_rng",")",":","...","...","...","loss","=","[","4",",","3",",","3",",","3",",","2",",","2",",","2",",","2",",","1",",","1","]","[","epoch","]","...","return","None",",","{","'loss","'",":","loss","}",">",">",">","early_stop","=","EarlyStopping","(","min_delta=1e-3",",","patience=2",")",">",">",">","optimizer","=","None",">",">",">","for","epoch","in","range","(","10",")",":","...","optimizer",",","train_metrics","=","train_epoch","(","...","optimizer=optimizer",",","train_ds=None",",","batch_size=None",",","epoch=epoch",",","input_rng=None",")","...","early_stop","=","early_stop.update","(","train_metrics","[","'loss","'","]",")","...","if","early_stop.should_stop",":","...","print","(","f'Met","early","stopping","criteria",",","breaking","at","epoch","{","epoch","}","'",")","...","break","Met","early","stopping","criteria",",","breaking","at","epoch","7","Attributes",":","min_delta",":","Minimum","delta","between","updates","to","be","considered","an","improvement",".","patience",":","Number","of","steps","of","no","improvement","before","stopping",".","best_metric",":","Current","best","metric","value",".","patience_count",":","Number","of","steps","since","last","improving","update",".","should_stop",":","Whether","the","training","loop","should","stop","to","avoid","overfitting",".","has_improved",":","Whether","the","metric","has","improved","greater","or","equal","to","the","min_delta","in","the","last","``",".update","``","call","."]
code: def reset(self):
      return self.replace(
          best_metric=float("inf"),
          patience_count=0,
          should_stop=False,
          has_improved=False,
      )
  
imports: import math
  from flax import struct
label_desc: Use image node_id 1 for calling the EarlyStopping obj's underlying member method code with example usage: obj.reset() and returns: self