code: def NormalizedChangeOverGeneration(tolerance=1e-4, generations=10):
      """normalized change in cost is < tolerance over number of generations:
  
      ``(cost[-g] - cost[-1]) / 0.5*(abs(cost[-g]) + abs(cost[-1])) <= tolerance``
      """
      eta = 1e-20
      doc = "NormalizedChangeOverGeneration with %s" % {
          "tolerance": tolerance,
          "generations": generations,
      }
  
      def _NormalizedChangeOverGeneration(inst, info=False):
          if info:
              info = lambda x: x
          else:
              info = bool
          hist = inst.energy_history
          lg = len(hist)
          if not lg:
              return info(null)
          if lg <= generations:
              return info(null)
          if hist[-generations] == hist[-1]:
              return info(doc)
          diff = (
              tolerance * (abs(hist[-generations]) + abs(hist[-1]))
              + eta
          )
          if 2.0 * (hist[-generations] - hist[-1]) <= diff:
              return info(doc)
          return info(null)
  
      _NormalizedChangeOverGeneration.__doc__ = doc
      return _NormalizedChangeOverGeneration
  
imports: import numpy
  import mystic.collapse
  from mystic.math.distance import Lnorm
  from mystic._scipy060optimize import approx_fprime, _epsilon
label_desc: Use image node_id 5 for calling a global function with example usage: NormalizedChangeOverGeneration(tolerance, generations) and returns: _NormalizedChangeOverGeneration, info, info, info, info, info