
from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import center_crop, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
					import PIL


SCREAMING_SNAKE_CASE							:int							 =				logging.get_logger(__name__)





class 							UpperCAmelCase      (  __SCREAMING_SNAKE_CASE  ):




	'''simple docstring'''





	snake_case_					    =     ["pixel_values"]






	def __init__(       self					: List[str]							,A					: bool = True							,A					: Dict[str, int] = None							,A					: PILImageResampling = PIL.Image.BICUBIC							,A					: bool = True							,A					: Dict[str, int] = None							,A					: Union[int, float] = 1 / 2_55							,A					: bool = True							,A					: bool = True							,A					: Optional[Union[float, List[float]]] = None							,A					: Optional[Union[float, List[float]]] = None							,**A					: Optional[int]							,):
					super().__init__(**A )
					__A   			= size if size is not None else {"height": 2_56, "width": 2_56}
					__A   			= get_size_dict(A )
					__A   			= crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
					__A   			= get_size_dict(A							,param_name="crop_size" )

					__A   			= do_resize
					__A   			= size
					__A   			= resample
					__A   			= do_center_crop
					__A   			= crop_size
					__A   			= do_rescale
					__A   			= rescale_factor
					__A   			= do_normalize
					__A   			= image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
					__A   			= image_std if image_std is not None else IMAGENET_STANDARD_STD






	def 				UpperCamelCase_  (       self					: Optional[Any]							,A					: np.ndarray							,A					: Dict[str, int]							,A					: PILImageResampling = PIL.Image.BICUBIC							,A					: Optional[Union[str, ChannelDimension]] = None							,**A					: Optional[Any]							,):
					__A   			= get_size_dict(A )
					if "height" not in size or "width" not in size:
									raise ValueError(f'''The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}''' )
					return resize(
					    A							,size=(size["height"], size["width"])							,resample=A							,data_format=A							,**A )






	def 				UpperCamelCase_  (       self					: Optional[int]							,A					: np.ndarray							,A					: Dict[str, int]							,A					: Optional[Union[str, ChannelDimension]] = None							,**A					: Optional[int]							,):
					__A   			= get_size_dict(A )
					if "height" not in size or "width" not in size:
									raise ValueError(f'''The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}''' )
					return center_crop(A							,size=(size["height"], size["width"])							,data_format=A							,**A )






	def 				UpperCamelCase_  (       self					: int							,A					: np.ndarray							,A					: Union[int, float]							,A					: Optional[Union[str, ChannelDimension]] = None							,**A					: Any							,):
					return rescale(A							,scale=A							,data_format=A							,**A )






	def 				UpperCamelCase_  (       self					: Tuple							,A					: np.ndarray							,A					: Union[float, List[float]]							,A					: Union[float, List[float]]							,A					: Optional[Union[str, ChannelDimension]] = None							,**A					: Union[str, Any]							,):
					return normalize(A							,mean=A							,std=A							,data_format=A							,**A )







	def 				UpperCamelCase_  (       self					: Tuple							,A					: ImageInput							,A					: bool = None							,A					: Dict[str, int] = None							,A					: Optional[Any]=None							,A					: bool = None							,A					: Dict[str, int] = None							,A					: bool = None							,A					: float = None							,A					: bool = None							,A					: Optional[Union[float, List[float]]] = None							,A					: Optional[Union[float, List[float]]] = None							,A					: Optional[Union[str, TensorType]] = None							,A					: ChannelDimension = ChannelDimension.FIRST							,**A					: Optional[Any]							,):
					__A   			= do_resize if do_resize is not None else self.do_resize
					__A   			= resample if resample is not None else self.resample
					__A   			= do_center_crop if do_center_crop is not None else self.do_center_crop
					__A   			= do_rescale if do_rescale is not None else self.do_rescale
					__A   			= rescale_factor if rescale_factor is not None else self.rescale_factor
					__A   			= do_normalize if do_normalize is not None else self.do_normalize
					__A   			= image_mean if image_mean is not None else self.image_mean
					__A   			= image_std if image_std is not None else self.image_std

					__A   			= size if size is not None else self.size
					__A   			= get_size_dict(A )
					__A   			= crop_size if crop_size is not None else self.crop_size
					__A   			= get_size_dict(A							,param_name="crop_size" )

					__A   			= make_list_of_images(A )

					if not valid_images(A ):
									raise ValueError(
									    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
									    "torch.Tensor, tf.Tensor or jax.ndarray." )

					if do_resize and size is None or resample is None:
									raise ValueError("Size and resample must be specified if do_resize is True." )

					if do_center_crop and crop_size is None:
									raise ValueError("Crop size must be specified if do_center_crop is True." )

					if do_rescale and rescale_factor is None:
									raise ValueError("Rescale factor must be specified if do_rescale is True." )

					if do_normalize and (image_mean is None or image_std is None):
									raise ValueError("Image mean and std must be specified if do_normalize is True." )

					# All transformations expect numpy arrays.
					__A   			= [to_numpy_array(A ) for image in images]

					if do_resize:
									__A   			= [self.resize(image=A							,size=A							,resample=A ) for image in images]

					if do_center_crop:
									__A   			= [self.center_crop(image=A							,size=A ) for image in images]

					if do_rescale:
									__A   			= [self.rescale(image=A							,scale=A ) for image in images]

					if do_normalize:
									__A   			= [self.normalize(image=A							,mean=A							,std=A ) for image in images]

					__A   			= [to_channel_dimension_format(A							,A ) for image in images]

					__A   			= {"pixel_values": images}
					return BatchFeature(data=A							,tensor_type=A )


