

'''simple docstring'''



from __future__ import annotations

import random

from matplotlib import animation
from matplotlib import pyplot as plt

# Frame rate of the animation
UpperCAmelCase				: Union[str, Any]         =  2_0

# Time between time steps in seconds
UpperCAmelCase				: Tuple         =  INTERVAL / 1_0_0_0







class 		lowerCAmelCase__     :



 """simple docstring"""



 def __init__(	self      : str      ,							__SCREAMING_SNAKE_CASE      : float      ,							__SCREAMING_SNAKE_CASE      : float      ,							__SCREAMING_SNAKE_CASE      : float      ,							__SCREAMING_SNAKE_CASE      : float      ,							__SCREAMING_SNAKE_CASE      : float = 1.0      ,							__SCREAMING_SNAKE_CASE      : float = 1.0      ,							__SCREAMING_SNAKE_CASE      : str = "blue"      ,							)						->				None:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE						     =   position_x
      __SCREAMING_SNAKE_CASE						     =   position_y
      __SCREAMING_SNAKE_CASE						     =   velocity_x
      __SCREAMING_SNAKE_CASE						     =   velocity_y
      __SCREAMING_SNAKE_CASE						     =   mass
      __SCREAMING_SNAKE_CASE						     =   size
      __SCREAMING_SNAKE_CASE						     =   color
 @property
 def    UpperCAmelCase__	(	self      : List[str]    )						->				tuple[float, float]:


      """simple docstring"""




      return self.position_x, self.position_y
 @property
 def    UpperCAmelCase__	(	self      : Optional[Any]    )						->				tuple[float, float]:


      """simple docstring"""




      return self.velocity_x, self.velocity_y
 def    UpperCAmelCase__	(	self      : Any      ,							__SCREAMING_SNAKE_CASE      : float      ,							__SCREAMING_SNAKE_CASE      : float      ,							__SCREAMING_SNAKE_CASE      : float    )						->				None:


      """simple docstring"""




      self.velocity_x += force_x * delta_time
      self.velocity_y += force_y * delta_time


 def    UpperCAmelCase__	(	self      : Any      ,							__SCREAMING_SNAKE_CASE      : float    )						->				None:


      """simple docstring"""




      self.position_x += self.velocity_x * delta_time
      self.position_y += self.velocity_y * delta_time







class 		lowerCAmelCase__     :



 """simple docstring"""



 def __init__(	self      : Optional[int]      ,							__SCREAMING_SNAKE_CASE      : list[Body]      ,							__SCREAMING_SNAKE_CASE      : float = 1.0      ,							__SCREAMING_SNAKE_CASE      : float = 1.0      ,							__SCREAMING_SNAKE_CASE      : float = 0.0      ,							)						->				None:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE						     =   bodies
      __SCREAMING_SNAKE_CASE						     =   gravitation_constant
      __SCREAMING_SNAKE_CASE						     =   time_factor
      __SCREAMING_SNAKE_CASE						     =   softening_factor
 def __len__(	self      : Any    )						->				int:


      """simple docstring"""




      return len(self.bodies    )


 def    UpperCAmelCase__	(	self      : Any      ,							__SCREAMING_SNAKE_CASE      : float    )						->				None:


      """simple docstring"""




      for bodya in self.bodies:
           __SCREAMING_SNAKE_CASE						     =   0.0
           __SCREAMING_SNAKE_CASE						     =   0.0
           for bodya in self.bodies:
                if bodya != bodya:
                     __SCREAMING_SNAKE_CASE						     =   bodya.position_x - bodya.position_x
                     __SCREAMING_SNAKE_CASE						     =   bodya.position_y - bodya.position_y

                     # Calculation of the distance using Pythagoras's theorem
                     # Extra factor due to the softening technique
                     __SCREAMING_SNAKE_CASE						     =   (dif_x**2 + dif_y**2 + self.softening_factor) ** (
                         1 / 2
                     )

                     # Newton's law of universal gravitation.
                     force_x += (
                         self.gravitation_constant * bodya.mass * dif_x / distance**3
                     )
                     force_y += (
                         self.gravitation_constant * bodya.mass * dif_y / distance**3
                     )

            # Update the body's velocity once all the force components have been added
           bodya.update_velocity(__SCREAMING_SNAKE_CASE      ,							__SCREAMING_SNAKE_CASE      ,							delta_time * self.time_factor    )

      # Update the positions only after all the velocities have been updated
      for body in self.bodies:
           body.update_position(delta_time * self.time_factor    )







def      a__ (						a__   ,					a__   ,					a__		):




     """simple docstring"""


     body_system.update_system(a__		)

     # Update the positions of the patches
     for patch, body in zip(a__   ,					body_system.bodies		):
          __SCREAMING_SNAKE_CASE						     =   (body.position_x, body.position_y)







def      a__ (						a__   ,					a__   ,					a__ = -1   ,					a__ = 1   ,					a__ = -1   ,					a__ = 1   ,					):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE						     =   plt.figure()
     fig.canvas.set_window_title(a__		)
     __SCREAMING_SNAKE_CASE						     =   plt.axes(
         xlim=(x_start, x_end)   ,					ylim=(y_start, y_end)		)  # Set section to be plotted
     plt.gca().set_aspect("""equal"""		)  # Fix aspect ratio

     # Each body is drawn as a patch by the plt-function
     __SCREAMING_SNAKE_CASE						     =   [
         plt.Circle((body.position_x, body.position_y)   ,					body.size   ,					fc=body.color		)
         for body in body_system.bodies
     ]

     for patch in patches:
          ax.add_patch(a__		)

     # Function called at each step of the animation
     def update(a__		) -> list[plt.Circle]:
          update_step(a__   ,					a__   ,					a__		)
          return patches

     __SCREAMING_SNAKE_CASE						     =   animation.FuncAnimation(  # noqa: F841
         a__   ,					a__   ,					interval=a__   ,					blit=a__		)

     plt.show()







