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 to be monotonic
  See documentation for Expect.pairwise.
  
  Parameters
  ----------
  label : None or integer (only allowed if conf is softmax)
      If None, the original prediction label
  increasing : bool
      Whether we want monotonically increasing or decreasing
  tolerance : float
      If confidence goes down (up) for monotonically increasing
      (decreasing) by less than tolerance, will not be considered a failure.
  
  Returns
  -------
  function
      an expectation function
docstr_tok: ["Expect","predictions","to","be","monotonic","See","documentation","for","Expect.pairwise",".","Parameters","--","--","--","--","--","label",":","None","or","integer","(","only","allowed","if","conf","is","softmax",")","If","None",",","the","original","prediction","label","increasing",":","bool","Whether","we","want","monotonically","increasing","or","decreasing","tolerance",":","float","If","confidence","goes","down","(","up",")","for","monotonically","increasing","(","decreasing",")","by","less","than","tolerance",",","will","not","be","considered","a","failure",".","Returns","--","--","--","-","function","an","expectation","function"]
code: def monotonic(label=None, increasing=True, tolerance=0.0):
      """Expect predictions to be monotonic
      See documentation for Expect.pairwise.
  
      Parameters
      ----------
      label : None or integer (only allowed if conf is softmax)
          If None, the original prediction label
      increasing : bool
          Whether we want monotonically increasing or decreasing
      tolerance : float
          If confidence goes down (up) for monotonically increasing
          (decreasing) by less than tolerance, will not be considered a failure.
  
      Returns
      -------
      function
          an expectation function
  
      """
      keep_label = label
  
      def expect(
          orig_pred, pred, orig_conf, conf, labels=None, meta=None
      ):
          label = keep_label
          softmax = type(orig_conf) in [np.array, np.ndarray]
          if not softmax and label is not None:
              raise (
                  Exception(
                      "Need prediction function to be softmax for monotonic if you specify label"
                  )
              )
          if label is None:
              label = orig_pred
          if softmax:
              orig_conf = orig_conf[label]
              conf = conf[label]
              conf_diff = conf - orig_conf
          else:
              if pred == orig_pred:
                  conf_diff = conf - orig_conf
              else:
                  conf_diff = -(orig_conf + conf)
          # can't fail
          if increasing and orig_conf <= tolerance:
              return None
          if not increasing and orig_conf >= 1 - tolerance:
              return None
  
          if increasing:
              if conf_diff + tolerance >= 0:
                  return True
              else:
                  return conf_diff + tolerance
              # return conf + tolerance >= orig_conf
          else:
              if conf_diff - tolerance <= 0:
                  return True
              else:
                  return -(conf_diff - tolerance)
              # return conf - tolerance <= orig_conf
  
      return Expect.pairwise(expect)
  
imports: import numpy
  import itertools
label_desc: Use image node_id 18 for calling the Expect obj's underlying member method code with example usage: obj.monotonic(label, increasing, tolerance) and returns: Expect, None, None, True, unknown, True, unknown