Ë
    þÍ: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y)é    )Ú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        ‰| �  di |¤Ž | j                  dt        j                  d«      d¬«       | j                  dt        j                  d«      d¬«       y )Nr   é   Úsum)ÚdefaultÚdist_reduce_fxr   © )ÚsuperÚ__init__Ú	add_stateÚtorchÚzeros)Úselfr   Ú	__class__s     €úq/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torchmetrics/regression/crps.pyr   z)ContinuousRankedProbabilityScore.__init__H   sG   ø€ Ü‰ÑÑ"˜6Ò"Ø�‰�w¬¯©°A«ÀuˆÔMØ�‰�w¬¯©°A«ÀuˆÕMó    ÚpredsÚtargetc                 ó¤   — t        ||«      \  }}}| xj                  t        j                  ||z
  «      z  c_        | xj                  |z  c_        y)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   sA   € ô *6°e¸VÓ)DÑ&ˆ
�D˜,Ø�
Š
”e—i‘i  |Ñ 3Ó4Ñ4�
Ø�
Š
�jÑ Ž
r%   c                 ó4   — | j                   | j                  z  S )z;Compute the continuous ranked probability score over state.)r   r   )r"   s    r$   Úcomputez(ContinuousRankedProbabilityScore.computeY   s   € à�z‰z˜DŸJ™JÑ&Ð&r%   ÚvalÚaxc                 ó&   — | j                  ||«      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      s»   ø… ñ ðD $Ð�tÓ#Ø"Ð�dÓ"Ø#Ð�tÓ#Ø!Ð�eÓ!àƒMØƒMð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      s9   ð÷ 2Ó 1ã Ý å @Ý &Ý @ß @áØ?Ð@Ðôh# võ h#r%   