class_docstr: Stop training when a monitored metric has stopped improving.
  
  Assuming the goal of a training is to minimize the loss. With this, the
  metric to be monitored would be 'loss', and mode would be 'min'. A
  `model.fit()` training loop will check at end of every epoch whether
  the loss is no longer decreasing, considering the `min_delta` and
  `patience` if applicable. Once it's found no longer decreasing,
  `model.stop_training` is marked True and the training terminates.
  
  The quantity to be monitored needs to be available in `logs` dict.
  To make it so, pass the loss or metrics at `model.__init__()`.
  
  Example:
  ```python
  np.random.seed(42)
  class MLP(elegy.Module):
      def call(self, input):
          mlp = elegy.Sequential([elegy.nn.Linear(10),])
          return mlp(input)
  
  callback = elegy.callbacks.EarlyStopping(monitor="loss", patience=3)
  # This callback will stop the training when there is no improvement in
  # the for three consecutive epochs.
  model = elegy.Model(
      module=MLP(),
      loss=elegy.losses.MeanSquaredError(),
      optimizer=optax.rmsprop(0.01),
  )
  history = model.fit(
      np.arange(100).reshape(5, 20).astype(np.float32),
      np.zeros(5),
      epochs=10,
      batch_size=1,
      callbacks=[callback],
      verbose=0,
  )
  assert len(history.history["loss"]) == 7  # Only 7 epochs are run.
  ```
class_docstr_tok: ["Stop","training","when","a","monitored","metric","has","stopped","improving",".","Assuming","the","goal","of","a","training","is","to","minimize","the","loss",".","With","this",",","the","metric","to","be","monitored","would","be","'loss","'",",","and","mode","would","be","'min","'",".","A","`","model.fit","(",")","`","training","loop","will","check","at","end","of","every","epoch","whether","the","loss","is","no","longer","decreasing",",","considering","the","`","min_delta","`","and","`","patience","`","if","applicable",".","Once","it","'s","found","no","longer","decreasing",",","`","model.stop_training","`","is","marked","True","and","the","training","terminates",".","The","quantity","to","be","monitored","needs","to","be","available","in","`","logs","`","dict",".","To","make","it","so",",","pass","the","loss","or","metrics","at","`","model.__init__","(",")","`",".","Example",":","``","`","python","np.random.seed","(","42",")","class","MLP","(","elegy.Module",")",":","def","call","(","self",",","input",")",":","mlp","=","elegy.Sequential","(","[","elegy.nn.Linear","(","10",")",",","]",")","return","mlp","(","input",")","callback","=","elegy.callbacks.EarlyStopping","(","monitor=","''","loss","''",",","patience=3",")","#","This","callback","will","stop","the","training","when","there","is","no","improvement","in","#","the","for","three","consecutive","epochs",".","model","=","elegy.Model","(","module=MLP","(",")",",","loss=elegy.losses.MeanSquaredError","(",")",",","optimizer=optax.rmsprop","(","0.01",")",",",")","history","=","model.fit","(","np.arange","(","100",")",".reshape","(","5",",","20",")",".astype","(","np.float32",")",",","np.zeros","(","5",")",",","epochs=10",",","batch_size=1",",","callbacks=","[","callback","]",",","verbose=0",",",")","assert","len","(","history.history","[","``","loss","''","]",")","==","7","#","Only","7","epochs","are","run",".","``","`"]
code: def on_train_begin(self, logs=None):
      # Allow instances to be re-used
      self.wait = 0
      self.stopped_epoch = 0
      if self.baseline is not None:
          self.best = self.baseline
      else:
          self.best = np.Inf if self.monitor_op == np.less else -np.Inf
  
file_path: elegy/elegy/callbacks/early_stopping.py
imports: import logging
  import typing
  import numpy
  from .callback import Callback
label_desc: Use image node_id 2 for calling the EarlyStopping obj's underlying member method code with example usage: obj.on_train_begin(logs) without return types