class_docstr: Implementation of Sufficiency test by Dasgupta et al., 2022.
  
  The (global) sufficiency metric measures the expected local sufficiency. Local sufficiency measures the probability
  of the prediction label for a given datapoint coinciding with the prediction labels of other data points that the
  same explanation applies to. For example, if the explanation of a given image is "contains zebra", the local
  sufficiency metric measures the probability a different that contains zebra having the same prediction label.
  
  Assumptions:
      - We assume that a given explanation applies to 'anothers' data point if the distance between
      the explanation and the explanations of the data point is under the user-defined threshold.
  
  References:
       1) Sanjoy Dasgupta et al.: "Framework for Evaluating Faithfulness of Local
          Explanations." ICML (2022): 4794-4815.
  
  Attributes:
      -  _name: The name of the metric.
      - _data_applicability: The data types that the metric implementation currently supports.
      - _models: The model types that this metric can work with.
      - score_direction: How to interpret the scores, whether higher/ lower values are considered better.
      - evaluation_category: What property/ explanation quality that this metric measures.
class_docstr_tok: ["Implementation","of","Sufficiency","test","by","Dasgupta","et","al.",",","2022",".","The","(","global",")","sufficiency","metric","measures","the","expected","local","sufficiency",".","Local","sufficiency","measures","the","probability","of","the","prediction","label","for","a","given","datapoint","coinciding","with","the","prediction","labels","of","other","data","points","that","the","same","explanation","applies","to",".","For","example",",","if","the","explanation","of","a","given","image","is","``","contains","zebra","''",",","the","local","sufficiency","metric","measures","the","probability","a","different","that","contains","zebra","having","the","same","prediction","label",".","Assumptions",":","-","We","assume","that","a","given","explanation","applies","to","'anothers","'","data","point","if","the","distance","between","the","explanation","and","the","explanations","of","the","data","point","is","under","the","user-defined","threshold",".","References",":","1",")","Sanjoy","Dasgupta","et","al",".",":","``","Framework","for","Evaluating","Faithfulness","of","Local","Explanations",".","''","ICML","(","2022",")",":","4794-4815",".","Attributes",":","-","_name",":","The","name","of","the","metric",".","-","_data_applicability",":","The","data","types","that","the","metric","implementation","currently","supports",".","-","_models",":","The","model","types","that","this","metric","can","work","with",".","-","score_direction",":","How","to","interpret","the","scores",",","whether","higher\/","lower","values","are","considered","better",".","-","evaluation_category",":","What","property\/","explanation","quality","that","this","metric","measures","."]
docstr: Compute additional arguments required for Sufficiency evaluation on batch-level.
docstr_tok: ["Compute","additional","arguments","required","for","Sufficiency","evaluation","on","batch-level","."]
code: def custom_batch_preprocess(
      self,
      model: ModelInterface,
      x_batch: np.ndarray,
      a_batch: np.ndarray,
      **kwargs,
  ) -> Dict[str, np.ndarray]:
      """Compute additional arguments required for Sufficiency evaluation on batch-level."""
  
      a_batch_flat = a_batch.reshape(a_batch.shape[0], -1)
      dist_matrix = cdist(
          a_batch_flat, a_batch_flat, self.distance_func, V=None
      )
      dist_matrix = self.normalise_func(dist_matrix)
      a_sim_matrix = np.zeros_like(dist_matrix)
      a_sim_matrix[dist_matrix <= self.threshold] = 1
  
      # Predict on input.
      x_input = model.shape_input(
          x_batch, x_batch[0].shape, channel_first=True, batched=True
      )
      y_pred_classes = np.argmax(
          model.predict(x_input), axis=1
      ).flatten()
  
      return {
          "i_batch": np.arange(x_batch.shape[0]),
          "a_sim_vector_batch": a_sim_matrix,
          "y_pred_classes": y_pred_classes,
      }
  
file_path: Quantus/quantus/metrics/faithfulness/sufficiency.py
imports: import sys
  from typing import Any, Callable, Dict, List, Optional, no_type_check
  import numpy
  from scipy.spatial.distance import cdist
  from quantus.helpers.model.model_interface import ModelInterface
  from quantus.helpers import warn
  from quantus.helpers.enums import DataType, EvaluationCategory, ModelType, ScoreDirection
  from quantus.metrics.base import Metric
label_desc: Use image node_id 4 for calling the Sufficiency obj's underlying member method code with example usage: obj.custom_batch_preprocess(model, x_batch, a_batch) and returns: dict