class_docstr: Relative Output Stability leverages the stability of an explanation with respect to the change in the output logits.
  
      `ROS(x, x', ex, ex') = max \frac{||\frac{e_x - e_x'}{e_x}||_p}
      {max (||h(x) - h(x')||_p, \epsilon_{min})}`,
  
  where `h(x)` and `h(x')` are the output logits for `x` and `x'` respectively.
  
  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","Output","Stability","leverages","the","stability","of","an","explanation","with","respect","to","the","change","in","the","output","logits",".","`","ROS","(","x",",","x","'",",","ex",",","ex","'",")","=","max","\\frac","{","||\\frac","{","e_x","-","e_x","'","}","{","e_x","}","||_p","}","{","max","(","||h","(","x",")","-","h","(","x","'",")","||_p",",","\\epsilon_","{","min","}",")","}","`",",","where","`","h","(","x",")","`","and","`","h","(","x","'",")","`","are","the","output","logits","for","`","x","`","and","`","x","'","`","respectively",".","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: 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.
  a_batch: np.ndarray, optional
      4D tensor with pre-computed explanations for the x_batch.
  kwargs:
      Unused.
  
  Returns
  -------
  ros: np.ndarray
      A batch of explanations.
docstr_tok: ["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",".","a_batch",":","np.ndarray",",","optional","4D","tensor","with","pre-computed","explanations","for","the","x_batch",".","kwargs",":","Unused",".","Returns","--","--","--","-","ros",":","np.ndarray","A","batch","of","explanations","."]
code: def evaluate_batch(
      self,
      model: ModelInterface,
      x_batch: np.ndarray,
      y_batch: np.ndarray,
      a_batch: np.ndarray,
      **kwargs,
  ) -> np.ndarray:
      """
      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.
      a_batch: np.ndarray, optional
          4D tensor with pre-computed explanations for the x_batch.
      kwargs:
          Unused.
  
      Returns
      -------
      ros: np.ndarray
          A batch of explanations.
  
      """
      batch_size = x_batch.shape[0]
      # Execute forward pass on provided inputs.
      logits = model.predict(x_batch)
  
      # Prepare output array.
      ros_batch = np.zeros(shape=[self._nr_samples, x_batch.shape[0]])
  
      for index in range(self._nr_samples):
          # Perturb input.
          x_perturbed = perturb_batch(
              perturb_func=self.perturb_func,
              indices=np.tile(
                  np.arange(0, x_batch[0].size), (batch_size, 1)
              ),
              indexed_axes=np.arange(0, x_batch[0].ndim),
              arr=x_batch,
          )
  
          # Generate explanations for perturbed input.
          a_batch_perturbed = self.explain_batch(
              model, x_perturbed, y_batch
          )
  
          # Execute forward pass on perturbed inputs.
          logits_perturbed = model.predict(x_perturbed)
          # Compute maximization's objective.
          ros = self.relative_output_stability_objective(
              logits, logits_perturbed, a_batch, a_batch_perturbed
          )
          ros_batch[index] = ros
  
          # If perturbed input caused change in prediction, then it's ROS=nan.
          changed_prediction_indices = (
              self.changed_prediction_indices_func(
                  model, x_batch, x_perturbed
              )
          )
  
          if len(changed_prediction_indices) != 0:
              ros_batch[index, changed_prediction_indices] = np.nan
  
      # Compute ROS.
      result = np.max(ros_batch, axis=0)
      if self.return_aggregate:
          result = [self.aggregate_func(result)]
  
      return result
  
file_path: Quantus/quantus/metrics/robustness/relative_output_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 4 for calling the RelativeOutputStability obj's underlying member method code with example usage: obj.evaluate_batch(model, x_batch, y_batch, a_batch) and returns: result