



'''simple docstring'''





from sklearn.metrics import precision_score

import datasets


_UpperCamelCase							    =						'\nPrecision is the fraction of correctly labeled positive examples out of all of the examples that were labeled as positive. It is computed via the equation:\nPrecision = TP / (TP + FP)\nwhere TP is the True positives (i.e. the examples correctly labeled as positive) and FP is the False positive examples (i.e. the examples incorrectly labeled as positive).\n'


_UpperCamelCase							    =						'\nArgs:\n    predictions (`list` of `int`): Predicted class labels.\n    references (`list` of `int`): Actual class labels.\n    labels (`list` of `int`): The set of labels to include when `average` is not set to `\'binary\'`. If `average` is `None`, it should be the label order. Labels present in the data can be excluded, for example to calculate a multiclass average ignoring a majority negative class. Labels not present in the data will result in 0 components in a macro average. For multilabel targets, labels are column indices. By default, all labels in `predictions` and `references` are used in sorted order. Defaults to None.\n    pos_label (`int`): The class to be considered the positive class, in the case where `average` is set to `binary`. Defaults to 1.\n    average (`string`): This parameter is required for multiclass/multilabel targets. If set to `None`, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data. Defaults to `\'binary\'`.\n\n        - \'binary\': Only report results for the class specified by `pos_label`. This is applicable only if the classes found in `predictions` and `references` are binary.\n        - \'micro\': Calculate metrics globally by counting the total true positives, false negatives and false positives.\n        - \'macro\': Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.\n        - \'weighted\': Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters `\'macro\'` to account for label imbalance. This option can result in an F-score that is not between precision and recall.\n        - \'samples\': Calculate metrics for each instance, and find their average (only meaningful for multilabel classification).\n    sample_weight (`list` of `float`): Sample weights Defaults to None.\n    zero_division (`int` or `string`): Sets the value to return when there is a zero division. Defaults to \'warn\'.\n\n        - 0: Returns 0 when there is a zero division.\n        - 1: Returns 1 when there is a zero division.\n        - \'warn\': Raises warnings and then returns 0 when there is a zero division.\n\nReturns:\n    precision (`float` or `array` of `float`): Precision score or list of precision scores, depending on the value passed to `average`. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate that fewer negative examples were incorrectly labeled as positive, which means that, generally, higher scores are better.\n\nExamples:\n\n    Example 1-A simple binary example\n        >>> precision_metric = datasets.load_metric("precision")\n        >>> results = precision_metric.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0])\n        >>> print(results)\n        {\'precision\': 0.5}\n\n    Example 2-The same simple binary example as in Example 1, but with `pos_label` set to `0`.\n        >>> precision_metric = datasets.load_metric("precision")\n        >>> results = precision_metric.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0], pos_label=0)\n        >>> print(round(results[\'precision\'], 2))\n        0.67\n\n    Example 3-The same simple binary example as in Example 1, but with `sample_weight` included.\n        >>> precision_metric = datasets.load_metric("precision")\n        >>> results = precision_metric.compute(references=[0, 1, 0, 1, 0], predictions=[0, 0, 1, 1, 0], sample_weight=[0.9, 0.5, 3.9, 1.2, 0.3])\n        >>> print(results)\n        {\'precision\': 0.23529411764705882}\n\n    Example 4-A multiclass example, with different values for the `average` input.\n        >>> predictions = [0, 2, 1, 0, 0, 1]\n        >>> references = [0, 1, 2, 0, 1, 2]\n        >>> results = precision_metric.compute(predictions=predictions, references=references, average=\'macro\')\n        >>> print(results)\n        {\'precision\': 0.2222222222222222}\n        >>> results = precision_metric.compute(predictions=predictions, references=references, average=\'micro\')\n        >>> print(results)\n        {\'precision\': 0.3333333333333333}\n        >>> results = precision_metric.compute(predictions=predictions, references=references, average=\'weighted\')\n        >>> print(results)\n        {\'precision\': 0.2222222222222222}\n        >>> results = precision_metric.compute(predictions=predictions, references=references, average=None)\n        >>> print([round(res, 2) for res in results[\'precision\']])\n        [0.67, 0.0, 0.0]\n'


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






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION       ,       _KWARGS_DESCRIPTION					)
class  lowerCamelCase_   (    datasets.Metric					):
  """simple docstring"""




  def 						_lowercase					(			self				:     str       ) -> List[str]:
    return datasets.MetricInfo(
        description=_DESCRIPTION      ,     citation=_CITATION      ,     inputs_description=_KWARGS_DESCRIPTION      ,     features=datasets.Features(
            {
                'predictions': datasets.Sequence(datasets.Value('int32'       )       ),
                'references': datasets.Sequence(datasets.Value('int32'       )       ),
            }
            if self.config_name == 'multilabel'
            else {
                'predictions': datasets.Value('int32'       ),
                'references': datasets.Value('int32'       ),
            }       )      ,     reference_urls=['https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html']      ,     )




  def 						_lowercase					(			self				:     Tuple      ,     _a				:     Union[str, Any]      ,     _a				:     str      ,     _a				:     List[str]=None      ,     _a				:     Any=1      ,     _a				:     Tuple="binary"      ,     _a				:     Dict=None      ,     _a				:     Optional[Any]="warn"      ,     ) -> int:
    __lowerCamelCase	:	int   	=			precision_score(
        _a      ,     _a      ,     labels=_a      ,     pos_label=_a      ,     average=_a      ,     sample_weight=_a      ,     zero_division=_a      ,     )
    return {"precision": float(_a       ) if score.size == 1 else score}











