code: def CollapseAs(
      offset=False, tolerance=1e-4, generations=50, mask=None
  ):
      """max(pairwise(x)) is < tolerance over a number of generations,
      and mask is column indices of selected params:
  
      ``bool(collapse_as(monitor, **kwds))``"""
      kwds = {
          "tolerance": tolerance,
          "generations": generations,
          "offset": offset,
          "mask": mask,
      }
      doc = "CollapseAs with %s" % kwds
  
      def _CollapseAs(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_as(inst._stepmon, **kwds): return info(doc)
          collapsed = ct.collapse_as(inst._stepmon, **kwds)
          if collapsed:
              return info(doc + " at %s" % str(collapsed))
          # otherwise bail out
          return info(null)
  
      _CollapseAs.__doc__ = doc
      return _CollapseAs
  
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 17 for calling a global function with example usage: CollapseAs(offset, tolerance, generations, mask) and returns: _CollapseAs, info, info, info, info