class_docstr: Implementation of Avg-Sensitivity by Yeh at el., 2019.
  
  Using Monte Carlo sampling-based approximation while measuring how explanations
  change under slight perturbation - the average sensitivity is captured.
  
  References:
      1) Chih-Kuan Yeh et al. "On the (in) fidelity and sensitivity for explanations."
      NeurIPS (2019): 10965-10976.
      2) 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","Avg-Sensitivity","by","Yeh","at","el.",",","2019",".","Using","Monte","Carlo","sampling-based","approximation","while","measuring","how","explanations","change","under","slight","perturbation","-","the","average","sensitivity","is","captured",".","References",":","1",")","Chih-Kuan","Yeh","et","al",".","``","On","the","(","in",")","fidelity","and","sensitivity","for","explanations",".","''","NeurIPS","(","2019",")",":","10965-10976",".","2",")","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=difference.
  norm_numerator: callable
      Function for norm calculations on the numerator.
      If None, the default value is used, default=fro_norm
  norm_denominator: callable
      Function for norm calculations on the denominator.
      If None, the default value is used, default=fro_norm
  nr_samples: integer
      The number of samples iterated, default=200.
  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=gaussian_noise.
  perturb_std: float
      The amount of noise added, default=0.1.
  perturb_mean: float
      The mean of noise added, default=0.0.
  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.
  return_nan_when_prediction_changes: boolean
      When set to true, the metric will be evaluated to NaN if the prediction changes after the perturbation is applied.
  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=difference",".","norm_numerator",":","callable","Function","for","norm","calculations","on","the","numerator",".","If","None",",","the","default","value","is","used",",","default=fro_norm","norm_denominator",":","callable","Function","for","norm","calculations","on","the","denominator",".","If","None",",","the","default","value","is","used",",","default=fro_norm","nr_samples",":","integer","The","number","of","samples","iterated",",","default=200",".","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=gaussian_noise",".","perturb_std",":","float","The","amount","of","noise","added",",","default=0.1",".","perturb_mean",":","float","The","mean","of","noise","added",",","default=0.0",".","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",".","return_nan_when_prediction_changes",":","boolean","When","set","to","true",",","the","metric","will","be","evaluated","to","NaN","if","the","prediction","changes","after","the","perturbation","is","applied",".","kwargs",":","optional","Keyword","arguments","."]
code: def __init__(
      self,
      similarity_func: Optional[Callable] = None,
      norm_numerator: Optional[Callable] = None,
      norm_denominator: Optional[Callable] = None,
      nr_samples: int = 200,
      abs: bool = False,
      normalise: bool = False,
      normalise_func: Optional[
          Callable[[np.ndarray], np.ndarray]
      ] = None,
      normalise_func_kwargs: Optional[Dict[str, Any]] = None,
      perturb_func: Callable = uniform_noise,
      lower_bound: float = 0.2,
      upper_bound: Optional[float] = None,
      perturb_func_kwargs: Optional[Dict[str, Any]] = None,
      return_aggregate: bool = False,
      aggregate_func: Optional[Callable] = None,
      default_plot_func: Optional[Callable] = None,
      disable_warnings: bool = False,
      display_progressbar: bool = False,
      return_nan_when_prediction_changes: bool = False,
      **kwargs,
  ):
      """
      Parameters
      ----------
      similarity_func: callable
          Similarity function applied to compare input and perturbed input.
          If None, the default value is used, default=difference.
      norm_numerator: callable
          Function for norm calculations on the numerator.
          If None, the default value is used, default=fro_norm
      norm_denominator: callable
          Function for norm calculations on the denominator.
          If None, the default value is used, default=fro_norm
      nr_samples: integer
          The number of samples iterated, default=200.
      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=gaussian_noise.
      perturb_std: float
          The amount of noise added, default=0.1.
      perturb_mean: float
          The mean of noise added, default=0.0.
      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.
      return_nan_when_prediction_changes: boolean
          When set to true, the metric will be evaluated to NaN if the prediction changes after the perturbation is applied.
      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.
      self.nr_samples = nr_samples
  
      if similarity_func is None:
          similarity_func = difference
      self.similarity_func = similarity_func
  
      if norm_numerator is None:
          norm_numerator = norm_func.fro_norm
      self.norm_numerator = norm_numerator
  
      if norm_denominator is None:
          norm_denominator = norm_func.fro_norm
      self.norm_denominator = norm_denominator
      self.changed_prediction_indices = (
          make_changed_prediction_indices_func(
              return_nan_when_prediction_changes
          )
      )
      self.mean_func = (
          np.mean if return_nan_when_prediction_changes else np.nanmean
      )
      self.perturb_func = make_perturb_func(
          perturb_func,
          perturb_func_kwargs,
          lower_bound=lower_bound,
          upper_bound=upper_bound,
      )
  
      # Asserts and warnings.
      if not self.disable_warnings:
          warn.warn_parameterisation(
              metric_name=self.__class__.__name__,
              sensitive_params=(
                  "amount of noise added 'lower_bound' and 'upper_bound', the number of samples "
                  "iterated over 'nr_samples', the function to perturb the input "
                  "'perturb_func', the similarity metric 'similarity_func' as well as "
                  "norm calculations on the numerator and denominator of the sensitivity"
                  " equation i.e., 'norm_numerator' and 'norm_denominator'"
              ),
              citation=(
                  "Yeh, Chih-Kuan, et al. 'On the (in) fidelity and sensitivity for explanations"
                  ".' arXiv preprint arXiv:1901.09392 (2019)"
              ),
          )
          warn.warn_noise_zero(noise=lower_bound)
  
file_path: Quantus/quantus/metrics/robustness/avg_sensitivity.py
imports: import sys
  from typing import Any, Callable, Dict, List, Optional
  import numpy
  from quantus.functions import norm_func
  from quantus.functions.perturb_func import perturb_batch, uniform_noise
  from quantus.functions.similarity_func import difference
  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_changed_prediction_indices_func, make_perturb_func
  from quantus.metrics.base import Metric
label_desc: Use image node_id 1 to create a new AvgSensitivity object from inherited base classes: Metric with example: obj = AvgSensitivity(similarity_func, norm_numerator, norm_denominator, nr_samples, abs, normalise, normalise_func, normalise_func_kwargs, perturb_func, lower_bound, upper_bound, perturb_func_kwargs, return_aggregate, aggregate_func, default_plot_func, disable_warnings, display_progressbar, return_nan_when_prediction_changes)