code: def CandidateRelativeTolerance(xtol=1e-4, ftol=1e-4):
      """absolute difference in candidates is < tolerance:
  
      ``abs(xi-x0) <= xtol`` & ``abs(fi-f0) <= ftol``, with ``x=params`` & ``f=cost``
      """
      # NOTE: this termination expects nPop > 1
      doc = "CandidateRelativeTolerance with %s" % {
          "xtol": xtol,
          "ftol": ftol,
      }
  
      def _CandidateRelativeTolerance(inst, info=False):
          sim = numpy.array(inst.population)
          fsim = numpy.array(inst.popEnergy)
          if not len(fsim[1:]):
              warn = "Warning: Invalid termination condition (nPop < 2)"
              print(warn)
              return warn
          #   raise ValueError, "Invalid termination condition (nPop < 2)"
          if info:
              info = lambda x: x
          else:
              info = bool
          # FIXME: abs(inf - inf) will raise a warning...
          errdict = numpy.seterr(
              invalid="ignore"
          )  # FIXME: turn off warning
          answer = max(numpy.ravel(abs(sim[1:] - sim[0]))) <= xtol
          answer = answer and max(abs(fsim[0] - fsim[1:])) <= ftol
          numpy.seterr(
              invalid=errdict["invalid"]
          )  # FIXME: turn on warnings
          if answer:
              return info(doc)
          return info(null)
  
      _CandidateRelativeTolerance.__doc__ = doc
      return _CandidateRelativeTolerance
  
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 6 for calling a global function with example usage: CandidateRelativeTolerance(xtol, ftol) and returns: _CandidateRelativeTolerance, info, warn, info