



import numpy as np

import datasets


SCREAMING_SNAKE_CASE__   			=   '''
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/]
'''

SCREAMING_SNAKE_CASE__   			=   '''\
@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}
}
'''

SCREAMING_SNAKE_CASE__   			=   '''
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   __lowerCAmelCase  (		datasets.Metric   ):
					"""simple docstring"""






					def      _a				(  self       :							List[str]       ):






								"""simple docstring"""


								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      _a				(  self       :							Tuple					,       _snake_case       :							Union[str, Any]					,       _snake_case       :							Any       ):






								"""simple docstring"""


								A__	  =     np.array(_snake_case       )
								A__	  =     np.array(_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
								A__	  =     X - np.mean(_snake_case       )
								A__	  =     np.cov(reference_distribution.T       )
								try:
											A__	  =     np.linalg.inv(_snake_case       )
								except np.linalg.LinAlgError:
											A__	  =     np.linalg.pinv(_snake_case       )
								A__	  =     np.dot(_snake_case					,       _snake_case       )
								A__	  =     np.dot(_snake_case					,       X_minus_mu.T       ).diagonal()

								return {"mahalanobis": mahal_dist}









'''simple docstring'''





import functools





def   a_   (		_UpperCAmelCase    :      list[int] ,_UpperCAmelCase    :      list[int]				)    ->  int:

      # Validation
      if not isinstance(_UpperCAmelCase ,_UpperCAmelCase				) or not all(isinstance(_UpperCAmelCase ,_UpperCAmelCase				) for day in days				):
            raise ValueError('The parameter days should be a list of integers'				)

      if len(_UpperCAmelCase				) != 3 or not all(isinstance(_UpperCAmelCase ,_UpperCAmelCase				) for cost in costs				):
            raise ValueError('The parameter costs should be a list of three integers'				)

      if len(_UpperCAmelCase				) == 0:
            return 0

      if min(_UpperCAmelCase				) <= 0:
            raise ValueError('All days elements should be greater than 0'				)

      if max(_UpperCAmelCase				) >= 3_66:
            raise ValueError('All days elements should be less than 366'				)

      __snake_case :   str													=    set(_UpperCAmelCase				)

      @functools.cache
      def dynamic_programming(_UpperCAmelCase    :      int				) -> int:
            if index > 3_65:
                  return 0

            if index not in days_set:
                  return dynamic_programming(index + 1				)

            return min(
                costs[0] + dynamic_programming(index + 1				) ,costs[1] + dynamic_programming(index + 7				) ,costs[2] + dynamic_programming(index + 30				) ,)

      return dynamic_programming(1				)


if __name__ == "__main__":
    import doctest

    doctest.testmod()