"""simple docstring"""





from sklearn.metrics import matthews_corrcoef

import datasets


_a														=		"""
Compute the Matthews correlation coefficient (MCC)

The Matthews correlation coefficient is used in machine learning as a
measure of the quality of binary and multiclass classifications. It takes
into account true and false positives and negatives and is generally
regarded as a balanced measure which can be used even if the classes are of
very different sizes. The MCC is in essence a correlation coefficient value
between -1 and +1. A coefficient of +1 represents a perfect prediction, 0
an average random prediction and -1 an inverse prediction.  The statistic
is also known as the phi coefficient. [source: Wikipedia]
"""

_a														=		"""
Args:
    predictions (list of int): Predicted labels, as returned by a model.
    references (list of int): Ground truth labels.
    sample_weight (list of int, float, or bool): Sample weights. Defaults to `None`.
Returns:
    matthews_correlation (dict containing float): Matthews correlation.
Examples:
    Example 1, a basic example with only predictions and references as inputs:
        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")
        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],
        ...                                     predictions=[1, 2, 2, 0, 3, 3])
        >>> print(round(results['matthews_correlation'], 2))
        0.54

    Example 2, the same example as above, but also including sample weights:
        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")
        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],
        ...                                     predictions=[1, 2, 2, 0, 3, 3],
        ...                                     sample_weight=[0.5, 3, 1, 1, 1, 2])
        >>> print(round(results['matthews_correlation'], 2))
        0.1

    Example 3, the same example as above, but with sample weights that cause a negative correlation:
        >>> matthews_metric = datasets.load_metric(\"matthews_correlation\")
        >>> results = matthews_metric.compute(references=[1, 3, 2, 0, 3, 2],
        ...                                     predictions=[1, 2, 2, 0, 3, 3],
        ...                                     sample_weight=[0.5, 1, 0, 0, 0, 1])
        >>> print(round(results['matthews_correlation'], 2))
        -0.25
"""

_a														=		"""\
@article{scikit-learn,
  title={Scikit-learn: Machine Learning in {P}ython},
  author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
  journal={Journal of Machine Learning Research},
  volume={12},
  pages={2825--2830},
  year={2011}
}
"""






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



		def 						UpperCAmelCase							(					self)       ->       List[Any]:






							'''simple docstring'''
							return datasets.MetricInfo(
							    description=_DESCRIPTION				,		citation=_CITATION				,		inputs_description=_KWARGS_DESCRIPTION				,		features=datasets.Features(
							        {
							            '''predictions''': datasets.Value('''int32'''),
							            '''references''': datasets.Value('''int32'''),
							        })				,		reference_urls=[
							        '''https://scikit-learn.org/stable/modules/generated/sklearn.metrics.matthews_corrcoef.html'''
							    ]				,		)




		def 						UpperCAmelCase							(					self				,		__a				,		__a				,		__a=None)       ->       Dict:






							'''simple docstring'''
							return {
							    "matthews_correlation": float(matthews_corrcoef(__a				,		__a				,		sample_weight=__a)),
							}






