§
    ’©ºjv  ã                   ó”   — d dl mZ d dlmZmZmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZmZ d dlmZ esd	gZ G d
„ de¦  «        ZdS )é    )ÚSequence)ÚAnyÚOptionalÚUnionN)ÚTensor)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPE)ÚWrapperMetriczMinMaxMetric.plotc                   ó0  ‡ — e Zd ZU dZdZee         ed<   eed<   eed<   de	de
dd	fˆ fd
„Zde
de
dd	fd„Zdeeef         fd„Zde
de
de
fˆ fd„Zdˆ fd„Zedeeef         defd„¦   «         Z	 ddeeeee         f                  dee         defd„Zˆ xZS )ÚMinMaxMetricak  Wrapper metric that tracks both the minimum and maximum of a scalar/tensor across an experiment.

    The min/max value will be updated each time ``.compute`` is called.

    Args:
        base_metric:
            The metric of which you want to keep track of its maximum and minimum values.
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError
            If ``base_metric` argument is not a subclasses instance of ``torchmetrics.Metric``

    Example::
        >>> import torch
        >>> from torchmetrics.wrappers import MinMaxMetric
        >>> from torchmetrics.classification import BinaryAccuracy
        >>> from pprint import pprint
        >>> base_metric = BinaryAccuracy()
        >>> minmax_metric = MinMaxMetric(base_metric)
        >>> preds_1 = torch.Tensor([[0.1, 0.9], [0.2, 0.8]])
        >>> preds_2 = torch.Tensor([[0.9, 0.1], [0.2, 0.8]])
        >>> labels = torch.Tensor([[0, 1], [0, 1]]).long()
        >>> pprint(minmax_metric(preds_1, labels))
        {'max': tensor(1.), 'min': tensor(1.), 'raw': tensor(1.)}
        >>> pprint(minmax_metric.compute())
        {'max': tensor(1.), 'min': tensor(1.), 'raw': tensor(1.)}
        >>> minmax_metric.update(preds_2, labels)
        >>> pprint(minmax_metric.compute())
        {'max': tensor(1.), 'min': tensor(0.7500), 'raw': tensor(0.7500)}

    TÚfull_state_updateÚmin_valÚmax_valÚbase_metricÚkwargsÚreturnNc                 ó.  •—  t          ¦   «         j        di |¤Ž t          |t          ¦  «        st	          d|› �¦  «        ‚|| _        t          j        t          d¦  «        ¦  «        | _	        t          j        t          d¦  «        ¦  «        | _
        d S )NzMExpected base metric to be an instance of `torchmetrics.Metric` but received Úinfz-inf© )ÚsuperÚ__init__Ú
isinstancer   Ú
ValueErrorÚ_base_metricÚtorchÚtensorÚfloatr   r   )Úselfr   r   Ú	__class__s      €úl/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/wrappers/minmax.pyr   zMinMaxMetric.__init__D   sŽ   ø€ ð
 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ý˜+¥vÑ.Ô.ð 	ÝØmÐ`kÐmÐmñô ð ð (ˆÔÝ”|¥E¨%¡L¤LÑ1Ô1ˆŒÝ”|¥E¨&¡M¤MÑ2Ô2ˆŒˆˆó    Úargsc                 ó*   —  | j         j        |i |¤Ž dS )zUpdate the underlying metric.N)r   Úupdate)r    r$   r   s      r"   r&   zMinMaxMetric.updateR   s#   € à ˆÔÔ  $Ð1¨&Ð1Ð1Ð1Ð1Ð1r#   c                 óÈ  — | j                              ¦   «         }|                      |¦  «        st          d|› d�¦  «        ‚| j                             |j        ¦  «        |k     r|n| j                             |j        ¦  «        | _        | j                             |j        ¦  «        |k    r|n| j                             |j        ¦  «        | _        || j        | j        dœS )zêCompute the underlying metric as well as max and min values for this metric.

        Returns a dictionary that consists of the computed value (``raw``), as well as the minimum (``min``) and maximum
        (``max``) values.

        zLReturned value from base metric should be a float or scalar tensor, but got ú.)ÚrawÚmaxÚmin)r   ÚcomputeÚ_is_suitable_valÚRuntimeErrorr   ÚtoÚdevicer   )r    Úvals     r"   r,   zMinMaxMetric.computeV   sÌ   € ð Ô×'Ò'Ñ)Ô)ˆØ×$Ò$ SÑ)Ô)ð 	vÝÐtÐnqÐtÐtÐtÑuÔuÐuØ"œlŸošo¨c¬jÑ9Ô9¸CÒ?Ð?�s�sÀTÄ\Ç_Â_ÐUXÔU_ÑE`ÔE`ˆŒØ"œlŸošo¨c¬jÑ9Ô9¸CÒ?Ð?�s�sÀTÄ\Ç_Â_ÐUXÔU_ÑE`ÔE`ˆŒØ 4¤<¸¼ÐEÐEÐEr#   c                 óD   •—  t          t          | ¦  «        j        |i |¤ŽS )z9Use the original forward method of the base metric class.)r   r   Úforward)r    r$   r   r!   s      €r"   r3   zMinMaxMetric.forwardd   s%   ø€ à1�u•] DÑ)Ô)Ô1°4ÐB¸6ÐBÐBÐBr#   c                 óz   •— t          ¦   «                              ¦   «          | j                             ¦   «          dS )zXSet ``max_val`` and ``min_val`` to the initialization bounds and resets the base metric.N)r   Úresetr   )r    r!   s    €r"   r5   zMinMaxMetric.reseth   s/   ø€ å‰Œ�Š‰ŒˆØÔ×ÒÑ!Ô!Ð!Ð!Ð!r#   r1   c                 óœ   — t          | t          t          f¦  «        rdS t          | t          ¦  «        r|                      ¦   «         dk    S dS )z(Check whether min/max is a scalar value.Té   F)r   Úintr   r   Únumel)r1   s    r"   r-   zMinMaxMetric._is_suitable_valm   sI   € õ �c�C¥˜<Ñ(Ô(ð 	Ø�4Ý�c�6Ñ"Ô"ð 	$Ø—9’9‘;”; !Ò#Ð#Øˆur#   Úaxc                 ó.   — |                       ||¦  «        S )aÉ  Plot a single or multiple values from the metric.

        Args:
            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
                If no value is provided, will automatically call `metric.compute` and plot that result.
            ax: An matplotlib axis object. If provided will add plot to that axis

        Returns:
            Figure and Axes object

        Raises:
            ModuleNotFoundError:
                If `matplotlib` is not installed

        .. plot::
            :scale: 75

            >>> # Example plotting a single value
            >>> import torch
            >>> from torchmetrics.wrappers import MinMaxMetric
            >>> from torchmetrics.classification import BinaryAccuracy
            >>> metric = MinMaxMetric(BinaryAccuracy())
            >>> metric.update(torch.randint(2, (20,)), torch.randint(2, (20,)))
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> import torch
            >>> from torchmetrics.wrappers import MinMaxMetric
            >>> from torchmetrics.classification import BinaryAccuracy
            >>> metric = MinMaxMetric(BinaryAccuracy())
            >>> values = [ ]
            >>> for _ in range(3):
            ...     values.append(metric(torch.randint(2, (20,)), torch.randint(2, (20,))))
            >>> fig_, ax_ = metric.plot(values)

        )Ú_plot)r    r1   r:   s      r"   ÚplotzMinMaxMetric.plotv   s   € ðT �zŠz˜#˜rÑ"Ô"Ð"r#   )r   N)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚboolÚ__annotations__r   r   r   r   r&   ÚdictÚstrr,   r3   r5   Ústaticmethodr   r   r-   r   r
   r   r=   Ú__classcell__)r!   s   @r"   r   r      sÄ  ø€ € € € € € ðð ðB )-Ð�x ”~Ð,Ð,Ñ,Ø€O€O�OØ€O€O�Oð3àð3ð ð3ð 
ð	3ð 3ð 3ð 3ð 3ð 3ð2˜Cð 2¨3ð 2°4ð 2ð 2ð 2ð 2ðF˜˜c 6˜kÔ*ð Fð Fð Fð FðC˜Sð C¨Cð C°Cð Cð Cð Cð Cð Cð Cð"ð "ð "ð "ð "ð "ð
 ð˜e E¨6 MÔ2ð °tð ð ð ñ „\ðð _cð*#ð *#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð*#ØIQÐRZÔI[ð*#à	ð*#ð *#ð *#ð *#ð *#ð *#ð *#ð *#r#   r   )Úcollections.abcr   Útypingr   r   r   r   r   Útorchmetrics.metricr   Útorchmetrics.utilities.importsr	   Útorchmetrics.utilities.plotr
   r   Útorchmetrics.wrappers.abstractr   Ú__doctest_skip__r   r   r#   r"   ú<module>rO      sï   ðð %Ð $Ð $Ð $Ð $Ð $Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à €€€Ø Ð Ð Ð Ð Ð à &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8àð -Ø+Ð,ÐðB#ð B#ð B#ð B#ð B#�=ñ B#ô B#ð B#ð B#ð B#r#   