'''simple docstring'''





from __future__ import annotations

from collections.abc import Iterable






class  lowerCamelCase_   :
  """simple docstring"""




  def __init__(			self				:     int      ,     _a				:     Dict      ,     _a				:     Optional[Any]       ) -> str:
    __lowerCamelCase	,__lowerCamelCase	:	List[Any]   	=			float(_a       ), float(_a       )




  def __eq__(			self				:     Tuple      ,     _a				:     List[Any]       ) -> Optional[int]:
    return self.x == other.x and self.y == other.y




  def __ne__(			self				:     Tuple      ,     _a				:     Optional[int]       ) -> List[str]:
    return not self == other




  def __gt__(			self				:     Tuple      ,     _a				:     str       ) -> str:
    if self.x > other.x:
      return True
    elif self.x == other.x:
      return self.y > other.y
    return False




  def __lt__(			self				:     Union[str, Any]      ,     _a				:     List[Any]       ) -> Optional[Any]:
    return not self > other




  def __ge__(			self				:     Tuple      ,     _a				:     Optional[Any]       ) -> Optional[int]:
    if self.x > other.x:
      return True
    elif self.x == other.x:
      return self.y >= other.y
    return False




  def __le__(			self				:     Any      ,     _a				:     List[str]       ) -> Optional[int]:
    if self.x < other.x:
      return True
    elif self.x == other.x:
      return self.y <= other.y
    return False




  def __repr__(			self				:     int       ) -> Optional[int]:
    return f'({self.x}, {self.y})'




  def __hash__(			self				:     Optional[Any]       ) -> Union[str, Any]:
    return hash(self.x       )




def 	a_					(							_lowerCAmelCase	,)				->				list[Point]:
  __lowerCamelCase	:	list[Point]   	=			[]
  if list_of_tuples:
    for p in list_of_tuples:
      if isinstance(_lowerCAmelCase	,_lowerCAmelCase	):
        points.append(_lowerCAmelCase	)
      else:
        try:
          points.append(Point(p[0]	,p[1]	)	)
        except (IndexError, TypeError):
          print(
              F'Ignoring deformed point {p}. All points'
              ' must have at least 2 coordinates.'	)
  return points

def 	a_					(							_lowerCAmelCase	)				->				list[Point]:

  if not hasattr(_lowerCAmelCase	,'__iter__'	):
    __lowerCamelCase	:	str   	=			F'Expecting an iterable object but got an non-iterable type {points}'
    raise ValueError(_lowerCAmelCase	)

  if not points:
    __lowerCamelCase	:	Any   	=			F'Expecting a list of points but got {points}'
    raise ValueError(_lowerCAmelCase	)

  return _construct_points(_lowerCAmelCase	)

def 	a_					(							_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	)				->				float:
  __lowerCamelCase	:	Optional[int]   	=			(a.x * b.y + b.x * c.y + c.x * a.y) - (a.y * b.x + b.y * c.x + c.y * a.x)
  return det

def 	a_					(							_lowerCAmelCase	)				->				list[Point]:
  __lowerCamelCase	:	Optional[Any]   	=			sorted(_validate_input(_lowerCAmelCase	)	)
  __lowerCamelCase	:	Optional[int]   	=			len(_lowerCAmelCase	)
  __lowerCamelCase	:	Union[str, Any]   	=			set()

  for i in range(n - 1	):
    for j in range(i + 1	,_lowerCAmelCase	):
      __lowerCamelCase	:	List[Any]   	=			False
      __lowerCamelCase	:	Union[str, Any]   	=			True
      for k in range(_lowerCAmelCase	):
        if k != i and k != j:
          __lowerCamelCase	:	Any   	=			_det(points[i]	,points[j]	,points[k]	)

          if det_k > 0:
            __lowerCamelCase	:	List[Any]   	=			True
          elif det_k < 0:
            __lowerCamelCase	:	Any   	=			True
          else:
            # point[i], point[j], point[k] all lie on a straight line
            # if point[k] is to the left of point[i] or it's to the
            # right of point[j], then point[i], point[j] cannot be
            # part of the convex hull of A
            if points[k] < points[i] or points[k] > points[j]:
              __lowerCamelCase	:	Dict   	=			False
              break

        if points_left_of_ij and points_right_of_ij:
          __lowerCamelCase	:	int   	=			False
          break

      if ij_part_of_convex_hull:
        convex_set.update([points[i], points[j]]	)

  return sorted(_lowerCAmelCase	)

