
"""simple docstring"""


from scipy.stats import spearmanr

import datasets


SCREAMING_SNAKE_CASE      =     """
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
"""

SCREAMING_SNAKE_CASE      =     """
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {'spearmanr': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results['spearmanr'])
        -0.7
        >>> print(round(results['spearmanr_pvalue'], 2))
        0.19
"""

SCREAMING_SNAKE_CASE      =     R"""\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
"""



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






       def 	_SCREAMING_SNAKE_CASE       (  self :							int			)->  List[Any]:







              """simple docstring"""
              return datasets.MetricInfo(
                  description=_DESCRIPTION       ,      citation=_CITATION       ,      inputs_description=_KWARGS_DESCRIPTION       ,      features=datasets.Features(
                      {
                          "predictions": datasets.Value("float"			),
                          "references": datasets.Value("float"			),
                      }			)       ,      reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"]       ,      )






       def 	_SCREAMING_SNAKE_CASE       (  self :							Optional[Any]       ,      UpperCAmelCase_ :							Optional[Any]       ,      UpperCAmelCase_ :							Tuple       ,      UpperCAmelCase_ :							Tuple=False			)->  int:







              """simple docstring"""
              UpperCamelCase					 =		spearmanr(UpperCAmelCase_       ,      UpperCAmelCase_			)
              if return_pvalue:
                     return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
              else:
                     return {"spearmanr": results[0]}







"""simple docstring"""


from .integrations import (
    is_optuna_available,
    is_ray_available,
    is_sigopt_available,
    is_wandb_available,
    run_hp_search_optuna,
    run_hp_search_ray,
    run_hp_search_sigopt,
    run_hp_search_wandb,
)
from .trainer_utils import (
    HPSearchBackend,
    default_hp_space_optuna,
    default_hp_space_ray,
    default_hp_space_sigopt,
    default_hp_space_wandb,
)
from .utils import logging


SCREAMING_SNAKE_CASE      =     logging.get_logger(__name__)



class   __a  :
       UpperCamelCase_		:					str
       UpperCamelCase_		:					str   =			None






       @staticmethod
       def 	_SCREAMING_SNAKE_CASE       (  )->  Union[str, Any]:







              """simple docstring"""
              raise NotImplementedError






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[str]       ,      UpperCAmelCase_ :							Optional[int]       ,      UpperCAmelCase_ :							int       ,      UpperCAmelCase_ :							str       ,      **UpperCAmelCase_ :							Dict			)->  Union[str, Any]:







              """simple docstring"""
              raise NotImplementedError






       def 	_SCREAMING_SNAKE_CASE       (  self :							Optional[int]       ,      UpperCAmelCase_ :							str			)->  Any:







              """simple docstring"""
              raise NotImplementedError






       def 	_SCREAMING_SNAKE_CASE       (  self :							Union[str, Any]			)->  List[str]:







              """simple docstring"""
              if not self.is_available():
                     raise RuntimeError(
                         f"You picked the {self.name} backend, but it is not installed. Run {self.pip_install()}."			)






       @classmethod
       def 	_SCREAMING_SNAKE_CASE       (  cls :							Union[str, Any]			)->  int:







              """simple docstring"""
              return f"`pip install {cls.pip_package or cls.name}`"





class   __a  (      _lowerCAmelCase	):
       UpperCamelCase_		:					List[str]   =			'''optuna'''






       @staticmethod
       def 	_SCREAMING_SNAKE_CASE       (  )->  Union[str, Any]:







              """simple docstring"""
              return is_optuna_available()






       def 	_SCREAMING_SNAKE_CASE       (  self :							Dict       ,      UpperCAmelCase_ :							List[str]       ,      UpperCAmelCase_ :							int       ,      UpperCAmelCase_ :							str       ,      **UpperCAmelCase_ :							Optional[Any]			)->  Union[str, Any]:







              """simple docstring"""
              return run_hp_search_optuna(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      **UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Dict       ,      UpperCAmelCase_ :							Union[str, Any]			)->  Union[str, Any]:







              """simple docstring"""
              return default_hp_space_optuna(UpperCAmelCase_			)





