docstr: Sample images from a perturbation distribution by masking randomly chosen superpixels
  from the original image and replacing them with pixel values from superimposed images
  if background images are provided to the explainer. Otherwise, the superpixels from the
  original image are replaced with their average values.
  
  Parameters
  ----------
  anchor
      - ``int`` - order of anchor in the batch.
      - ``tuple`` - features (= superpixels) present in the proposed anchor.
  num_samples
      Number of samples used.
  compute_labels
      If ``True``, an array of comparisons between predictions on perturbed samples and
      instance to be explained is returned.
  
  Returns
  -------
  If ``compute_labels=True``, a list containing the following is returned
  
   - `covered_true` - perturbed examples where the anchor applies and the model prediction  on perturbed is the          same as the instance prediction.
  
   - `covered_false` - perturbed examples where the anchor applies and the model prediction on pertrurbed sample          is NOT the same as the instance prediction.
  
   - `labels` - `num_samples` ints indicating whether the prediction on the perturbed sample matches (1)          the label of the instance to be explained or not (0).
  
   - `data` - Matrix with 1s and 0s indicating whether the values in a superpixel will remain unchanged (1) or          will be perturbed (0), for each sample.
  
   - `-1.0` - indicates exact coverage is not computed for this algorithm.
  
   - `anchor[0]` - position of anchor in the batch request
  
  Otherwise, a list containing the data matrix only is returned.
docstr_tok: ["Sample","images","from","a","perturbation","distribution","by","masking","randomly","chosen","superpixels","from","the","original","image","and","replacing","them","with","pixel","values","from","superimposed","images","if","background","images","are","provided","to","the","explainer",".","Otherwise",",","the","superpixels","from","the","original","image","are","replaced","with","their","average","values",".","Parameters","--","--","--","--","--","anchor","-","``","int","``","-","order","of","anchor","in","the","batch",".","-","``","tuple","``","-","features","(","=","superpixels",")","present","in","the","proposed","anchor",".","num_samples","Number","of","samples","used",".","compute_labels","If","``","True","``",",","an","array","of","comparisons","between","predictions","on","perturbed","samples","and","instance","to","be","explained","is","returned",".","Returns","--","--","--","-","If","``","compute_labels=True","``",",","a","list","containing","the","following","is","returned","-","`","covered_true","`","-","perturbed","examples","where","the","anchor","applies","and","the","model","prediction","on","perturbed","is","the","same","as","the","instance","prediction",".","-","`","covered_false","`","-","perturbed","examples","where","the","anchor","applies","and","the","model","prediction","on","pertrurbed","sample","is","NOT","the","same","as","the","instance","prediction",".","-","`","labels","`","-","`","num_samples","`","ints","indicating","whether","the","prediction","on","the","perturbed","sample","matches","(","1",")","the","label","of","the","instance","to","be","explained","or","not","(","0",")",".","-","`","data","`","-","Matrix","with","1s","and","0s","indicating","whether","the","values","in","a","superpixel","will","remain","unchanged","(","1",")","or","will","be","perturbed","(","0",")",",","for","each","sample",".","-","`","-1.0","`","-","indicates","exact","coverage","is","not","computed","for","this","algorithm",".","-","`","anchor","[","0","]","`","-","position","of","anchor","in","the","batch","request","Otherwise",",","a","list","containing","the","data","matrix","only","is","returned","."]
code: def __call__(
      self,
      anchor: Tuple[int, tuple],
      num_samples: int,
      compute_labels: bool = True,
  ) -> List[Union[np.ndarray, float, int]]:
      """
          Sample images from a perturbation distribution by masking randomly chosen superpixels
          from the original image and replacing them with pixel values from superimposed images
          if background images are provided to the explainer. Otherwise, the superpixels from the
          original image are replaced with their average values.
  
          Parameters
          ----------
          anchor
              - ``int`` - order of anchor in the batch.
              - ``tuple`` - features (= superpixels) present in the proposed anchor.
          num_samples
              Number of samples used.
          compute_labels
              If ``True``, an array of comparisons between predictions on perturbed samples and
              instance to be explained is returned.
  
          Returns
          -------
          If ``compute_labels=True``, a list containing the following is returned
  
           - `covered_true` - perturbed examples where the anchor applies and the model prediction  on perturbed is the \
           same as the instance prediction.
  
           - `covered_false` - perturbed examples where the anchor applies and the model prediction on pertrurbed sample \
           is NOT the same as the instance prediction.
  
           - `labels` - `num_samples` ints indicating whether the prediction on the perturbed sample matches (1) \
           the label of the instance to be explained or not (0).
  
           - `data` - Matrix with 1s and 0s indicating whether the values in a superpixel will remain unchanged (1) or \
           will be perturbed (0), for each sample.
  
           - `-1.0` - indicates exact coverage is not computed for this algorithm.
  
           - `anchor[0]` - position of anchor in the batch request
  
          Otherwise, a list containing the data matrix only is returned.
          """
  
      if compute_labels:
          raw_data, data = self.perturbation(anchor[1], num_samples)
          labels = self.compare_labels(raw_data)
          covered_true = raw_data[labels][: self.n_covered_ex]
          covered_true = [scale_image(img) for img in covered_true]
          covered_false = raw_data[np.logical_not(labels)][
              : self.n_covered_ex
          ]
          covered_false = [scale_image(img) for img in covered_false]
          # coverage set to -1.0 as we can't compute 'true' coverage for this model
  
          return [
              covered_true,
              covered_false,
              labels.astype(int),
              data,
              -1.0,
              anchor[0],
          ]
  
      else:
          data = self._choose_superpixels(num_samples)
          data[
              :, anchor[1]
          ] = 1  # superpixels in candidate anchor are not perturbed
  
          return [data]
  
imports: import copy
  import logging
  from functools import partial
  from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union
  import numpy
  from skimage.segmentation import felzenszwalb, quickshift, slic
  from alibi.api.defaults import DEFAULT_DATA_ANCHOR_IMG, DEFAULT_META_ANCHOR
  from alibi.api.interfaces import Explainer, Explanation
  from alibi.exceptions import PredictorCallError, PredictorReturnTypeError
  from alibi.utils.wrappers import ArgmaxTransformer
  from .anchor_base import AnchorBaseBeam
  from .anchor_explanation import AnchorExplanation
label_desc: Use image node_id 2 for calling the AnchorImageSampler obj's underlying member method code with example usage: obj.__call__(anchor, num_samples, compute_labels) and returns: list, list