§
    ’©ºjè  ã                   óŒ   — d dl mZ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 d dlmZmZ esdgZ G d	„ d
e
¦  «        ZdS )é    )ÚAnyÚOptionalÚSequenceÚUnionN)ÚTensor)Ú_crps_update)ÚMetric)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEz%ContinuousRankedProbabilityScore.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
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 )Ú ContinuousRankedProbabilityScorea  Computes continuous ranked probability score.

    .. math::
        CRPS(F, y) = \int_{-\infty}^{\infty} (F(x) - 1_{x \geq y})^2 dx

    where :math:`F` is the predicted cumulative distribution function and :math:`y` is the true target. The metric is
    usually used to evaluate probabilistic regression models, such as forecasting models. A lower CRPS indicates a
    better forecast, meaning that forecasted probabilities are closer to the true observed values. CRPS can also be
    seen as a generalization of the brier score for non binary classification problems.

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

    - ``preds`` (:class:`~torch.Tensor`): Predicted float tensor with shape ``(N,d)``
    - ``target`` (:class:`~torch.Tensor`): Ground truth float tensor with shape ``(N,d)``

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

    - ``cosine_similarity`` (:class:`~torch.Tensor`): A float tensor with the cosine similarity

    Args:
        reduction: how to reduce over the batch dimension using 'sum', 'mean' or 'none' (taking the individual scores)
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> from torch import randn
        >>> from torchmetrics.regression import ContinuousRankedProbabilityScore
        >>> preds = randn(10, 5)
        >>> target = randn(10)
        >>> crps = ContinuousRankedProbabilityScore()
        >>> crps(preds, target)
        tensor(0.7731)

    FÚis_differentiableÚhigher_is_betterÚfull_state_updateg        Úplot_lower_boundÚscoreÚtotalÚkwargsÚreturnNc                 óâ   •—  t          ¦   «         j        di |¤Ž |                      dt          j        d¦  «        d¬¦  «         |                      dt          j        d¦  «        d¬¦  «         d S )Nr   é   Úsum)ÚdefaultÚdist_reduce_fxr   © )ÚsuperÚ__init__Ú	add_stateÚtorchÚzeros)Úselfr   Ú	__class__s     €úl/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/regression/crps.pyr   z)ContinuousRankedProbabilityScore.__init__H   sf   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ø�Š�w­¬°A©¬ÀuˆÑMÔMÐMØ�Š�w­¬°A©¬ÀuˆÑMÔMÐMÐMÐMó    ÚpredsÚtargetc                 ó˜   — t          ||¦  «        \  }}}| xj        t          j        ||z
  ¦  «        z  c_        | xj        |z  c_        dS )z•Update state with predictions and targets.

        Args:
            preds: Predictions from model
            target: Ground truth values

        N)r   r   r    r   r   )r"   r&   r'   Ú
batch_sizeÚdiffÚensemble_sums         r$   Úupdatez'ContinuousRankedProbabilityScore.updateM   sM   € õ *6°e¸VÑ)DÔ)DÑ&ˆ
�D˜,Øˆ
Œ
•e”i  |Ñ 3Ñ4Ô4Ñ4ˆ
Œ
Øˆ
Œ
�jÑ ˆ
Œ
ˆ
ˆ
r%   c                 ó    — | j         | j        z  S )z;Compute the continuous ranked probability score over state.)r   r   )r"   s    r$   Úcomputez(ContinuousRankedProbabilityScore.computeY   s   € àŒz˜DœJÑ&Ð&r%   ÚvalÚaxc                 ó.   — |                       ||¦  «        S )aO  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 ContinuousRankedProbabilityScore
            >>> metric = ContinuousRankedProbabilityScore()
            >>> metric.update(randn(10,5), randn(10))
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

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

        )Ú_plot)r"   r/   r0   s      r$   Úplotz%ContinuousRankedProbabilityScore.plot]   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   r   r   r3   Ú__classcell__)r#   s   @r$   r   r      sN  ø€ € € € € € ð ð  ðD $Ð�tÐ#Ð#Ñ#Ø"Ð�dÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!à€M€M�MØ€M€M�MðN ð N¨ð Nð Nð Nð Nð Nð Nð

!˜Fð 
!¨Fð 
!°tð 
!ð 
!ð 
!ð 
!ð'˜ð 'ð 'ð 'ð 'ð
 _cð(#ð (#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð(#ØIQÐRZÔI[ð(#à	ð(#ð (#ð (#ð (#ð (#ð (#ð (#ð (#r%   r   )Útypingr   r   r   r   r    r   Ú'torchmetrics.functional.regression.crpsr   Útorchmetrics.metricr	   Útorchmetrics.utilities.importsr
   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r   r%   r$   ú<module>rB      sä   ðð 2Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1à €€€Ø Ð Ð Ð Ð Ð à @Ð @Ð @Ð @Ð @Ð @Ø &Ð &Ð &Ð &Ð &Ð &Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð AØ?Ð@Ððh#ð h#ð h#ð h#ð h# vñ h#ô h#ð h#ð h#ð h#r%   