class_docstr: To run: "python -m saliency.core.xrai_test" from the top-level directory.
class_docstr_tok: ["To","run",":","``","python","-m","saliency.core.xrai_test","''","from","the","top-level","directory","."]
docstr: Performs general XRAIOutput verification that is applicable for all XRAI results.
docstr_tok: ["Performs","general","XRAIOutput","verification","that","is","applicable","for","all","XRAI","results","."]
code: def _assert_xrai_correctness(self, xrai_out, is_flatten_segments):
      """Performs general XRAIOutput verification that is applicable for all XRAI results."""
      xrai_attribution_mask = xrai_out.attribution_mask
      xrai_segments = xrai_out.segments
  
      # Check completeness with respect to IG attribution.
      self.assertAlmostEqual(
          self.ig_mask.max(axis=2).sum(),
          xrai_attribution_mask.sum(),
          msg="The sum of IG attribution (max along the color "
          "axis) should be equal to the sum of XRAI "
          "attribution.",
      )
  
      # Check that the returned IG values are the same as returned by IG.
      self.assertTrue(
          np.array_equal(self.ig_bl_1_attr, xrai_out.ig_attribution[0]),
          msg="IG values returned by IG and returned to the client do not match.",
      )
      self.assertTrue(
          np.array_equal(self.ig_bl_2_attr, xrai_out.ig_attribution[1]),
          msg="IG values returned by IG and returned to the client do not match.",
      )
  
      # If the result is flattened, verify that the first segment is assigned
      # value 1. Convert the flattened integer segments to individual boolean
      # segments.
      segment_masks = []
      if is_flatten_segments:
          first_segment_id = xrai_segments.min()
          last_segment_id = xrai_segments.max()
          self.assertEqual(
              1,
              first_segment_id,
              msg="The first segment should" ' be assigned value "1".',
          )
          for segment_id in range(
              first_segment_id, last_segment_id + 1
          ):
              segment_masks.append(xrai_segments == segment_id)
      else:
          segment_masks = xrai_segments
  
      # Verify that 1) the segments are ordered according to their attribution;
      # 2) that every segment preserves the completeness properties;
      # 3) all pixels within a single segment have the same attribution.
      prev_seg_attr = np.inf
      for i, segment_mask in enumerate(segment_masks):
          segment_id = i + 1
          segment_attr = xrai_attribution_mask[segment_mask]
          self.assertGreater(
              segment_mask.sum(),
              0,
              msg="Segment {} of {} has zero area.".format(
                  segment_id, len(segment_masks)
              ),
          )
          self.assertEqual(
              segment_attr.min(),
              segment_attr.max(),
              "All attribution values within a single segment should "
              "be equal.",
          )
          segment_attr = segment_attr.max()
          self.assertAlmostEqual(
              self.ig_mask.max(axis=2)[segment_mask].sum(),
              xrai_attribution_mask[segment_mask].sum(),
              msg="The sum of the XRAI attribution within a "
              "segment should be equal to the sum of IG "
              "attribution within the same segment.",
          )
          # The last segment may have attribution higher than the previous one
          # because it includes all pixels that weren't included by the previous
          # segments.
          if i < len(segment_masks) - 1:
              self.assertLessEqual(
                  segment_attr,
                  prev_seg_attr,
                  "Pixel attributions of a segment with higher id "
                  "should be lower than pixel attributions of a "
                  "segment with a lower id. Segment {}".format(
                      segment_id
                  ),
              )
          prev_seg_attr = segment_attr
  
imports: import unittest
  import unittest.mock
  import numpy
  import skimage.draw
  from .None import xrai
  from .xrai import XRAI
  from .xrai import XRAIParameters
label_desc: Use image node_id 12 for calling the XraiTest obj's underlying member method code with example usage: obj._assert_xrai_correctness(xrai_out, is_flatten_segments) without return types