class_docstr: Relative Representation Stability leverages the stability of an explanation with respect
  to the change in the output logits.
  
      `RRS(x, x', ex, ex') = max \frac{||\frac{e_x - e_{x'}}{e_x}||_p}
      {max (||\frac{L_x - L_{x'}}{L_x}||_p, \epsilon_{min})},`
  
  where `L(·)` denotes the internal model representation, e.g., output embeddings of hidden layers.
  
  References:
      1) Chirag Agarwal, et. al., 2022. "Rethinking stability for attribution based explanations.",
      https://arxiv.org/pdf/2203.06877.pdf
  
  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: ["Relative","Representation","Stability","leverages","the","stability","of","an","explanation","with","respect","to","the","change","in","the","output","logits",".","`","RRS","(","x",",","x","'",",","ex",",","ex","'",")","=","max","\\frac","{","||\\frac","{","e_x","-","e_","{","x","'","}","}","{","e_x","}","||_p","}","{","max","(","||\\frac","{","L_x","-","L_","{","x","'","}","}","{","L_x","}","||_p",",","\\epsilon_","{","min","}",")","}",",","`","where","`","L","(","\u00b7",")","`","denotes","the","internal","model","representation",",","e.g.",",","output","embeddings","of","hidden","layers",".","References",":","1",")","Chirag","Agarwal",",","et",".","al.",",","2022",".","``","Rethinking","stability","for","attribution","based","explanations",".","``",",","https",":","\/\/arxiv.org\/pdf\/2203.06877.pdf","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: For each image `x`:
   - Generate `num_perturbations` perturbed `xs` in the neighborhood of `x`.
   - Compute explanations `e_x` and `e_xs`.
   - Compute relative representation stability objective, find max value with respect to `xs`.
   - In practise we just use `max` over a finite `xs_batch`.
  
  Parameters
  ----------
  model: tf.keras.Model, torch.nn.Module
      A torch or tensorflow model that is subject to explanation.
  x_batch: np.ndarray
      4D tensor representing batch of input images
  y_batch: np.ndarray
      1D tensor, representing predicted labels for the x_batch.
  model_predict_kwargs: dict, optional
      Keyword arguments to be passed to the model's predict method.
  explain_func: callable, optional
      Function used to generate explanations.
  explain_func_kwargs: dict, optional
      Keyword arguments to be passed to explain_func on call.
  a_batch: np.ndarray, optional
      4D tensor with pre-computed explanations for the x_batch.
  device: str, optional
      Device on which torch should perform computations.
  softmax: boolean, optional
      Indicates whether to use softmax probabilities or logits in model prediction.
      This is used for this __call__ only and won't be saved as attribute. If None, self.softmax is used.
  channel_first: boolean, optional
      Indicates of the image dimensions are channel first, or channel last.
      Inferred from the input shape if None.
  batch_size: int
      The batch size to be used.
  kwargs:
      not used, deprecated
  Returns
  -------
  relative representation stability: float, np.ndarray
      float in case `return_aggregate=True`, otherwise np.ndarray of floats
docstr_tok: ["For","each","image","`","x","`",":","-","Generate","`","num_perturbations","`","perturbed","`","xs","`","in","the","neighborhood","of","`","x","`",".","-","Compute","explanations","`","e_x","`","and","`","e_xs","`",".","-","Compute","relative","representation","stability","objective",",","find","max","value","with","respect","to","`","xs","`",".","-","In","practise","we","just","use","`","max","`","over","a","finite","`","xs_batch","`",".","Parameters","--","--","--","--","--","model",":","tf.keras.Model",",","torch.nn.Module","A","torch","or","tensorflow","model","that","is","subject","to","explanation",".","x_batch",":","np.ndarray","4D","tensor","representing","batch","of","input","images","y_batch",":","np.ndarray","1D","tensor",",","representing","predicted","labels","for","the","x_batch",".","model_predict_kwargs",":","dict",",","optional","Keyword","arguments","to","be","passed","to","the","model","'s","predict","method",".","explain_func",":","callable",",","optional","Function","used","to","generate","explanations",".","explain_func_kwargs",":","dict",",","optional","Keyword","arguments","to","be","passed","to","explain_func","on","call",".","a_batch",":","np.ndarray",",","optional","4D","tensor","with","pre-computed","explanations","for","the","x_batch",".","device",":","str",",","optional","Device","on","which","torch","should","perform","computations",".","softmax",":","boolean",",","optional","Indicates","whether","to","use","softmax","probabilities","or","logits","in","model","prediction",".","This","is","used","for","this","__call__","only","and","wo","n't","be","saved","as","attribute",".","If","None",",","self.softmax","is","used",".","channel_first",":","boolean",",","optional","Indicates","of","the","image","dimensions","are","channel","first",",","or","channel","last",".","Inferred","from","the","input","shape","if","None",".","batch_size",":","int","The","batch","size","to","be","used",".","kwargs",":","not","used",",","deprecated","Returns","--","--","--","-","relative","representation","stability",":","float",",","np.ndarray","float","in","case","`","return_aggregate=True","`",",","otherwise","np.ndarray","of","floats"]
code: def __call__(  # type: ignore
      self,
      model: tf.keras.Model | torch.nn.Module,
      x_batch: np.ndarray,
      y_batch: np.ndarray,
      model_predict_kwargs: Optional[Dict[str, ...]] = None,
      explain_func: Optional[Callable] = None,
      explain_func_kwargs: Optional[Dict[str, ...]] = None,
      a_batch: Optional[np.ndarray] = None,
      device: Optional[str] = None,
      softmax: bool = False,
      channel_first: bool = True,
      batch_size: int = 64,
      **kwargs,
  ) -> List[float]:
      """
      For each image `x`:
       - Generate `num_perturbations` perturbed `xs` in the neighborhood of `x`.
       - Compute explanations `e_x` and `e_xs`.
       - Compute relative representation stability objective, find max value with respect to `xs`.
       - In practise we just use `max` over a finite `xs_batch`.
  
      Parameters
      ----------
      model: tf.keras.Model, torch.nn.Module
          A torch or tensorflow model that is subject to explanation.
      x_batch: np.ndarray
          4D tensor representing batch of input images
      y_batch: np.ndarray
          1D tensor, representing predicted labels for the x_batch.
      model_predict_kwargs: dict, optional
          Keyword arguments to be passed to the model's predict method.
      explain_func: callable, optional
          Function used to generate explanations.
      explain_func_kwargs: dict, optional
          Keyword arguments to be passed to explain_func on call.
      a_batch: np.ndarray, optional
          4D tensor with pre-computed explanations for the x_batch.
      device: str, optional
          Device on which torch should perform computations.
      softmax: boolean, optional
          Indicates whether to use softmax probabilities or logits in model prediction.
          This is used for this __call__ only and won't be saved as attribute. If None, self.softmax is used.
      channel_first: boolean, optional
          Indicates of the image dimensions are channel first, or channel last.
          Inferred from the input shape if None.
      batch_size: int
          The batch size to be used.
      kwargs:
          not used, deprecated
      Returns
      -------
      relative representation stability: float, np.ndarray
          float in case `return_aggregate=True`, otherwise np.ndarray of floats
      """
      return super().__call__(
          model=model,
          x_batch=x_batch,
          y_batch=y_batch,
          explain_func=explain_func,
          explain_func_kwargs=explain_func_kwargs,
          a_batch=a_batch,
          device=device,
          softmax=softmax,
          channel_first=channel_first,
          model_predict_kwargs=model_predict_kwargs,
          s_batch=None,
          batch_size=batch_size,
      )
  
file_path: Quantus/quantus/metrics/robustness/relative_representation_stability.py
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Callable, Dict, List, Optional
  import numpy
  import sys
  from quantus.functions.normalise_func import normalise_by_average_second_moment_estimate
  from quantus.functions.perturb_func import perturb_batch, uniform_noise
  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.helpers.warn import warn_parameterisation
  from quantus.metrics.base import Metric
label_desc: Use image node_id 2 for calling the RelativeRepresentationStability obj's underlying member method code with example usage: obj.__call__(model, x_batch, y_batch, model_predict_kwargs, explain_func, explain_func_kwargs, a_batch, device, softmax, channel_first, batch_size) and returns: super