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: Computes relative output stabilities maximization objective
  as defined here :ref:`https://arxiv.org/pdf/2203.06877.pdf` by the authors.
  
  Parameters
  ----------
  h_x: np.ndarray
      Output logits for x_batch.
  h_xs: np.ndarray
      Output logits for xs_batch.
  e_x: np.ndarray
      Explanations for x.
  e_xs: np.ndarray
      Explanations for xs.
  
  Returns
  -------
  ros_obj: np.ndarray
      ROS maximization objective.
docstr_tok: ["Computes","relative","output","stabilities","maximization","objective","as","defined","here",":","ref",":","`","https",":","\/\/arxiv.org\/pdf\/2203.06877.pdf","`","by","the","authors",".","Parameters","--","--","--","--","--","h_x",":","np.ndarray","Output","logits","for","x_batch",".","h_xs",":","np.ndarray","Output","logits","for","xs_batch",".","e_x",":","np.ndarray","Explanations","for","x.","e_xs",":","np.ndarray","Explanations","for","xs",".","Returns","--","--","--","-","ros_obj",":","np.ndarray","ROS","maximization","objective","."]
code: def relative_output_stability_objective(
      self,
      h_x: np.ndarray,
      h_xs: np.ndarray,
      e_x: np.ndarray,
      e_xs: np.ndarray,
  ) -> np.ndarray:
      """
      Computes relative output stabilities maximization objective
      as defined here :ref:`https://arxiv.org/pdf/2203.06877.pdf` by the authors.
  
      Parameters
      ----------
      h_x: np.ndarray
          Output logits for x_batch.
      h_xs: np.ndarray
          Output logits for xs_batch.
      e_x: np.ndarray
          Explanations for x.
      e_xs: np.ndarray
          Explanations for xs.
  
      Returns
      -------
      ros_obj: np.ndarray
          ROS maximization objective.
      """
  
      num_dim = e_x.ndim
      if num_dim == 4:
          norm_function = lambda arr: np.linalg.norm(
              np.linalg.norm(arr, axis=(-1, -2)), axis=-1
          )  # noqa
      elif num_dim == 3:
          norm_function = lambda arr: np.linalg.norm(
              arr, axis=(-1, -2)
          )  # noqa
      elif num_dim == 2:
          norm_function = lambda arr: np.linalg.norm(arr, axis=-1)
      else:
          raise ValueError(
              "Relative Output Stability only supports 4D, 3D and 2D inputs (batch dimension inclusive)."
          )
  
          # fmt: off
          nominator = (e_x - e_xs) / (e_x + (e_x == 0) * self._eps_min)  # prevent division by 0
          nominator = norm_function(nominator)
      # fmt: on
  
      denominator = h_x - h_xs
      denominator = np.linalg.norm(denominator, axis=-1)
      denominator += (
          denominator == 0
      ) * self._eps_min  # prevent division by 0
      return nominator / denominator
  
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 3 for calling the RelativeOutputStability obj's underlying member method code with example usage: obj.relative_output_stability_objective(h_x, h_xs, e_x, e_xs) and returns: unknown