class_docstr: Implementation of the Efficient MPRT by Hedström et al., 2023.
  
  The Efficient MPRT measures replaces the layer-by-layer pairwise comparison
  between e and ˆe of MPRT by instead computing the relative rise in explanation complexity using only
  two model states, i.e., the original- and fully randomised model version
  
  References:
      1) Hedström, Anna, et al. "Sanity Checks Revisited: An Exploration to Repair the Model Parameter
      Randomisation Test." XAI in Action: Past, Present, and Future Applications. 2023.
  
  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","the","Efficient","MPRT","by","Hedstr\u00f6m","et","al.",",","2023",".","The","Efficient","MPRT","measures","replaces","the","layer-by-layer","pairwise","comparison","between","e","and","\u02c6e","of","MPRT","by","instead","computing","the","relative","rise","in","explanation","complexity","using","only","two","model","states",",","i.e.",",","the","original-","and","fully","randomised","model","version","References",":","1",")","Hedstr\u00f6m",",","Anna",",","et","al",".","``","Sanity","Checks","Revisited",":","An","Exploration","to","Repair","the","Model","Parameter","Randomisation","Test",".","''","XAI","in","Action",":","Past",",","Present",",","and","Future","Applications",".","2023",".","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
  ----------
  complexity_func: callable
      A callable that computes the complexity of an explanation.
  complexity_func_kwargs: dict, optional
      Keyword arguments to be passed to complexity_func on call.
  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.
  compute_extra_scores: boolean
      Indicates if exta scores should be computed (and stored in a metric attrbute
      (dict) called scores_extra.
  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","--","--","--","--","--","complexity_func",":","callable","A","callable","that","computes","the","complexity","of","an","explanation",".","complexity_func_kwargs",":","dict",",","optional","Keyword","arguments","to","be","passed","to","complexity_func","on","call",".","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",".","compute_extra_scores",":","boolean","Indicates","if","exta","scores","should","be","computed","(","and","stored","in","a","metric","attrbute","(","dict",")","called","scores_extra",".","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,
      complexity_func: Optional[Callable] = None,
      complexity_func_kwargs: Optional[dict] = None,
      similarity_func: Optional[Callable] = None,
      layer_order: str = "bottom_up",
      seed: int = 42,
      compute_extra_scores: bool = False,
      skip_layers: bool = True,
      abs: bool = False,
      normalise: bool = False,
      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
      ----------
      complexity_func: callable
          A callable that computes the complexity of an explanation.
      complexity_func_kwargs: dict, optional
          Keyword arguments to be passed to complexity_func on call.
      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.
      compute_extra_scores: boolean
          Indicates if exta scores should be computed (and stored in a metric attrbute
          (dict) called scores_extra.
      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,
      )
  
      # Save metric-specific attributes.
      if complexity_func is None:
          complexity_func = discrete_entropy
  
      if complexity_func_kwargs is None:
          complexity_func_kwargs = {}
  
      if normalise_func is None:
          normalise_func = normalise_by_average_second_moment_estimate
  
      if normalise_func_kwargs is None:
          normalise_func_kwargs = {}
  
      if similarity_func is None:
          similarity_func = correlation_spearman
  
      self.complexity_func = complexity_func
      self.complexity_func_kwargs = complexity_func_kwargs
      self.normalise_func = normalise_func
      self.abs = abs
      self.normalise_func_kwargs = normalise_func_kwargs
      self.similarity_func = similarity_func
      self.layer_order = layer_order
      self.seed = seed
      self.compute_extra_scores = compute_extra_scores
      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.assert_layer_order(layer_order=self.layer_order)
      if not self.disable_warnings:
          warn.warn_parameterisation(
              metric_name=self.__class__.__name__,
              sensitive_params=(
                  "the order of the layer randomisation 'layer_order' (we recommend "
                  "bottom-up randomisation and advice against top-down randomisation) "
              ),
              citation=(
                  'Hedström, Anna, et al. "Sanity Checks Revisited: An Exploration to Repair'
                  ' the Model Parameter Randomisation Test." XAI in Action: Past, Present, '
                  "and Future Applications. 2023."
              ),
          )
  
imports: import sys
  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.functions.complexity_func import discrete_entropy, entropy
  from quantus.functions.normalise_func import normalise_by_average_second_moment_estimate
  from quantus.functions import n_bins_func
  from quantus.helpers import asserts, warn, utils
  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 EfficientMPRT object from inherited base classes: Metric with example: obj = EfficientMPRT(complexity_func, complexity_func_kwargs, similarity_func, layer_order, seed, compute_extra_scores, skip_layers, abs, normalise, normalise_func, normalise_func_kwargs, return_aggregate, aggregate_func, default_plot_func, disable_warnings, display_progressbar)