def      a__ (						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE						     =   0.9_700_436
     __SCREAMING_SNAKE_CASE						     =   -0.24_308_753
     __SCREAMING_SNAKE_CASE						     =   0.466_203_685
     __SCREAMING_SNAKE_CASE						     =   0.43_236_573

     __SCREAMING_SNAKE_CASE						     =   [
         Body(a__   ,					a__   ,					a__   ,					a__   ,					size=0.2   ,					color="""red"""		),
         Body(-position_x   ,					-position_y   ,					a__   ,					a__   ,					size=0.2   ,					color="""green"""		),
         Body(0   ,					0   ,					-2 * velocity_x   ,					-2 * velocity_y   ,					size=0.2   ,					color="""blue"""		),
     ]
     return BodySystem(a__   ,					time_factor=3		)







def      a__ (						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE						     =   7.3_4_7_6E2_2
     __SCREAMING_SNAKE_CASE						     =   5.9_7_2E2_4
     __SCREAMING_SNAKE_CASE						     =   10_22
     __SCREAMING_SNAKE_CASE						     =   3_84_39_90_00
     __SCREAMING_SNAKE_CASE						     =   6.6_7_4E-1_1

     # Calculation of the respective velocities so that total impulse is zero,
     # i.e. the two bodies together don't move
     __SCREAMING_SNAKE_CASE						     =   earth_mass * velocity_dif / (earth_mass + moon_mass)
     __SCREAMING_SNAKE_CASE						     =   moon_velocity - velocity_dif

     __SCREAMING_SNAKE_CASE						     =   Body(-earth_moon_distance   ,					0   ,					0   ,					a__   ,					a__   ,					10_00_00_00   ,					"""grey"""		)
     __SCREAMING_SNAKE_CASE						     =   Body(0   ,					0   ,					0   ,					a__   ,					a__   ,					50_00_00_00   ,					"""blue"""		)
     return BodySystem([earth, moon]   ,					a__   ,					time_factor=1_00_00_00		)







def      a__ (						):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE						     =   []
     for _ in range(10		):
          __SCREAMING_SNAKE_CASE						     =   random.uniform(-0.5   ,					0.5		)
          __SCREAMING_SNAKE_CASE						     =   random.uniform(-0.5   ,					0.5		)

          # Bodies are created pairwise with opposite velocities so that the
          # total impulse remains zero
          bodies.append(
              Body(
                  random.uniform(-0.5   ,					0.5		)   ,					random.uniform(-0.5   ,					0.5		)   ,					a__   ,					a__   ,					size=0.05   ,					)		)
          bodies.append(
              Body(
                  random.uniform(-0.5   ,					0.5		)   ,					random.uniform(-0.5   ,					0.5		)   ,					-velocity_x   ,					-velocity_y   ,					size=0.05   ,					)		)
     return BodySystem(a__   ,					0.01   ,					10   ,					0.1		)


if __name__ == "__main__":
  plot('Figure-8 solution to the 3-body-problem', example_a(), -2, 2, -2, 2)
  plot(
      'Moon\'s orbit around the earth',
      example_a(),
      -4_3_0_0_0_0_0_0_0,
      4_3_0_0_0_0_0_0_0,
      -4_3_0_0_0_0_0_0_0,
      4_3_0_0_0_0_0_0_0,
  )
  plot('Random system with many bodies', example_a(), -1.5, 1.5, -1.5, 1.5)









'''simple docstring'''



from sklearn.metrics import precision_score

import datasets


UpperCAmelCase				: Optional[int]         =  '\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				: Optional[int]         =  '\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				: Union[str, Any]         =  '\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    UpperCAmelCase__	(	self      : List[str]    )						->				Dict:


      """simple docstring"""




      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    UpperCAmelCase__	(	self      : List[Any]      ,							__SCREAMING_SNAKE_CASE      : List[str]      ,							__SCREAMING_SNAKE_CASE      : Dict      ,							__SCREAMING_SNAKE_CASE      : Union[str, Any]=None      ,							__SCREAMING_SNAKE_CASE      : List[Any]=1      ,							__SCREAMING_SNAKE_CASE      : Tuple="binary"      ,							__SCREAMING_SNAKE_CASE      : Any=None      ,							__SCREAMING_SNAKE_CASE      : Tuple="warn"      ,							)						->				List[Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE						     =   precision_score(
          __SCREAMING_SNAKE_CASE      ,							__SCREAMING_SNAKE_CASE      ,							labels=__SCREAMING_SNAKE_CASE      ,							pos_label=__SCREAMING_SNAKE_CASE      ,							average=__SCREAMING_SNAKE_CASE      ,							sample_weight=__SCREAMING_SNAKE_CASE      ,							zero_division=__SCREAMING_SNAKE_CASE      ,							)
      return {"precision": float(__SCREAMING_SNAKE_CASE    ) if score.size == 1 else score}






