class_docstr: Implementation of faithfulness correlation by Bhatt et al., 2020.
  
  The Faithfulness Correlation metric intend to capture an explanation's relative faithfulness
  (or 'fidelity') with respect to the model behaviour.
  
  Faithfulness correlation scores shows to what extent the predicted logits of each modified test point and
  the average explanation attribution for only the subset of features are (linearly) correlated, taking the
  average over multiple runs and test samples. The metric returns one float per input-attribution pair that
  ranges between -1 and 1, where higher scores are better.
  
  For each test sample, |S| features are randomly selected and replace them with baseline values (zero baseline
  or average of set). Thereafter, Pearson’s correlation coefficient between the predicted logits of each modified
  test point and the average explanation attribution for only the subset of features is calculated. Results is
  average over multiple runs and several test samples.
  
  References:
      1) Umang Bhatt et al.: "Evaluating and aggregating feature-based model
      explanations." IJCAI (2020): 3016-3022.
  
  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","faithfulness","correlation","by","Bhatt","et","al.",",","2020",".","The","Faithfulness","Correlation","metric","intend","to","capture","an","explanation","'s","relative","faithfulness","(","or","'fidelity","'",")","with","respect","to","the","model","behaviour",".","Faithfulness","correlation","scores","shows","to","what","extent","the","predicted","logits","of","each","modified","test","point","and","the","average","explanation","attribution","for","only","the","subset","of","features","are","(","linearly",")","correlated",",","taking","the","average","over","multiple","runs","and","test","samples",".","The","metric","returns","one","float","per","input-attribution","pair","that","ranges","between","-1","and","1",",","where","higher","scores","are","better",".","For","each","test","sample",",","|S|","features","are","randomly","selected","and","replace","them","with","baseline","values","(","zero","baseline","or","average","of","set",")",".","Thereafter",",","Pearson","\u2019","s","correlation","coefficient","between","the","predicted","logits","of","each","modified","test","point","and","the","average","explanation","attribution","for","only","the","subset","of","features","is","calculated",".","Results","is","average","over","multiple","runs","and","several","test","samples",".","References",":","1",")","Umang","Bhatt","et","al",".",":","``","Evaluating","and","aggregating","feature-based","model","explanations",".","''","IJCAI","(","2020",")",":","3016-3022",".","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: Parameters
  ----------
  similarity_func: callable
      Similarity function applied to compare input and perturbed input.
      If None, the default value is used, default=correlation_pearson.
  nr_runs: integer
      The number of runs (for each input and explanation pair), default=100.
  subset_size: integer
      The size of subset, default=224.
  abs: boolean
      Indicates whether absolute operation is applied on the attribution, default=False.
  normalise: boolean
      Indicates whether normalise operation is applied on the attribution, default=True.
  normalise_func: callable
      Attribution normalisation function applied in case normalise=True.
      If normalise_func=None, the default value is used, default=normalise_by_max.
  normalise_func_kwargs: dict
      Keyword arguments to be passed to normalise_func on call, default={}.
  perturb_func: callable
      Input perturbation function. If None, the default value is used,
      default=baseline_replacement_by_indices.
  perturb_baseline: string
      Indicates the type of baseline: "mean", "random", "uniform", "black" or "white",
      default="black".
  perturb_func_kwargs: dict
      Keyword arguments to be passed to perturb_func, default={}.
  return_aggregate: boolean
      Indicates if an aggregated score should be computed over all instances.
  aggregate_func: callable
      Callable that aggregates the scores given an evaluation call.
  default_plot_func: callable
      Callable that plots the metrics result.
  disable_warnings: boolean
      Indicates whether the warnings are printed, default=False.
  display_progressbar: boolean
      Indicates whether a tqdm-progress-bar is printed, default=False.
  kwargs: optional
      Keyword arguments.