def 	a_					(							_lowerCAmelCase	)				->				list[Point]:
  __lowerCamelCase	:	Dict   	=			sorted(_validate_input(_lowerCAmelCase	)	)
  __lowerCamelCase	:	Optional[Any]   	=			len(_lowerCAmelCase	)

  # divide all the points into an upper hull and a lower hull
  # the left most point and the right most point are definitely
  # members of the convex hull by definition.
  # use these two anchors to divide all the points into two hulls,
  # an upper hull and a lower hull.

  # all points to the left (above) the line joining the extreme points belong to the
  # upper hull
  # all points to the right (below) the line joining the extreme points below to the
  # lower hull
  # ignore all points on the line joining the extreme points since they cannot be
  # part of the convex hull

  __lowerCamelCase	:	str   	=			points[0]
  __lowerCamelCase	:	Optional[Any]   	=			points[n - 1]

  __lowerCamelCase	:	Tuple   	=			{left_most_point, right_most_point}
  __lowerCamelCase	:	int   	=			[]
  __lowerCamelCase	:	Tuple   	=			[]

  for i in range(1	,n - 1	):
    __lowerCamelCase	:	Dict   	=			_det(_lowerCAmelCase	,_lowerCAmelCase	,points[i]	)

    if det > 0:
      upper_hull.append(points[i]	)
    elif det < 0:
      lower_hull.append(points[i]	)

  _construct_hull(_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	)
  _construct_hull(_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	)

  return sorted(_lowerCAmelCase	)

def 	a_					(							_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	)				->				None:
  if points:
    __lowerCamelCase	:	Optional[int]   	=			None
    __lowerCamelCase	:	Optional[Any]   	=			float('-inf'	)
    __lowerCamelCase	:	Optional[int]   	=			[]

    for p in points:
      __lowerCamelCase	:	List[str]   	=			_det(_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	)

      if det > 0:
        candidate_points.append(_lowerCAmelCase	)

        if det > extreme_point_distance:
          __lowerCamelCase	:	Union[str, Any]   	=			det
          __lowerCamelCase	:	Dict   	=			p

    if extreme_point:
      _construct_hull(_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	)
      convex_set.add(_lowerCAmelCase	)
      _construct_hull(_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	,_lowerCAmelCase	)

def 	a_					(							_lowerCAmelCase	)				->				list[Point]:
  __lowerCamelCase	:	Optional[int]   	=			sorted(_validate_input(_lowerCAmelCase	)	)
  __lowerCamelCase	:	List[Any]   	=			len(_lowerCAmelCase	)

  __lowerCamelCase	:	Tuple   	=			points[:2]
  for i in range(2	,_lowerCAmelCase	):
    __lowerCamelCase	:	Tuple   	=			_det(convex_hull[1]	,convex_hull[0]	,points[i]	)
    if det > 0:
      convex_hull.insert(0	,points[i]	)
      break
    elif det < 0:
      convex_hull.append(points[i]	)
      break
    else:
      __lowerCamelCase	:	Optional[int]   	=			points[i]
  i += 1

  for j in range(_lowerCAmelCase	,_lowerCAmelCase	):
    if (
        _det(convex_hull[0]	,convex_hull[-1]	,points[j]	) > 0
        and _det(convex_hull[-1]	,convex_hull[0]	,points[1]	) < 0
    ):
      # The point lies within the convex hull
      continue

    convex_hull.insert(0	,points[j]	)
    convex_hull.append(points[j]	)
    while _det(convex_hull[0]	,convex_hull[1]	,convex_hull[2]	) >= 0:
      del convex_hull[1]
    while _det(convex_hull[-1]	,convex_hull[-2]	,convex_hull[-3]	) <= 0:
      del convex_hull[-2]

    # `convex_hull` is contains the convex hull in circular order
  return sorted(convex_hull[1:] if len(_lowerCAmelCase	) > 3 else convex_hull	)

def 	a_					(							)				->				Optional[int]:
  __lowerCamelCase	:	List[Any]   	=			[
      (0, 3),
      (2, 2),
      (1, 1),
      (2, 1),
      (3, 0),
      (0, 0),
      (3, 3),
      (2, -1),
      (2, -4),
      (1, -3),
  ]
  # the convex set of points is
  # [(0, 0), (0, 3), (1, -3), (2, -4), (3, 0), (3, 3)]
  __lowerCamelCase	:	Any   	=			convex_hull_bf(_lowerCAmelCase	)

  __lowerCamelCase	:	Optional[int]   	=			convex_hull_recursive(_lowerCAmelCase	)
  assert results_bf == results_recursive

  __lowerCamelCase	:	int   	=			convex_hull_melkman(_lowerCAmelCase	)
  assert results_bf == results_melkman

  print(_lowerCAmelCase	)


if __name__ == "__main__":
   main()






