§
    ’©ºj»  ã                   óœ   — d dl mZ d dlmZmZmZ d dlZd dlmZmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZ esd	gZ G d
„ de¦  «        ZdS )é    )ÚSequence)ÚAnyÚOptionalÚUnionN)ÚTensorÚtensor)Ú_mean_absolute_error_computeÚ_mean_absolute_error_update)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzMeanAbsoluteError.plotc                   óî   ‡ — e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	e
ed<   eed	<   eed
<   	 ddededdfˆ fd„Zdededdfd„Zdefd„Z	 ddeeeee         f                  dee         defd„Zˆ xZS )ÚMeanAbsoluteErrora
  `Compute Mean Absolute Error`_ (MAE).

    .. math:: \text{MAE} = \frac{1}{N}\sum_i^N | y_i - \hat{y_i} |

    Where :math:`y` is a tensor of target values, and :math:`\hat{y}` is a tensor of predictions.

    As input to ``forward`` and ``update`` the metric accepts the following input:

    - ``preds`` (:class:`~torch.Tensor`): Predictions from model
    - ``target`` (:class:`~torch.Tensor`): Ground truth values

    As output of ``forward`` and ``compute`` the metric returns the following output:

    - ``mean_absolute_error`` (:class:`~torch.Tensor`): A tensor with the mean absolute error over the state

    Args:
        num_outputs: Number of outputs in multioutput setting
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> from torch import tensor
        >>> from torchmetrics.regression import MeanAbsoluteError
        >>> target = tensor([3.0, -0.5, 2.0, 7.0])
        >>> preds = tensor([2.5, 0.0, 2.0, 8.0])
        >>> mean_absolute_error = MeanAbsoluteError()
        >>> mean_absolute_error(preds, target)
        tensor(0.5000)

    Example::
        Multioutput mse computation:

        >>> from torch import tensor
        >>> from torchmetrics.regression import MeanAbsoluteError
        >>> target = tensor([[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
        >>> preds = tensor([[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]])
        >>> mean_absolute_error = MeanAbsoluteError(num_outputs=3)
        >>> mean_absolute_error(preds, target)
        tensor([1., 2., 3.])

    TÚis_differentiableFÚhigher_is_betterÚfull_state_updateg        Úplot_lower_boundÚsum_abs_errorÚtotalé   Únum_outputsÚkwargsÚreturnNc                 ó@  •—  t          ¦   «         j        di |¤Ž t          |t          ¦  «        r|dk    st	          d|› �¦  «        ‚|| _        |                      dt          j        |¦  «        d¬¦  «         |                      dt          d¦  «        d¬¦  «         d S )Nr   z6Expected num_outputs to be a positive integer but got r   Úsum)ÚdefaultÚdist_reduce_fxr   © )
ÚsuperÚ__init__Ú
isinstanceÚintÚ
ValueErrorr   Ú	add_stateÚtorchÚzerosr   )Úselfr   r   Ú	__class__s      €úk/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/regression/mae.pyr!   zMeanAbsoluteError.__init__O   s¤   ø€ ð
 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"å˜;­Ñ,Ô,ð 	e°¸q²°ÝÐcÐVaÐcÐcÑdÔdÐdØ&ˆÔà�Š�µ´¸KÑ0HÔ0HÐY^ˆÑ_Ô_Ð_Ø�Š�w­¨q©	¬	À%ˆÑHÔHÐHÐHÐHó    ÚpredsÚtargetc                 óz   — t          ||| j        ¬¦  «        \  }}| xj        |z  c_        | xj        |z  c_        dS )z*Update state with predictions and targets.)r   N)r
   r   r   r   )r(   r,   r-   r   Únum_obss        r*   ÚupdatezMeanAbsoluteError.update]   sG   € å!<¸UÀFÐX\ÔXhÐ!iÑ!iÔ!iÑˆ�wàÐÔ˜mÑ+ÐÔØˆ
Œ
�gÑˆ
Œ
ˆ
ˆ
r+   c                 ó6   — t          | j        | j        ¦  «        S )z'Compute mean absolute error over state.)r	   r   r   )r(   s    r*   ÚcomputezMeanAbsoluteError.computed   s   € å+¨DÔ,>ÀÄ
ÑKÔKÐKr+   ÚvalÚ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

            >>> from torch import randn
            >>> # Example plotting a single value
            >>> from torchmetrics.regression import MeanAbsoluteError
            >>> metric = MeanAbsoluteError()
            >>> metric.update(randn(10,), randn(10,))
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> from torch import randn
            >>> # Example plotting multiple values
            >>> from torchmetrics.regression import MeanAbsoluteError
            >>> metric = MeanAbsoluteError()
            >>> values = []
            >>> for _ in range(10):
            ...     values.append(metric(randn(10,), randn(10,)))
            >>> fig, ax = metric.plot(values)

        )Ú_plot)r(   r3   r4   s      r*   ÚplotzMeanAbsoluteError.ploth   s   € ðP �zŠz˜#˜rÑ"Ô"Ð"r+   )r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   Úfloatr   r#   r   r!   r0   r2   r   r   r   r   r   r7   Ú__classcell__)r)   s   @r*   r   r      sp  ø€ € € € € € ð'ð 'ðR #Ð�tÐ"Ð"Ñ"Ø"Ð�dÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!àÐÐÑØ€M€M�Mð ðIð IàðIð ðIð 
ð	Ið Ið Ið Ið Ið Ið˜Fð ¨Fð °tð ð ð ð ðL˜ð Lð Lð Lð Lð
 _cð(#ð (#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð(#ØIQÐRZÔI[ð(#à	ð(#ð (#ð (#ð (#ð (#ð (#ð (#ð (#r+   r   )Úcollections.abcr   Útypingr   r   r   r&   r   r   Ú&torchmetrics.functional.regression.maer	   r
   Útorchmetrics.metricr   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r   r+   r*   ú<module>rG      sû   ðð %Ð $Ð $Ð $Ð $Ð $Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à lÐ lÐ lÐ lÐ lÐ lÐ lÐ lØ &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 2Ø0Ð1Ððs#ð s#ð s#ð s#ð s#˜ñ s#ô s#ð s#ð s#ð s#r+   