class_docstr: Implementation of Sensitivity-N test by Ancona et al., 2019.
  
  An attribution method satisfies Sensitivity-n when the sum of the attributions for any subset of features of
  cardinality n is equal to the variation of the output Sc caused removing the features in the subset. The test
  computes the correlation between sum of attributions and delta output.
  
  Pearson correlation coefficient (PCC) is computed between the sum of the attributions and the variation in the
  target output varying n from one to about 80% of the total number of features, where an average across a thousand
  of samples is reported. Sampling is performed using a uniform probability distribution over the features.
  
  References:
      1) Marco Ancona et al.: "Towards better understanding of gradient-based attribution
      methods for deep neural networks." ICLR (Poster) (2018).
  
  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","Sensitivity-N","test","by","Ancona","et","al.",",","2019",".","An","attribution","method","satisfies","Sensitivity-n","when","the","sum","of","the","attributions","for","any","subset","of","features","of","cardinality","n","is","equal","to","the","variation","of","the","output","Sc","caused","removing","the","features","in","the","subset",".","The","test","computes","the","correlation","between","sum","of","attributions","and","delta","output",".","Pearson","correlation","coefficient","(","PCC",")","is","computed","between","the","sum","of","the","attributions","and","the","variation","in","the","target","output","varying","n","from","one","to","about","80","%","of","the","total","number","of","features",",","where","an","average","across","a","thousand","of","samples","is","reported",".","Sampling","is","performed","using","a","uniform","probability","distribution","over","the","features",".","References",":","1",")","Marco","Ancona","et","al",".",":","``","Towards","better","understanding","of","gradient-based","attribution","methods","for","deep","neural","networks",".","''","ICLR","(","Poster",")","(","2018",")",".","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: Post-process the evaluation results.
  
  Parameters
  ----------
  x_batch: np.ndarray
      A np.ndarray which contains the input data that are explained.
  kwargs:
      Unused.
  
  Returns
  -------
  None
docstr_tok: ["Post-process","the","evaluation","results",".","Parameters","--","--","--","--","--","x_batch",":","np.ndarray","A","np.ndarray","which","contains","the","input","data","that","are","explained",".","kwargs",":","Unused",".","Returns","--","--","--","-","None"]
code: def custom_postprocess(
      self,
      x_batch: np.ndarray,
      **kwargs,
  ) -> None:
      """
      Post-process the evaluation results.
  
      Parameters
      ----------
      x_batch: np.ndarray
          A np.ndarray which contains the input data that are explained.
      kwargs:
          Unused.
  
      Returns
      -------
      None
      """
      max_features = int(
          self.n_max_percentage
          * np.prod(x_batch.shape[2:])
          // self.features_in_step
      )
  
      # Get pred_deltas and att_sums from result list.
      sub_results_pred_deltas: List[Any] = [
          r["pred_deltas"] for r in self.evaluation_scores
      ]
      sub_results_att_sums: List[Any] = [
          r["att_sums"] for r in self.evaluation_scores
      ]
  
      # Re-arrange sub-lists so that they are sorted by n.
      sub_results_pred_deltas_l: Dict[int, Any] = {
          k: [] for k in range(max_features)
      }
      sub_results_att_sums_l: Dict[int, Any] = {
          k: [] for k in range(max_features)
      }
  
      for k in range(max_features):
          for pred_deltas_instance in sub_results_pred_deltas:
              sub_results_pred_deltas_l[k].append(
                  pred_deltas_instance[k]
              )
          for att_sums_instance in sub_results_att_sums:
              sub_results_att_sums_l[k].append(att_sums_instance[k])
  
      # Compute the similarity for each n.
      self.evaluation_scores = [
          self.similarity_func(
              a=sub_results_att_sums_l[k],
              b=sub_results_pred_deltas_l[k],
          )
          for k in range(max_features)
      ]
  
file_path: Quantus/quantus/metrics/faithfulness/sensitivity_n.py
imports: import sys
  from typing import Any, Callable, Dict, List, Optional
  import numpy
  from quantus.functions.normalise_func import normalise_by_max
  from quantus.functions.perturb_func import baseline_replacement_by_indices
  from quantus.functions.similarity_func import correlation_pearson
  from quantus.helpers import asserts, plotting, warn
  from quantus.helpers.enums import DataType, EvaluationCategory, ModelType, ScoreDirection
  from quantus.helpers.model.model_interface import ModelInterface
  from quantus.helpers.perturbation_utils import make_perturb_func
  from quantus.metrics.base import Metric
label_desc: Use image node_id 5 for calling the SensitivityN obj's underlying member method code with example usage: obj.custom_postprocess(x_batch) without return types