§
    ’©º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_squared_error_computeÚ_mean_squared_error_update)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzMeanSquaredError.plotc            	       óÖ   ‡ — e Zd ZU dZdZdZdZdZee	d<   e
e	d<   e
e	d<   	 	 dd	e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 )ÚMeanSquaredErrora`  Compute `mean squared error`_ (MSE).

    .. math:: \text{MSE} = \frac{1}{N}\sum_i^N(y_i - \hat{y_i})^2

    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_squared_error`` (:class:`~torch.Tensor`): A tensor with the mean squared error

    Args:
        squared: If True returns MSE value, if False returns RMSE value.
        num_outputs: Number of outputs in multioutput setting
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example::
        Single output mse computation:

        >>> from torch import tensor
        >>> from torchmetrics.regression import MeanSquaredError
        >>> target = tensor([2.5, 5.0, 4.0, 8.0])
        >>> preds = tensor([3.0, 5.0, 2.5, 7.0])
        >>> mean_squared_error = MeanSquaredError()
        >>> mean_squared_error(preds, target)
        tensor(0.8750)

    Example::
        Multioutput mse computation:

        >>> from torch import tensor
        >>> from torchmetrics.regression import MeanSquaredError
        >>> 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_squared_error = MeanSquaredError(num_outputs=3)
        >>> mean_squared_error(preds, target)
        tensor([1., 4., 9.])

    TFg        Úplot_lower_boundÚsum_squared_errorÚtotalé   ÚsquaredÚnum_outputsÚkwargsÚreturnNc                 óœ  •—  t          ¦   «         j        di |¤Ž t          |t          ¦  «        st	          d|› �¦  «        ‚|| _        t          |t          ¦  «        r|dk    st	          d|› �¦  «        ‚|| _        |                      dt          j
        |¦  «        d¬¦  «         |                      dt          d¦  «        d¬¦  «         d S )	Nz4Expected argument `squared` to be a boolean but got r   z6Expected num_outputs to be a positive integer but got r   Úsum)ÚdefaultÚdist_reduce_fxr   © )ÚsuperÚ__init__Ú
isinstanceÚboolÚ
ValueErrorr   Úintr   Ú	add_stateÚtorchÚzerosr   )Úselfr   r   r   Ú	__class__s       €úk/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/regression/mse.pyr   zMeanSquaredError.__init__R   s×   ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"å˜'¥4Ñ(Ô(ð 	_ÝÐ]ÐT[Ð]Ð]Ñ^Ô^Ð^ØˆŒå˜;­Ñ,Ô,ð 	e°¸q²°ÝÐcÐVaÐcÐcÑdÔdÐdØ&ˆÔà�ŠÐ*µE´KÀÑ4LÔ4LÐ]bˆÑcÔcÐcØ�Š�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MeanSquaredError.updatee   sI   € å%?ÀÀvÐ[_Ô[kÐ%lÑ%lÔ%lÑ"Ð˜7àÐÔÐ"3Ñ3ÐÔØˆ
Œ
�gÑˆ
Œ
ˆ
ˆ
r*   c                 óD   — t          | j        | j        | j        ¬¦  «        S )z&Compute mean squared error over state.)r   )r	   r   r   r   )r'   s    r)   ÚcomputezMeanSquaredError.computel   s    € å*¨4Ô+AÀ4Ä:ÐW[ÔWcÐdÑdÔdÐdr*   Ú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 MeanSquaredError
            >>> metric = MeanSquaredError()
            >>> 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 MeanSquaredError
            >>> metric = MeanSquaredError()
            >>> values = []
            >>> for _ in range(10):
            ...     values.append(metric(randn(10,), randn(10,)))
            >>> fig, ax = metric.plot(values)

        )Ú_plot)r'   r2   r3   s      r)   ÚplotzMeanSquaredError.plotp   s   € ðP �zŠz˜#˜rÑ"Ô"Ð"r*   )Tr   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_differentiableÚhigher_is_betterÚfull_state_updater   ÚfloatÚ__annotations__r   r!   r#   r   r   r/   r1   r   r   r   r   r   r6   Ú__classcell__)r(   s   @r)   r   r      s]  ø€ € € € € € ð*ð *ðX ÐØÐØÐØ!Ð�eÐ!Ð!Ñ!àÐÐÑØ€M€M�Mð ØðIð IàðIð ðIð ð	Ið
 
ðIð Ið Ið Ið Ið Ið&˜Fð ¨Fð °tð ð ð ð ðe˜ð eð eð eð eð
 _cð(#ð (#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð(#ØIQÐRZÔI[ð(#à	ð(#ð (#ð (#ð (#ð (#ð (#ð (#ð (#r*   r   )Úcollections.abcr   Útypingr   r   r   r%   r   r   Ú&torchmetrics.functional.regression.mser	   r
   Útorchmetrics.metricr   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r   r*   r)   ú<module>rH      sû   ðð %Ð $Ð $Ð $Ð $Ð $Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à jÐ jÐ jÐ jÐ jÐ jÐ jÐ jØ &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 1Ø/Ð0Ðð{#ð {#ð {#ð {#ð {#�vñ {#ô {#ð {#ð {#ð {#r*   