Ë
    þÍ: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y)é    )Ú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        ‰| �  di |¤Ž t        |t        «      r|dkD  st	        d|› �«      ‚|| _        | j                  dt        j                  |«      d¬«       | j                  dt        d«      d¬«       y )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      €úp/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torchmetrics/regression/mae.pyr    zMeanAbsoluteError.__init__O   st   ø€ ô
 	‰ÑÑ"˜6Ò"ä˜;¬Ô,°¸q²ÜÐUÐVaÐUbÐcÓdÐdØ&ˆÔà�‰�´·±¸KÓ0HÐY^ˆÔ_Ø�‰�w¬¨q«	À%ˆÕHó    ÚpredsÚtargetc                 óŽ   — t        ||| j                  ¬«      \  }}| xj                  |z  c_        | xj                  |z  c_        y)z*Update state with predictions and targets.)r   N)r
   r   r   r   )r'   r+   r,   r   Únum_obss        r)   ÚupdatezMeanAbsoluteError.update]   s;   € ä!<¸UÀFÐX\×XhÑXhÔ!iÑˆ�wà×Ò˜mÑ+ÕØ�
Š
�gÑŽ
r*   c                 óB   — t        | j                  | j                  «      S )z'Compute mean absolute error over state.)r	   r   r   )r'   s    r)   ÚcomputezMeanAbsoluteError.computed   s   € ä+¨D×,>Ñ,>ÀÇ
Á
ÓKÐKr*   ÚvalÚaxc                 ó&   — | j                  ||«      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'   r2   r3   s      r)   ÚplotzMeanAbsoluteError.ploth   s   € ðP �z‰z˜#˜rÓ"Ð"r*   )é   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   Úfloatr   r"   r   r    r/   r1   r   r   r   r   r   r6   Ú__classcell__)r(   s   @r)   r   r      sÒ   ø… ñ'ðR #Ð�tÓ"Ø"Ð�dÓ"Ø#Ð�tÓ#Ø!Ð�eÓ!àÓØƒMð ñIàðIð ðIð 
õ	Ið˜Fð ¨Fð °tó ð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Ý &Ý @ß @áØ0Ð1Ðôs#˜õ s#r*   