class_docstr: Helpers for writing expectation functions over tests.
  Each test has a list of testcases, and each testcase has a list of examples.
  Expectation function will act on whole tests, testcases, individual examples, or pairs of examples.
  In any of these, the output of an expectation function for a single example
  is an integer, float, bool, or None, where:
      > 0 (or True) means passed,
      <= 0 or False means fail, and (optionally) the magnitude of the
        failure, indicated by distance from 0, e.g. -10 is worse than -1
      None means the test does not apply, and this should not be counted
docstr: Expect predictions not to change, with a tolerance threshold
  See documentation for Expect.pairwise.
  
  Parameters
  ----------
  tolerance : float
      If prediction changes but prediction probability is within the tolerance,
      will not consider it a failure.
  
  Returns
  -------
  function
      an expectation function
docstr_tok: ["Expect","predictions","not","to","change",",","with","a","tolerance","threshold","See","documentation","for","Expect.pairwise",".","Parameters","--","--","--","--","--","tolerance",":","float","If","prediction","changes","but","prediction","probability","is","within","the","tolerance",",","will","not","consider","it","a","failure",".","Returns","--","--","--","-","function","an","expectation","function"]
code: def inv(tolerance=0):
      """Expect predictions not to change, with a tolerance threshold
      See documentation for Expect.pairwise.
  
      Parameters
      ----------
      tolerance : float
          If prediction changes but prediction probability is within the tolerance,
          will not consider it a failure.
  
      Returns
      -------
      function
          an expectation function
  
      """
  
      def expect(
          orig_pred, pred, orig_conf, conf, labels=None, meta=None
      ):
          softmax = type(orig_conf) in [np.array, np.ndarray]
          try:
              if pred == orig_pred:
                  return True
          except ValueError:  # np.array output
              if (pred == orig_pred).all():
                  return True
          if softmax:
              orig_conf = orig_conf[orig_pred]
              conf = conf[orig_pred]
              if np.abs(conf - orig_conf) <= tolerance:
                  return True
              else:
                  return -np.abs(conf - orig_conf)
          else:
              # This is being generous I think
              if conf + orig_conf <= tolerance:
                  return True
              else:
                  return -(conf + orig_conf)
  
      return Expect.pairwise(expect)
  
imports: import numpy
  import itertools
label_desc: Use image node_id 17 for calling the Expect obj's underlying member method code with example usage: obj.inv(tolerance) and returns: Expect, True, True, unknown, True, unknown, True