class_docstr: Implementation of the Local Lipschitz Estimate (or Stability) test by Alvarez-Melis et al., 2018a, 2018b.
  
  This tests asks how consistent are the explanations for similar/neighboring examples.
  The test denotes a (weaker) empirical notion of stability based on discrete,
  finite-sample neighborhoods i.e., argmax_(||f(x) - f(x')||_2 / ||x - x'||_2)
  where f(x) is the explanation for input x and x' is the perturbed input.
  
  References:
      1) David Alvarez-Melis and Tommi S. Jaakkola. "On the robustness of interpretability methods."
      arXiv preprint arXiv:1806.08049 (2018).
  
      2) 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: Parameters
  ----------
  similarity_func: callable
      Similarity function applied to compare input and perturbed input.
      If None, the default value is used, default=lipschitz_constant.
  norm_numerator: callable
      Function for norm calculations on the numerator.
      If None, the default value is used, default=distance_euclidean.
  norm_denominator: callable
      Function for norm calculations on the denominator.
      If None, the default value is used, default=distance_euclidean.
  nr_samples: integer
      The number of samples iterated, default=200.
  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=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=lipschitz_constant",".","norm_numerator",":","callable","Function","for","norm","calculations","on","the","numerator",".","If","None",",","the","default","value","is","used",",","default=distance_euclidean",".","norm_denominator",":","callable","Function","for","norm","calculations","on","the","denominator",".","If","None",",","the","default","value","is","used",",","default=distance_euclidean",".","nr_samples",":","integer","The","number","of","samples","iterated",",","default=200",".","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=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 = True,
      normalise_func: Optional[
          Callable[[np.ndarray], np.ndarray]
      ] = None,
      normalise_func_kwargs: Optional[Dict[str, Any]] = None,
      perturb_func: Optional[Callable] = None,
      perturb_mean: float = 0.0,
      perturb_std: float = 0.1,
      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=lipschitz_constant.
      norm_numerator: callable
          Function for norm calculations on the numerator.
          If None, the default value is used, default=distance_euclidean.
      norm_denominator: callable
          Function for norm calculations on the denominator.
          If None, the default value is used, default=distance_euclidean.
      nr_samples: integer
          The number of samples iterated, default=200.
      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=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,
      )
  
      if perturb_func is None:
          perturb_func = gaussian_noise
  
      # Save metric-specific attributes.
      self.nr_samples = nr_samples
  
      if similarity_func is None:
          similarity_func = lipschitz_constant
      self.similarity_func = similarity_func
  
      if norm_numerator is None:
          norm_numerator = distance_euclidean
      self.norm_numerator = norm_numerator
  
      if norm_denominator is None:
          norm_denominator = distance_euclidean
      self.norm_denominator = norm_denominator
      self.perturb_func = make_perturb_func(
          perturb_func,
          perturb_func_kwargs,
          perturb_mean=perturb_mean,
          perturb_std=perturb_std,
      )
      self.changed_prediction_indices_func = (
          make_changed_prediction_indices_func(
              return_nan_when_prediction_changes
          )
      )
      self.max_func = (
          np.max if return_nan_when_prediction_changes else np.nanmax
      )
  
      # Asserts and warnings.
      if not self.disable_warnings:
          warn.warn_parameterisation(
              metric_name=self.__class__.__name__,
              sensitive_params=(
                  "amount of noise added 'perturb_std', 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 lipschitz "
                  "equation i.e., 'norm_numerator' and 'norm_denominator'"
              ),
              citation=(
                  "Alvarez-Melis, David, and Tommi S. Jaakkola. 'On the robustness of "
                  "interpretability methods.' arXiv preprint arXiv:1806.08049 (2018). and "
                  "Alvarez-Melis, David, and Tommi S. Jaakkola. 'Towards robust interpretability"
                  " with self-explaining neural networks.' arXiv preprint "
                  "arXiv:1806.07538 (2018)"
              ),
          )
          warn.warn_noise_zero(noise=perturb_std)
  
file_path: Quantus/quantus/metrics/robustness/local_lipschitz_estimate.py
imports: import sys
  from typing import Any, Callable, Dict, List, Optional
  import numpy
  from quantus.functions.perturb_func import gaussian_noise, perturb_batch
  from quantus.functions.similarity_func import distance_euclidean, lipschitz_constant
  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 LocalLipschitzEstimate object from inherited base classes: Metric with example: obj = LocalLipschitzEstimate(similarity_func, norm_numerator, norm_denominator, nr_samples, abs, normalise, normalise_func, normalise_func_kwargs, perturb_func, perturb_mean, perturb_std, perturb_func_kwargs, return_aggregate, aggregate_func, default_plot_func, disable_warnings, display_progressbar, return_nan_when_prediction_changes)