code: def collapse_as(
      stepmon, offset=False, tolerance=0.005, generations=50, mask=None
  ):
      """return a set of pairs of indices where the parameters exhibit a
      dimensional collapse. Dimensional collapse is defined by:
      max(pairwise(parameters)) <= tolerance over N generations (offset=False),
      ptp(pairwise(parameters)) <= tolerance over N generations (offset=True).
  
      collapse will be ignored at any pairs of indices specififed in the mask.
      If single indices are provided, ignore all pairs with the given indices.
      """
      np = _m.numpy
      # reject bad masks
      if mask is None:
          pass
      elif type(mask) is set:
          for i in mask:
              if hasattr(i, "__len__") and len(i) != 2:
                  msg = "bad element '%s' in mask" % str(i)
                  raise ValueError(msg)
      else:
          msg = "%s is not a valid mask" % str(mask)
          raise TypeError(msg)
      # is the max position difference less than tolerance across all generations?
      distances = _m._solutions(stepmon, generations)
      # FIXME: HACK: array should be ndim=2... apparently sometimes it's ndim=3
      if distances.ndim == 3 and distances.shape[-1] == 1:
          distances.shape = distances.shape[:-1]
      elif distances.ndim < 3:
          pass
      else:
          msg = (
              "could not extract pairwise distances from array with shape %s"
              % distances.shape
          )
          raise ValueError(msg)
      nindices = distances.shape[-1]
      # get distances and pairs of indices
      from mystic.tools import pairwise
  
      distances, pairs = pairwise(distances, True)
      if offset:  # tracking at a distance
          distances = distances.ptp(axis=0) <= tolerance
      else:  # tracking with the same position
          distances = distances.max(axis=0) <= tolerance
      # get the (index1,index2) pairs where the collapse occurs
      if distances.ndim > 1:
          distances.shape = tuple(
              i for i in distances.shape if i != 1
          ) or (1,)
      distances = np.array(pairs)[distances]
      # apply mask
      if mask is None:
          return set(tuple(i) for i in distances)
      mask = selector(mask)
      return set(tuple(i) for i in distances if not mask(i))
  
file_path: mystic/mystic/collapse.py
imports: import mystic.monitors
label_desc: Use image node_id 2 for calling a global function with example usage: collapse_as(stepmon, offset, tolerance, generations, mask) and returns: set, set