


"""simple docstring"""
import numpy as np

import datasets


UpperCAmelCase				=						"""
Compute the Mahalanobis Distance

Mahalonobis distance is the distance between a point and a distribution.
And not between two distinct points. It is effectively a multivariate equivalent of the Euclidean distance.
It was introduced by Prof. P. C. Mahalanobis in 1936
and has been used in various statistical applications ever since
[source: https://www.machinelearningplus.com/statistics/mahalanobis-distance/]
"""

UpperCAmelCase				=						"""\
@article{de2000mahalanobis,
  title={The mahalanobis distance},
  author={De Maesschalck, Roy and Jouan-Rimbaud, Delphine and Massart, D{\'e}sir{\'e} L},
  journal={Chemometrics and intelligent laboratory systems},
  volume={50},
  number={1},
  pages={1--18},
  year={2000},
  publisher={Elsevier}
}
"""

UpperCAmelCase				=						"""
Args:
    X: List of datapoints to be compared with the `reference_distribution`.
    reference_distribution: List of datapoints from the reference distribution we want to compare to.
Returns:
    mahalanobis: The Mahalonobis distance for each datapoint in `X`.
Examples:

    >>> mahalanobis_metric = datasets.load_metric(\"mahalanobis\")
    >>> results = mahalanobis_metric.compute(reference_distribution=[[0, 1], [1, 0]], X=[[0, 1]])
    >>> print(results)
    {'mahalanobis': array([0.5])}
"""




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION ,_KWARGS_DESCRIPTION				)
class 	lowercase__				(					datasets.Metric				):





   def 		UpperCamelCase_  (							self)  ->  Union[str, Any]:
      return datasets.MetricInfo(
          description=_DESCRIPTION      ,   citation=_CITATION      ,   inputs_description=_KWARGS_DESCRIPTION      ,   features=datasets.Features(
              {
                  """X""": datasets.Sequence(datasets.Value("""float"""      ,   id="""sequence""")      ,   id="""X"""),
              })      ,   )





   def 		UpperCamelCase_  (							self      ,   SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)  ->  str:
      # convert to numpy arrays
      _lowerCamelCase	:					Optional[Any]   =		np.array(SCREAMING_SNAKE_CASE)
      _lowerCamelCase	:					Any   =		np.array(SCREAMING_SNAKE_CASE)

      # Assert that arrays are 2D
      if len(X.shape) != 2:
         raise ValueError("""Expected `X` to be a 2D vector""")
      if len(reference_distribution.shape) != 2:
         raise ValueError("""Expected `reference_distribution` to be a 2D vector""")
      if reference_distribution.shape[0] < 2:
         raise ValueError(
             """Expected `reference_distribution` to be a 2D vector with more than one element in the first dimension""")

      # Get mahalanobis distance for each prediction
      _lowerCamelCase	:					Tuple   =		X - np.mean(SCREAMING_SNAKE_CASE)
      _lowerCamelCase	:					Dict   =		np.cov(reference_distribution.T)
      try:
         _lowerCamelCase	:					Optional[Any]   =		np.linalg.inv(SCREAMING_SNAKE_CASE)
      except np.linalg.LinAlgError:
         _lowerCamelCase	:					Any   =		np.linalg.pinv(SCREAMING_SNAKE_CASE)
      _lowerCamelCase	:					str   =		np.dot(SCREAMING_SNAKE_CASE      ,   SCREAMING_SNAKE_CASE)
      _lowerCamelCase	:					int   =		np.dot(SCREAMING_SNAKE_CASE      ,   X_minus_mu.T).diagonal()

      return {"mahalanobis": mahal_dist}





"""simple docstring"""
from transformers import HfArgumentParser, TensorFlowBenchmark, TensorFlowBenchmarkArguments

def 				_snake_case      (   ):




   """simple docstring"""







   _lowerCamelCase	:					Any   =		HfArgumentParser(__snake_case   )
   _lowerCamelCase	:					int   =		parser.parse_args_into_dataclasses()[0]
   _lowerCamelCase	:					Dict   =		TensorFlowBenchmark(args=__snake_case   )
   try:
      _lowerCamelCase	:					Optional[int]   =		parser.parse_args_into_dataclasses()[0]
   except ValueError as e:
      _lowerCamelCase	:					Union[str, Any]   =		"""Arg --no_{0} is no longer used, please use --no-{0} instead."""
      _lowerCamelCase	:					List[str]   =		""" """.join(str(__snake_case   ).split(""" """   )[:-1]   )
      _lowerCamelCase	:					Dict   =		""""""
      _lowerCamelCase	:					List[Any]   =		eval(str(__snake_case   ).split(""" """   )[-1]   )
      _lowerCamelCase	:					Tuple   =		[]
      for arg in depreciated_args:
         # arg[2:] removes '--'
         if arg[2:] in TensorFlowBenchmark.deprecated_args:
            # arg[5:] removes '--no_'
            full_error_msg += arg_error_msg.format(arg[5:]   )
         else:
            wrong_args.append(__snake_case   )
      if len(__snake_case   ) > 0:
         _lowerCamelCase	:					Tuple   =		full_error_msg + begin_error_msg + str(__snake_case   )
      raise ValueError(__snake_case   )
   benchmark.run()


if __name__ == "__main__":
 main()

