






from ...configuration_utils import PretrainedConfig
from ...utils import logging


__magic_name__   :  Optional[int]        =							logging.get_logger(__name__)

__magic_name__   :  List[Any]        =							{
    'facebook/vit-mae-base': 'https://huggingface.co/facebook/vit-mae-base/resolve/main/config.json',
    # See all ViT MAE models at https://huggingface.co/models?filter=vit-mae
}





class 					A__     (     A__ ):

     '''simple docstring'''






     snake_case__					=					"""vit_mae"""







     def __init__( self      :    Optional[Any]   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=768   ,						_SCREAMING_SNAKE_CASE      :    List[Any]=12   ,						_SCREAMING_SNAKE_CASE      :    List[Any]=12   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=3072   ,						_SCREAMING_SNAKE_CASE      :    List[str]="gelu"   ,						_SCREAMING_SNAKE_CASE      :    Any=0.0   ,						_SCREAMING_SNAKE_CASE      :    str=0.0   ,						_SCREAMING_SNAKE_CASE      :    List[Any]=0.0_2   ,						_SCREAMING_SNAKE_CASE      :    str=1E-1_2   ,						_SCREAMING_SNAKE_CASE      :    int=224   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=16   ,						_SCREAMING_SNAKE_CASE      :    Optional[Any]=3   ,						_SCREAMING_SNAKE_CASE      :    Any=True   ,						_SCREAMING_SNAKE_CASE      :    Any=16   ,						_SCREAMING_SNAKE_CASE      :    Any=512   ,						_SCREAMING_SNAKE_CASE      :    Dict=8   ,						_SCREAMING_SNAKE_CASE      :    Optional[int]=2048   ,						_SCREAMING_SNAKE_CASE      :    List[str]=0.7_5   ,						_SCREAMING_SNAKE_CASE      :    Any=False   ,						**_SCREAMING_SNAKE_CASE      :    Union[str, Any]   ,						):






           """simple docstring"""




           super().__init__(**_SCREAMING_SNAKE_CASE )

           UpperCamelCase					       =  hidden_size
           UpperCamelCase					       =  num_hidden_layers
           UpperCamelCase					       =  num_attention_heads
           UpperCamelCase					       =  intermediate_size
           UpperCamelCase					       =  hidden_act
           UpperCamelCase					       =  hidden_dropout_prob
           UpperCamelCase					       =  attention_probs_dropout_prob
           UpperCamelCase					       =  initializer_range
           UpperCamelCase					       =  layer_norm_eps
           UpperCamelCase					       =  image_size
           UpperCamelCase					       =  patch_size
           UpperCamelCase					       =  num_channels
           UpperCamelCase					       =  qkv_bias
           UpperCamelCase					       =  decoder_num_attention_heads
           UpperCamelCase					       =  decoder_hidden_size
           UpperCamelCase					       =  decoder_num_hidden_layers
           UpperCamelCase					       =  decoder_intermediate_size
           UpperCamelCase					       =  mask_ratio
           UpperCamelCase					       =  norm_pix_loss











import numpy as np

import datasets


A__      :     int       =					'\nCompute the Mahalanobis Distance\n\nMahalonobis distance is the distance between a point and a distribution.\nAnd not between two distinct points. It is effectively a multivariate equivalent of the Euclidean distance.\nIt was introduced by Prof. P. C. Mahalanobis in 1936\nand has been used in various statistical applications ever since\n[source: https://www.machinelearningplus.com/statistics/mahalanobis-distance/]\n'

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

A__      :     Optional[int]       =					'\nArgs:\n    X: List of datapoints to be compared with the `reference_distribution`.\n    reference_distribution: List of datapoints from the reference distribution we want to compare to.\nReturns:\n    mahalanobis: The Mahalonobis distance for each datapoint in `X`.\nExamples:\n\n    >>> mahalanobis_metric = datasets.load_metric("mahalanobis")\n    >>> results = mahalanobis_metric.compute(reference_distribution=[[0, 1], [1, 0]], X=[[0, 1]])\n    >>> print(results)\n    {\'mahalanobis\': array([0.5])}\n'
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,_KWARGS_DESCRIPTION      )
class  _UpperCAmelCase   (			datasets.Metric      ):

				"""simple docstring"""




				def 							lowercase__  (	self		:       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 							lowercase__  (	self		:       Dict,    lowerCamelCase		:       int,    lowerCamelCase		:       Optional[int]    ):

								'''simple docstring'''
								# convert to numpy arrays
								lowercase__  					=     np.array(lowerCamelCase    )
								lowercase__  					=     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
								lowercase__  					=     X - np.mean(lowerCamelCase    )
								lowercase__  					=     np.cov(reference_distribution.T    )
								try:
												lowercase__  					=     np.linalg.inv(lowerCamelCase    )
								except np.linalg.LinAlgError:
												lowercase__  					=     np.linalg.pinv(lowerCamelCase    )
								lowercase__  					=     np.dot(lowerCamelCase,    lowerCamelCase    )
								lowercase__  					=     np.dot(lowerCamelCase,    X_minus_mu.T    ).diagonal()

								return {"mahalanobis": mahal_dist}




