class_docstr: An epoch counter which can save and recall its state, integrating an early stopper by tracking a target metric.
  
  Arguments
  ---------
  limit: int
      maximum number of epochs
  limit_to_stop : int
      maximum number of consecutive epochs without improvements in performance
  limit_warmup : int
      number of epochs to wait until start checking for early stopping
  direction : "max" or "min"
      direction to optimize the target metric
  
  Example
  -------
  >>> limit = 10
  >>> limit_to_stop = 5
  >>> limit_warmup = 2
  >>> direction = "min"
  >>> epoch_counter = EpochCounterWithStopper(limit, limit_to_stop, limit_warmup, direction)
  >>> for epoch in epoch_counter:
  ...     # Run training...
  ...     # Track a validation metric, (insert calculation here)
  ...     current_valid_metric = 0
  ...     # Update epoch counter so that we stop at the appropriate time
  ...     epoch_counter.update_metric(current_valid_metric)
  ...     print(epoch)
  1
  2
  3
  4
  5
  6
  7
  8
class_docstr_tok: ["An","epoch","counter","which","can","save","and","recall","its","state",",","integrating","an","early","stopper","by","tracking","a","target","metric",".","Arguments","--","--","--","--","-","limit",":","int","maximum","number","of","epochs","limit_to_stop",":","int","maximum","number","of","consecutive","epochs","without","improvements","in","performance","limit_warmup",":","int","number","of","epochs","to","wait","until","start","checking","for","early","stopping","direction",":","``","max","''","or","``","min","''","direction","to","optimize","the","target","metric","Example","--","--","--","-",">",">",">","limit","=","10",">",">",">","limit_to_stop","=","5",">",">",">","limit_warmup","=","2",">",">",">","direction","=","``","min","''",">",">",">","epoch_counter","=","EpochCounterWithStopper","(","limit",",","limit_to_stop",",","limit_warmup",",","direction",")",">",">",">","for","epoch","in","epoch_counter",":","...","#","Run","training","...","...","#","Track","a","validation","metric",",","(","insert","calculation","here",")","...","current_valid_metric","=","0","...","#","Update","epoch","counter","so","that","we","stop","at","the","appropriate","time","...","epoch_counter.update_metric","(","current_valid_metric",")","...","print","(","epoch",")","1","2","3","4","5","6","7","8"]
docstr: Update the state to reflect most recent value of the relevant metric.
  
  NOTE: Should be called only once per validation loop.
  
  Arguments
  ---------
  current_metric : float
      The metric used to make a stopping decision.
docstr_tok: ["Update","the","state","to","reflect","most","recent","value","of","the","relevant","metric",".","NOTE",":","Should","be","called","only","once","per","validation","loop",".","Arguments","--","--","--","--","-","current_metric",":","float","The","metric","used","to","make","a","stopping","decision","."]
code: def update_metric(self, current_metric):
      """Update the state to reflect most recent value of the relevant metric.
  
      NOTE: Should be called only once per validation loop.
  
      Arguments
      ---------
      current_metric : float
          The metric used to make a stopping decision.
      """
      if self.current > self.limit_warmup:
          if self.sign * current_metric < self.sign * (
              (1 - self.min_delta) * self.best_score
          ):
              self.best_limit = self.current
              self.best_score = current_metric
  
          epochs_without_improvement = self.current - self.best_limit
          self.should_stop = (
              epochs_without_improvement >= self.limit_to_stop
          )
          if self.should_stop:
              logger.info(
                  f"{epochs_without_improvement} epochs without improvement.\n"
                  f"Patience of {self.limit_to_stop} is exhausted, stopping."
              )
  
file_path: speechbrain/speechbrain/utils/epoch_loop.py
imports: from .checkpoints import register_checkpoint_hooks
  from .checkpoints import mark_as_saver
  from .checkpoints import mark_as_loader
  import logging
  import yaml
label_desc: Use image node_id 3 for calling the EpochCounterWithStopper obj's underlying member method code with example usage: obj.update_metric(current_metric) without return types