class_docstr: Implementation of Completeness test by Kindermans et al., 2017.
  
  To test for input invariance, we add a constant shift to the input data and a mean shift to the model bias,
  so that the output of the original model on the original data is equal to the output of the changed model
  on the shifted data. The metric returns True if batch attributions stayed unchanged too. Currently only
  supporting constant values for the shift.
  
  References:
      Pieter-Jan Kindermans et al.: "The (Un)reliability of Saliency Methods." Explainable AI (2019): 267-280
  
  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.
class_docstr_tok: ["Implementation","of","Completeness","test","by","Kindermans","et","al.",",","2017",".","To","test","for","input","invariance",",","we","add","a","constant","shift","to","the","input","data","and","a","mean","shift","to","the","model","bias",",","so","that","the","output","of","the","original","model","on","the","original","data","is","equal","to","the","output","of","the","changed","model","on","the","shifted","data",".","The","metric","returns","True","if","batch","attributions","stayed","unchanged","too",".","Currently","only","supporting","constant","values","for","the","shift",".","References",":","Pieter-Jan","Kindermans","et","al",".",":","``","The","(","Un",")","reliability","of","Saliency","Methods",".","''","Explainable","AI","(","2019",")",":","267-280","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","."]
docstr: Evaluates model and attributes on a single data batch and returns the batched evaluation result.
  
  Parameters
  ----------
  model: ModelInterface
      A ModelInteface that is subject to explanation.
  x_batch: np.ndarray
      The input to be evaluated on a batch-basis.
  y_batch: np.ndarray
      The output to be evaluated on a batch-basis.
  a_batch: np.ndarray
      The explanation to be evaluated on a batch-basis.
  
  Returns
  -------
  scores_batch: np.ndarray
      The evaluation results.
docstr_tok: ["Evaluates","model","and","attributes","on","a","single","data","batch","and","returns","the","batched","evaluation","result",".","Parameters","--","--","--","--","--","model",":","ModelInterface","A","ModelInteface","that","is","subject","to","explanation",".","x_batch",":","np.ndarray","The","input","to","be","evaluated","on","a","batch-basis",".","y_batch",":","np.ndarray","The","output","to","be","evaluated","on","a","batch-basis",".","a_batch",":","np.ndarray","The","explanation","to","be","evaluated","on","a","batch-basis",".","Returns","--","--","--","-","scores_batch",":","np.ndarray","The","evaluation","results","."]
code: def evaluate_batch(
      self,
      model: ModelInterface,
      x_batch: np.ndarray,
      y_batch: np.ndarray,
      a_batch: np.ndarray,
      **kwargs,
  ) -> np.ndarray:
      """
      Evaluates model and attributes on a single data batch and returns the batched evaluation result.
  
      Parameters
      ----------
      model: ModelInterface
          A ModelInteface that is subject to explanation.
      x_batch: np.ndarray
          The input to be evaluated on a batch-basis.
      y_batch: np.ndarray
          The output to be evaluated on a batch-basis.
      a_batch: np.ndarray
          The explanation to be evaluated on a batch-basis.
  
      Returns
      -------
      scores_batch: np.ndarray
          The evaluation results.
      """
      batch_size = x_batch.shape[0]
  
      # Perturb the batched input.
      x_shifted = perturb_batch(
          perturb_func=self.perturb_func,
          indices=np.tile(
              np.arange(0, x_batch[0].size), (batch_size, 1)
          ),
          indexed_axes=np.arange(0, x_batch[0].ndim),
          arr=x_batch,
      )
  
      # Get input shift.
      input_shift = self.perturb_func.keywords["input_shift"]  # type: ignore
      x_shifted = model.shape_input(
          x=x_shifted,
          shape=x_shifted.shape,
          channel_first=True,
          batched=True,
      )
  
      # Shift the model.
      shifted_model = model.add_mean_shift_to_first_layer(
          input_shift, x_shifted[:1].shape
      )
  
      # Generate explanation based on shifted input x.
      a_shifted = self.explain_batch(shifted_model, x_shifted, y_batch)
  
      # Compute the invaraince.
      score = np.all(
          np.isclose(a_batch, a_shifted, atol=1e-04),
          axis=tuple(range(1, a_batch.ndim)),
      )
  
      return score
  
file_path: Quantus/quantus/metrics/axiomatic/input_invariance.py
imports: import sys
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  from quantus.functions.perturb_func import baseline_replacement_by_shift, perturb_batch
  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 InputInvariance obj's underlying member method code with example usage: obj.evaluate_batch(model, x_batch, y_batch, a_batch) and returns: score