class_docstr: Implementation of the Model Parameter Randomisation Test (MPRT) by Adebayo et al., 2018.
  
  The MPRT measures the distance between the original attribution and a newly computed
  attribution throughout the process of cascadingly/ independently randomizing the model
  parameters of one layer at a time.
  
  Assumptions:
      - In the original paper multiple distance measures are taken: Spearman rank correlation (with and without abs),
      HOG and SSIM. We have set Spearman as the default value.
  
  References:
      1) Julius Adebayo et al.: "Sanity Checks for Saliency Maps." NeurIPS (2018): 9525-9536.
  
  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, default=correlation_spearman.
  layer_order: string
      Indicated whether the model is randomized cascadingly or independently.
      Set order=top_down for cascading randomization, set order=independent for independent randomization,
      default="independent".
  seed: integer
      Seed used for the random generator, default=42.
  return_average_correlation: boolean
      Indicates whether to return one float per sample, computing the average
      correlation coefficient across the layers for a given sample.
  return_last_correlation: boolean
      Indicates whether to return one float per sample, computing the explanation
      correlation coefficient for the full model randomisation (not layer-wise) of a sample.
  skip_layers: boolean
      Indicates if explanation similarity should be computed only once; between the
      original and fully randomised model, instead of in a layer-by-layer basis.
  abs: boolean
      Indicates whether absolute operation is applied on the attribution, default=True.
  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={}.
  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",",","default=correlation_spearman",".","layer_order",":","string","Indicated","whether","the","model","is","randomized","cascadingly","or","independently",".","Set","order=top_down","for","cascading","randomization",",","set","order=independent","for","independent","randomization",",","default=","''","independent","''",".","seed",":","integer","Seed","used","for","the","random","generator",",","default=42",".","return_average_correlation",":","boolean","Indicates","whether","to","return","one","float","per","sample",",","computing","the","average","correlation","coefficient","across","the","layers","for","a","given","sample",".","return_last_correlation",":","boolean","Indicates","whether","to","return","one","float","per","sample",",","computing","the","explanation","correlation","coefficient","for","the","full","model","randomisation","(","not","layer-wise",")","of","a","sample",".","skip_layers",":","boolean","Indicates","if","explanation","similarity","should","be","computed","only","once",";","between","the","original","and","fully","randomised","model",",","instead","of","in","a","layer-by-layer","basis",".","abs",":","boolean","Indicates","whether","absolute","operation","is","applied","on","the","attribution",",","default=True",".","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=","{","}",".","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,
      layer_order: str = "top_down",
      seed: int = 42,
      return_sample_correlation: Optional[bool] = None,
      return_average_correlation: bool = False,
      return_last_correlation: bool = False,
      skip_layers: bool = False,
      abs: bool = True,
      normalise: bool = True,
      normalise_func: Optional[
          Callable[[np.ndarray], np.ndarray]
      ] = None,
      normalise_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,
      **kwargs,
  ):
      """
      Parameters
      ----------
      similarity_func: callable
          Similarity function applied to compare input and perturbed input, default=correlation_spearman.
      layer_order: string
          Indicated whether the model is randomized cascadingly or independently.
          Set order=top_down for cascading randomization, set order=independent for independent randomization,
          default="independent".
      seed: integer
          Seed used for the random generator, default=42.
      return_average_correlation: boolean
          Indicates whether to return one float per sample, computing the average
          correlation coefficient across the layers for a given sample.
      return_last_correlation: boolean
          Indicates whether to return one float per sample, computing the explanation
          correlation coefficient for the full model randomisation (not layer-wise) of a sample.
      skip_layers: boolean
          Indicates if explanation similarity should be computed only once; between the
          original and fully randomised model, instead of in a layer-by-layer basis.
      abs: boolean
          Indicates whether absolute operation is applied on the attribution, default=True.
      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={}.
      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,
      )
  
      if return_sample_correlation is not None:
          print(
              "'return_sample_correlation' parameter is deprecated and will be removed in future versions. "
              f"Please use 'return_average_correlation' instead. "
              f"Setting 'return_average_correlation' to {return_sample_correlation}.",
          )
          # Use the value of 'return_average_correlation' for 'return_sample_correlation'
          return_average_correlation = return_sample_correlation
  
      # Save metric-specific attributes.
      if similarity_func is None:
          similarity_func = correlation_spearman
      self.similarity_func = similarity_func
      self.layer_order = layer_order
      self.seed = seed
      self.return_average_correlation = return_average_correlation
      self.return_last_correlation = return_last_correlation
      self.skip_layers = skip_layers
  
      # Results are returned/saved as a dictionary not like in the super-class as a list.
      self.evaluation_scores = {}
  
      # Asserts and warnings.
      if (
          self.return_average_correlation
          and self.return_last_correlation
      ):
          raise ValueError(
              f"Both 'return_average_correlation' and 'return_last_correlation' cannot be set to 'True'. "
              f"Set both to 'False' or one of the attributes to 'True'."
          )
      if self.return_average_correlation and self.skip_layers:
          raise ValueError(
              f"Both 'return_average_correlation' and 'skip_layers' cannot be set to 'True'. "
              f"You need to calculate the explanation correlation at all layers in order "
              f"to compute the average correlation coefficient on all layers."
          )
      asserts.assert_layer_order(layer_order=self.layer_order)
      if not self.disable_warnings:
          warn.warn_parameterisation(
              metric_name=self.__class__.__name__,
              sensitive_params=(
                  "similarity metric 'similarity_func' and the order of "
                  "the layer randomisation 'layer_order'"
              ),
              citation=(
                  "Adebayo, J., Gilmer, J., Muelly, M., Goodfellow, I., Hardt, M., and Kim, B. "
                  "'Sanity Checks for Saliency Maps.' arXiv preprint,"
                  " arXiv:1810.073292v3 (2018)"
              ),
          )
  
imports: import sys
  import warnings
  from typing import Any, Callable, Collection, Dict, List, Optional, Union, Tuple, Generator, Iterable
  import numpy
  from tqdm.auto import tqdm
  from sklearn.utils import gen_batches
  from quantus.functions.similarity_func import correlation_spearman
  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.metrics.base import Metric
label_desc: Use image node_id 1 to create a new MPRT object from inherited base classes: Metric with example: obj = MPRT(similarity_func, layer_order, seed, return_sample_correlation, return_average_correlation, return_last_correlation, skip_layers, abs, normalise, normalise_func, normalise_func_kwargs, return_aggregate, aggregate_func, default_plot_func, disable_warnings, display_progressbar)