docstr_tok: ["Parameters","--","--","--","--","--","similarity_func",":","callable","Similarity","function","applied","to","compare","input","and","perturbed","input",".","If","None",",","the","default","value","is","used",",","default=correlation_pearson",".","nr_runs",":","integer","The","number","of","runs","(","for","each","input","and","explanation","pair",")",",","default=100",".","subset_size",":","integer","The","size","of","subset",",","default=224",".","abs",":","boolean","Indicates","whether","absolute","operation","is","applied","on","the","attribution",",","default=False",".","normalise",":","boolean","Indicates","whether","normalise","operation","is","applied","on","the","attribution",",","default=True",".","normalise_func",":","callable","Attribution","normalisation","function","applied","in","case","normalise=True",".","If","normalise_func=None",",","the","default","value","is","used",",","default=normalise_by_max",".","normalise_func_kwargs",":","dict","Keyword","arguments","to","be","passed","to","normalise_func","on","call",",","default=","{","}",".","perturb_func",":","callable","Input","perturbation","function",".","If","None",",","the","default","value","is","used",",","default=baseline_replacement_by_indices",".","perturb_baseline",":","string","Indicates","the","type","of","baseline",":","``","mean","''",",","``","random","''",",","``","uniform","''",",","``","black","''","or","``","white","''",",","default=","''","black","''",".","perturb_func_kwargs",":","dict","Keyword","arguments","to","be","passed","to","perturb_func",",","default=","{","}",".","return_aggregate",":","boolean","Indicates","if","an","aggregated","score","should","be","computed","over","all","instances",".","aggregate_func",":","callable","Callable","that","aggregates","the","scores","given","an","evaluation","call",".","default_plot_func",":","callable","Callable","that","plots","the","metrics","result",".","disable_warnings",":","boolean","Indicates","whether","the","warnings","are","printed",",","default=False",".","display_progressbar",":","boolean","Indicates","whether","a","tqdm-progress-bar","is","printed",",","default=False",".","kwargs",":","optional","Keyword","arguments","."]
code: def __init__(
      self,
      similarity_func: Optional[Callable] = None,
      nr_runs: int = 100,
      subset_size: int = 224,
      abs: bool = False,
      normalise: bool = True,
      normalise_func: Optional[
          Callable[[np.ndarray], np.ndarray]
      ] = None,
      normalise_func_kwargs: Optional[Dict[str, Any]] = None,
      perturb_func: Optional[Callable] = None,
      perturb_baseline: str = "black",
      perturb_func_kwargs: Optional[Dict[str, Any]] = None,
      return_aggregate: bool = True,
      aggregate_func: Optional[Callable] = None,
      default_plot_func: Optional[Callable] = None,
      disable_warnings: bool = False,
      display_progressbar: bool = False,
      **kwargs,
  ):
      """
      Parameters
      ----------
      similarity_func: callable
          Similarity function applied to compare input and perturbed input.
          If None, the default value is used, default=correlation_pearson.
      nr_runs: integer
          The number of runs (for each input and explanation pair), default=100.
      subset_size: integer
          The size of subset, default=224.
      abs: boolean
          Indicates whether absolute operation is applied on the attribution, default=False.
      normalise: boolean
          Indicates whether normalise operation is applied on the attribution, default=True.
      normalise_func: callable
          Attribution normalisation function applied in case normalise=True.
          If normalise_func=None, the default value is used, default=normalise_by_max.
      normalise_func_kwargs: dict
          Keyword arguments to be passed to normalise_func on call, default={}.
      perturb_func: callable
          Input perturbation function. If None, the default value is used,
          default=baseline_replacement_by_indices.
      perturb_baseline: string
          Indicates the type of baseline: "mean", "random", "uniform", "black" or "white",
          default="black".
      perturb_func_kwargs: dict
          Keyword arguments to be passed to perturb_func, default={}.
      return_aggregate: boolean
          Indicates if an aggregated score should be computed over all instances.
      aggregate_func: callable
          Callable that aggregates the scores given an evaluation call.
      default_plot_func: callable
          Callable that plots the metrics result.
      disable_warnings: boolean
          Indicates whether the warnings are printed, default=False.
      display_progressbar: boolean
          Indicates whether a tqdm-progress-bar is printed, default=False.
      kwargs: optional
          Keyword arguments.
      """
      super().__init__(
          abs=abs,
          normalise=normalise,
          normalise_func=normalise_func,
          normalise_func_kwargs=normalise_func_kwargs,
          return_aggregate=return_aggregate,
          aggregate_func=aggregate_func,
          default_plot_func=default_plot_func,
          display_progressbar=display_progressbar,
          disable_warnings=disable_warnings,
          **kwargs,
      )
  
      # Save metric-specific attributes.
      if perturb_func is None:
          perturb_func = baseline_replacement_by_indices
  
      if similarity_func is None:
          similarity_func = correlation_pearson
  
      self.similarity_func = similarity_func
      self.nr_runs = nr_runs
      self.subset_size = subset_size
      self.perturb_func = make_perturb_func(
          perturb_func,
          perturb_func_kwargs,
          perturb_baseline=perturb_baseline,
      )
  
      # Asserts and warnings.
      if not self.disable_warnings:
          warn.warn_parameterisation(
              metric_name=self.__class__.__name__,
              sensitive_params=(
                  "baseline value 'perturb_baseline', size of subset |S| 'subset_size'"
                  " and the number of runs (for each input and explanation pair) "
                  "'nr_runs'"
              ),
              citation=(
                  "Bhatt, Umang, Adrian Weller, and José MF Moura. 'Evaluating and aggregating "
                  "feature-based model explanations.' arXiv preprint arXiv:2005.00631 (2020)"
              ),
          )
  
file_path: Quantus/quantus/metrics/faithfulness/faithfulness_correlation.py
imports: import sys
  from typing import Any, Callable, Dict, List, Optional
  import numpy
  from quantus.functions.perturb_func import baseline_replacement_by_indices
  from quantus.functions.similarity_func import correlation_pearson
  from quantus.helpers import asserts, 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 1 to create a new FaithfulnessCorrelation object from inherited base classes: Metric with example: obj = FaithfulnessCorrelation(similarity_func, nr_runs, subset_size, abs, normalise, normalise_func, normalise_func_kwargs, perturb_func, perturb_baseline, perturb_func_kwargs, return_aggregate, aggregate_func, default_plot_func, disable_warnings, display_progressbar)