class   __a  (      _lowerCAmelCase	):
       UpperCamelCase_		:					Optional[int]   =			'''ray'''
       UpperCamelCase_		:					Tuple   =			'''\'ray[tune]\''''






       @staticmethod
       def 	_SCREAMING_SNAKE_CASE       (  )->  Any:







              """simple docstring"""
              return is_ray_available()






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[Any]       ,      UpperCAmelCase_ :							Any       ,      UpperCAmelCase_ :							int       ,      UpperCAmelCase_ :							str       ,      **UpperCAmelCase_ :							int			)->  int:







              """simple docstring"""
              return run_hp_search_ray(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      **UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							str       ,      UpperCAmelCase_ :							str			)->  Union[str, Any]:







              """simple docstring"""
              return default_hp_space_ray(UpperCAmelCase_			)





class   __a  (      _lowerCAmelCase	):
       UpperCamelCase_		:					Union[str, Any]   =			'''sigopt'''






       @staticmethod
       def 	_SCREAMING_SNAKE_CASE       (  )->  List[str]:







              """simple docstring"""
              return is_sigopt_available()






       def 	_SCREAMING_SNAKE_CASE       (  self :							Tuple       ,      UpperCAmelCase_ :							List[str]       ,      UpperCAmelCase_ :							int       ,      UpperCAmelCase_ :							str       ,      **UpperCAmelCase_ :							Tuple			)->  Tuple:







              """simple docstring"""
              return run_hp_search_sigopt(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      **UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							List[Any]       ,      UpperCAmelCase_ :							Tuple			)->  Optional[Any]:







              """simple docstring"""
              return default_hp_space_sigopt(UpperCAmelCase_			)





class   __a  (      _lowerCAmelCase	):
       UpperCamelCase_		:					Any   =			'''wandb'''






       @staticmethod
       def 	_SCREAMING_SNAKE_CASE       (  )->  List[Any]:







              """simple docstring"""
              return is_wandb_available()






       def 	_SCREAMING_SNAKE_CASE       (  self :							int       ,      UpperCAmelCase_ :							Optional[int]       ,      UpperCAmelCase_ :							int       ,      UpperCAmelCase_ :							str       ,      **UpperCAmelCase_ :							List[str]			)->  str:







              """simple docstring"""
              return run_hp_search_wandb(UpperCAmelCase_       ,      UpperCAmelCase_       ,      UpperCAmelCase_       ,      **UpperCAmelCase_			)






       def 	_SCREAMING_SNAKE_CASE       (  self :							Tuple       ,      UpperCAmelCase_ :							List[Any]			)->  List[Any]:







              """simple docstring"""
              return default_hp_space_wandb(UpperCAmelCase_			)





SCREAMING_SNAKE_CASE      =     {
    HPSearchBackend(backend.name): backend for backend in [OptunaBackend, RayTuneBackend, SigOptBackend, WandbBackend]
}



def 	lowerCamelCase__			(							)->							str:







       """simple docstring"""
       UpperCamelCase					 =		[backend for backend in ALL_HYPERPARAMETER_SEARCH_BACKENDS.values() if backend.is_available()]
       if len(UpperCAmelCase_				) > 0:
              UpperCamelCase					 =		available_backends[0].name
              if len(UpperCAmelCase_				) > 1:
                     logger.info(
                         F"{len(UpperCAmelCase_				)} hyperparameter search backends available. Using {name} as the default."				)
              return name
       raise RuntimeError(
           "No hyperparameter search backend available.\n"
           + "\n".join(
               F" - To install {backend.name} run {backend.pip_install()}"
               for backend in ALL_HYPERPARAMETER_SEARCH_BACKENDS.values()				)				)





