§
    ’©ºjÑ  ã                   óŒ   — d dl 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 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)ÚOptionalÚUnion)ÚTensor)Ú_concordance_corrcoef_compute)ÚPearsonCorrCoefÚ_final_aggregation)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzConcordanceCorrCoef.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<   dZe
ed	<   d
efd„Z	 ddeeeee         f                  dee         d
efd„ZdS )ÚConcordanceCorrCoefa�  Compute concordance correlation coefficient that measures the agreement between two variables.

    .. math::
        \rho_c = \frac{2 \rho \sigma_x \sigma_y}{\sigma_x^2 + \sigma_y^2 + (\mu_x - \mu_y)^2}

    where :math:`\mu_x, \mu_y` is the means for the two variables, :math:`\sigma_x^2, \sigma_y^2` are the corresponding
    variances and \rho is the pearson correlation coefficient between the two variables.

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

    - ``preds`` (:class:`~torch.Tensor`): either single output float tensor with shape ``(N,)`` or multioutput
      float tensor of shape ``(N,d)``
    - ``target`` (:class:`~torch.Tensor`): either single output float tensor with shape ``(N,)`` or multioutput
      float tensor of shape ``(N,d)``

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

    - ``concordance`` (:class:`~torch.Tensor`): A scalar float tensor with the concordance coefficient(s) for
      non-multioutput input or a float tensor with shape ``(d,)`` for multioutput input

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

    Example (single output regression):
        >>> from torchmetrics.regression import ConcordanceCorrCoef
        >>> from torch import tensor
        >>> target = tensor([3, -0.5, 2, 7])
        >>> preds = tensor([2.5, 0.0, 2, 8])
        >>> concordance = ConcordanceCorrCoef()
        >>> concordance(preds, target)
        tensor(0.9777)

    Example (multi output regression):
        >>> from torchmetrics.regression import ConcordanceCorrCoef
        >>> target = tensor([[3, -0.5], [2, 7]])
        >>> preds = tensor([[2.5, 0.0], [2, 8]])
        >>> concordance = ConcordanceCorrCoef(num_outputs=2)
        >>> concordance(preds, target)
        tensor([0.7273, 0.9887])

    TÚis_differentiableÚhigher_is_betterÚfull_state_updateg      ð¿Úplot_lower_boundg      ð?Úplot_upper_boundÚreturnc           
      ó¶  — | j         dk    r| j                             ¦   «         dk    s| j         dk    rY| j        j        dk    rIt	          | j        | j        | j        | j        | j        | j	        | j
        | j        ¬¦  «        \  }}}}}}}}n8| j        }| j        }| j        }| j        }| j        }| j	        }| j
        }| j        }t          ||||||||¦  «        S )zECompute final concordance correlation coefficient over metric states.é   )Úmeans_xÚmeans_yÚ
maxs_abs_xÚ
maxs_abs_yÚvars_xÚvars_yÚcorrs_xyÚnbs)Únum_outputsÚmean_xÚnumelÚndimr	   Úmean_yÚmax_abs_dev_xÚmax_abs_dev_yÚvar_xÚvar_yÚcorr_xyÚn_totalr   )	Úselfr    r#   r$   r%   r&   r'   r(   r)   s	            ús/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/regression/concordance.pyÚcomputezConcordanceCorrCoef.computeO   sþ   € àÔ Ò!Ð! d¤k×&7Ò&7Ñ&9Ô&9¸AÒ&=Ð&=À4ÔCSÐVWÒCWÐCWÐ\`Ô\gÔ\lÐopÒ\pÐ\pÝ[mØœØœØÔ-ØÔ-Ø”zØ”zØœØ”Lð	\ñ 	\ô 	\ÑXˆF�F˜M¨=¸%ÀÈÐQXÐQXð ”[ˆFØ”[ˆFØ Ô.ˆMØ Ô.ˆMØ”JˆEØ”JˆEØ”lˆGØ”lˆGÝ,Ø˜=¨&°&¸%ÀÈÐQXñ
ô 
ð 	
ó    NÚ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 ConcordanceCorrCoef
            >>> metric = ConcordanceCorrCoef()
            >>> 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 ConcordanceCorrCoef
            >>> metric = ConcordanceCorrCoef()
            >>> values = []
            >>> for _ in range(10):
            ...     values.append(metric(randn(10,), randn(10,)))
            >>> fig, ax = metric.plot(values)

        )Ú_plot)r*   r.   r/   s      r+   ÚplotzConcordanceCorrCoef.ploti   s   € ðP �zŠz˜#˜rÑ"Ô"Ð"r-   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   Úfloatr   r   r,   r   r   r   r   r   r2   © r-   r+   r   r      så   € € € € € € ð)ð )ðV #Ð�tÐ"Ð"Ñ"Ø!Ð�dÐ!Ð!Ñ!Ø"Ð�tÐ"Ð"Ñ"à"Ð�eÐ"Ð"Ñ"Ø!Ð�eÐ!Ð!Ñ!ð
˜ð 
ð 
ð 
ð 
ð6 _cð(#ð (#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð(#ØIQÐRZÔI[ð(#à	ð(#ð (#ð (#ð (#ð (#ð (#r-   r   N)Úcollections.abcr   Útypingr   r   Útorchr   Ú.torchmetrics.functional.regression.concordancer   Útorchmetrics.regression.pearsonr   r	   Útorchmetrics.utilities.importsr
   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r:   r-   r+   ú<module>rC      sæ   ðð %Ð $Ð $Ð $Ð $Ð $Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð à XÐ XÐ XÐ XÐ XÐ XØ OÐ OÐ OÐ OÐ OÐ OÐ OÐ OØ @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 4Ø2Ð3Ððu#ð u#ð u#ð u#ð u#˜/ñ u#ô u#ð u#ð u#ð u#r-   