class_docstr: Implementation of Faithfulness Estimate by Alvares-Melis at el., 2018a and 2018b.
  
  Computes the correlations of probability drops and the relevance scores on various points,
  showing the aggregate statistics.
  
  References:
      1) David Alvarez-Melis and Tommi S. Jaakkola.: "Towards robust interpretability with self-explaining
      neural networks." NeurIPS (2018): 7786-7795.
  
  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","Estimate","by","Alvares-Melis","at","el.",",","2018a","and","2018b",".","Computes","the","correlations","of","probability","drops","and","the","relevance","scores","on","various","points",",","showing","the","aggregate","statistics",".","References",":","1",")","David","Alvarez-Melis","and","Tommi","S",".","Jaakkola",".",":","``","Towards","robust","interpretability","with","self-explaining","neural","networks",".","''","NeurIPS","(","2018",")",":","7786-7795",".","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: Evaluate instance gets model and data for a single instance as input and returns the evaluation result.
  
  Parameters
  ----------
  model: ModelInterface
      A ModelInteface that is subject to explanation.
  x: np.ndarray
      The input to be evaluated on an instance-basis.
  y: np.ndarray
      The output to be evaluated on an instance-basis.
  a: np.ndarray
      The explanation to be evaluated on an instance-basis.
  
  Returns
  -------
  float
      The evaluation results.
docstr_tok: ["Evaluate","instance","gets","model","and","data","for","a","single","instance","as","input","and","returns","the","evaluation","result",".","Parameters","--","--","--","--","--","model",":","ModelInterface","A","ModelInteface","that","is","subject","to","explanation",".","x",":","np.ndarray","The","input","to","be","evaluated","on","an","instance-basis",".","y",":","np.ndarray","The","output","to","be","evaluated","on","an","instance-basis",".","a",":","np.ndarray","The","explanation","to","be","evaluated","on","an","instance-basis",".","Returns","--","--","--","-","float","The","evaluation","results","."]
code: def evaluate_instance(
      self,
      model: ModelInterface,
      x: np.ndarray,
      y: np.ndarray,
      a: np.ndarray,
  ) -> float:
      """
      Evaluate instance gets model and data for a single instance as input and returns the evaluation result.
  
      Parameters
      ----------
      model: ModelInterface
          A ModelInteface that is subject to explanation.
      x: np.ndarray
          The input to be evaluated on an instance-basis.
      y: np.ndarray
          The output to be evaluated on an instance-basis.
      a: np.ndarray
          The explanation to be evaluated on an instance-basis.
  
      Returns
      -------
      float
          The evaluation results.
      """
  
      # Flatten the attributions.
      a = a.flatten()
  
      # Get indices of sorted attributions (descending).
      a_indices = np.argsort(-a)
  
      # Predict on input.
      x_input = model.shape_input(x, x.shape, channel_first=True)
      y_pred = float(model.predict(x_input)[:, y])
  
      n_perturbations = len(
          range(0, len(a_indices), self.features_in_step)
      )
      pred_deltas = [None for _ in range(n_perturbations)]
      att_sums = [None for _ in range(n_perturbations)]
  
      for i_ix, a_ix in enumerate(a_indices[:: self.features_in_step]):
          # Perturb input by indices of attributions.
          a_ix = a_indices[
              (self.features_in_step * i_ix) : (
                  self.features_in_step * (i_ix + 1)
              )
          ]
          x_perturbed = self.perturb_func(
              arr=x,
              indices=a_ix,
              indexed_axes=self.a_axes,
          )
          warn.warn_perturbation_caused_no_change(
              x=x, x_perturbed=x_perturbed
          )
  
          # Predict on perturbed input x.
          x_input = model.shape_input(
              x_perturbed, x.shape, channel_first=True
          )
          y_pred_perturb = float(model.predict(x_input)[:, y])
          pred_deltas[i_ix] = float(y_pred - y_pred_perturb)
  
          # Sum attributions.
          att_sums[i_ix] = np.sum(a[a_ix])
  
      similarity = self.similarity_func(a=att_sums, b=pred_deltas)
      return similarity
  
file_path: Quantus/quantus/metrics/faithfulness/faithfulness_estimate.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 3 for calling the FaithfulnessEstimate obj's underlying member method code with example usage: obj.evaluate_instance(model, x, y, a) and returns: similarity