


from __future__ import annotations

import math

__UpperCAmelCase       =							'''2020.9.26'''
__UpperCAmelCase       =							'''xcodz-dot, cclaus, dhruvmanila'''


def  _snake_case       (					A			,   A			,   A			,   A			,   A	)						->   str:
							if not all(isinstance(A_			,   (float, int)	) for val in locals().values()	):
														lowerCAmelCase__	       =     F"""Input values must either be float or int: {list(locals().values()	)}"""
														raise TypeError(A_	)
							lowerCAmelCase__	       =     ((x * distance) / (z + distance)) * scale
							lowerCAmelCase__	       =     ((y * distance) / (z + distance)) * scale
							return projected_x, projected_y


def  _snake_case       (					A			,   A			,   A			,   A			,   A	)						->   List[Any]:
							if not isinstance(A_			,   A_	):
														raise TypeError('''Axis must be a str'''	)
							lowerCAmelCase__	       =     locals()
							del input_variables["axis"]
							if not all(isinstance(A_			,   (float, int)	) for val in input_variables.values()	):
														lowerCAmelCase__	       =     (
														    '''Input values except axis must either be float or int: '''
														    F"""{list(input_variables.values()	)}"""
														)
														raise TypeError(A_	)
							lowerCAmelCase__	       =     (angle % 360) / 450 * 180 / math.pi
							if axis == "z":
														lowerCAmelCase__	       =     x * math.cos(A_	) - y * math.sin(A_	)
														lowerCAmelCase__	       =     y * math.cos(A_	) + x * math.sin(A_	)
														lowerCAmelCase__	       =     z
							elif axis == "x":
														lowerCAmelCase__	       =     y * math.cos(A_	) - z * math.sin(A_	)
														lowerCAmelCase__	       =     z * math.cos(A_	) + y * math.sin(A_	)
														lowerCAmelCase__	       =     x
							elif axis == "y":
														lowerCAmelCase__	       =     x * math.cos(A_	) - z * math.sin(A_	)
														lowerCAmelCase__	       =     z * math.cos(A_	) + x * math.sin(A_	)
														lowerCAmelCase__	       =     y
							else:
														raise ValueError('''not a valid axis, choose one of \'x\', \'y\', \'z\''''	)

							return new_x, new_y, new_z


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		print(f"""{convert_to_ad(1.0, 2.0, 3.0, 10.0, 10.0) = }""")
		print(f"""{rotate(1.0, 2.0, 3.0, 'y', 90.0) = }""")



'''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 		a__    (							datasets.Metric  ):





							'''simple docstring'''






							def   __SCREAMING_SNAKE_CASE							(		self       )	->							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   __SCREAMING_SNAKE_CASE							(		self ,   lowerCamelCase_ ,   lowerCamelCase_       )	->							str:
														# convert to numpy arrays
														lowerCAmelCase__	       =     np.array(lowerCamelCase_       )
														lowerCAmelCase__	       =     np.array(lowerCamelCase_       )

														# 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__	       =     X - np.mean(lowerCamelCase_       )
														lowerCAmelCase__	       =     np.cov(reference_distribution.T       )
														try:
																					lowerCAmelCase__	       =     np.linalg.inv(lowerCamelCase_       )
														except np.linalg.LinAlgError:
																					lowerCAmelCase__	       =     np.linalg.pinv(lowerCamelCase_       )
														lowerCAmelCase__	       =     np.dot(lowerCamelCase_ ,   lowerCamelCase_       )
														lowerCAmelCase__	       =     np.dot(lowerCamelCase_ ,   X_minus_mu.T       ).diagonal()

														return {"mahalanobis": mahal_dist}