class_docstr: Abstract class for model trainers.
class_docstr_tok: ["Abstract","class","for","model","trainers","."]
docstr: Checks if training for a model has converged.
docstr_tok: ["Checks","if","training","for","a","model","has","converged","."]
code: def check_convergence(
      self,
      prev_loss,
      loss,
      step,
      max_iter,
      iter_below_tol,
      min_num_iter=0,
  ):
      """Checks if training for a model has converged."""
      has_converged = False
  
      # Check if we have reached the desired loss tolerance.
      loss_diff = abs(prev_loss - loss)
      if (
          loss_diff < self.abs_loss_chg_tol
          or abs(loss_diff / prev_loss) < self.rel_loss_chg_tol
      ):
          iter_below_tol += 1
      else:
          iter_below_tol = 0
      if iter_below_tol >= self.loss_chg_iter_below_tol:
          # print('Loss value converged.')
          has_converged = True
  
      # Make sure that irrespective of the stop criteria, the minimum required
      # number of iterations is achieved.
      if step < min_num_iter:
          has_converged = False
      else:
          has_converged = True
  
      # Make sure we don't exceed the max allowed number of iterations.
      if max_iter is not None and step >= max_iter:
          print("Maximum number of iterations reached.")
          has_converged = True
      return has_converged, iter_below_tol
  
file_path: neural-structured-learning/research/gam/gam/trainer/trainer_base.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import abc
  import numpy
  import tensorflow
label_desc: Use image node_id 3 for calling the Trainer obj's underlying member method code with example usage: obj.check_convergence(prev_loss, loss, step, max_iter, iter_below_tol, min_num_iter) and returns: has_converged,  iter_below_tol