code: def CollapseAt(
      target=None, tolerance=1e-4, generations=50, mask=None
  ):
      """change(x[i]) is < tolerance over a number of generations,
      where target can be a single value or a list of values of x length,
      change(x[i]) = max(x[i]) - min(x[i]) if target=None else abs(x[i] - target),
      and mask is column indices of selected params:
  
      ``bool(collapse_at(monitor, **kwds))``"""
      kwds = {
          "tolerance": tolerance,
          "generations": generations,
          "target": target,
          "mask": mask,
      }
      doc = "CollapseAt with %s" % kwds
  
      def _CollapseAt(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)
          # XXX: might want to log/utilize *where* collapse happens...
          #       if ct.collapse_at(inst._stepmon, **kwds): return info(doc)
          collapsed = ct.collapse_at(inst._stepmon, **kwds)
          if collapsed:
              return info(doc + " at %s" % str(collapsed))
          # otherwise bail out
          return info(null)
  
      _CollapseAt.__doc__ = doc
      return _CollapseAt
  
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 16 for calling a global function with example usage: CollapseAt(target, tolerance, generations, mask) and returns: _CollapseAt, info, info, info, info