§
    ’©ºj`  ã                   ó¸   — d dl mZ d dlmZmZ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 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ÚListÚOptionalÚUnion)ÚTensor)ÚLiteral)Ú_ergas_computeÚ_ergas_update)ÚMetric)Úrank_zero_warn)Údim_zero_cat)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEz.ErrorRelativeGlobalDimensionlessSynthesis.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         ed	<   ee         ed
<   	 	 dde
d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 )Ú)ErrorRelativeGlobalDimensionlessSynthesisaš  Calculate the `Error relative global dimensionless synthesis`_  (ERGAS) metric.

    This metric is used to calculate the accuracy of Pan sharpened image considering normalized average error of each
    band of the result image. It is defined as:

    .. math::
        ERGAS = \frac{100}{r} \cdot \sqrt{\frac{1}{N} \sum_{k=1}^{N} \frac{RMSE(B_k)^2}{\mu_k^2}}

    where :math:`r=h/l` denote the ratio in spatial resolution (pixel size) between the high and low resolution images.
    :math:`N` is the number of spectral bands, :math:`RMSE(B_k)` is the root mean square error of the k-th band between
    low and high resolution images, and :math:`\\mu_k` is the mean value of the k-th band of the reference image.

    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

    - ``ergas`` (:class:`~torch.Tensor`): if ``reduction!='none'`` returns float scalar tensor with average ERGAS
      value over sample else returns tensor of shape ``(N,)`` with ERGAS values per sample

    Args:
        ratio: ratio of high resolution to low resolution.
        reduction: a method to reduce metric score over labels.

            - ``'elementwise_mean'``: takes the mean (default)
            - ``'sum'``: takes the sum
            - ``'none'`` or ``None``: no reduction will be applied

        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Example:
        >>> from torch import rand
        >>> from torchmetrics.image import ErrorRelativeGlobalDimensionlessSynthesis
        >>> preds = rand([16, 1, 16, 16])
        >>> target = preds * 0.75
        >>> ergas = ErrorRelativeGlobalDimensionlessSynthesis()
        >>> ergas(preds, target).round()
        tensor(10.)

    FÚhigher_is_betterTÚis_differentiableÚfull_state_updateg        Úplot_lower_boundÚpredsÚtargeté   Úelementwise_meanÚratioÚ	reduction)r   ÚsumÚnoneNÚkwargsÚreturnNc                 óÔ   •—  t          ¦   «         j        di |¤Ž t          d¦  «         |                      dg d¬¦  «         |                      dg d¬¦  «         || _        || _        d S )Nz�Metric `UniversalImageQualityIndex` will save all targets and predictions in buffer. For large datasets this may lead to large memory footprint.r   Úcat)ÚdefaultÚdist_reduce_fxr   © )ÚsuperÚ__init__r   Ú	add_stater   r   )Úselfr   r   r    Ú	__class__s       €úh/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/image/ergas.pyr(   z2ErrorRelativeGlobalDimensionlessSynthesis.__init__T   s}   ø€ ð 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ýð*ñ	
ô 	
ð 	
ð 	�Š�w¨¸5ˆÑAÔAÐAØ�Š�x¨¸EˆÑBÔBÐBØˆŒ
Ø"ˆŒˆˆó    c                 ó”   — t          ||¦  «        \  }}| j                             |¦  «         | j                             |¦  «         dS )z*Update state with predictions and targets.N)r   r   Úappendr   ©r*   r   r   s      r,   Úupdatez0ErrorRelativeGlobalDimensionlessSynthesis.updatef   sG   € å% e¨VÑ4Ô4‰ˆˆvØŒ
×Ò˜%Ñ Ô Ð ØŒ×Ò˜6Ñ"Ô"Ð"Ð"Ð"r-   c                 óŠ   — t          | j        ¦  «        }t          | j        ¦  «        }t          ||| j        | j        ¦  «        S )z&Compute explained variance over state.)r   r   r   r
   r   r   r0   s      r,   Úcomputez1ErrorRelativeGlobalDimensionlessSynthesis.computel   s8   € å˜TœZÑ(Ô(ˆÝ˜dœkÑ*Ô*ˆÝ˜e V¨T¬Z¸¼ÑHÔHÐHr-   Ú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

            >>> # Example plotting a single value
            >>> from torch import rand
            >>> from torchmetrics.image import ErrorRelativeGlobalDimensionlessSynthesis
            >>> preds = rand([16, 1, 16, 16])
            >>> target = preds * 0.75
            >>> metric = ErrorRelativeGlobalDimensionlessSynthesis()
            >>> metric.update(preds, target)
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> from torch import rand
            >>> from torchmetrics.image import ErrorRelativeGlobalDimensionlessSynthesis
            >>> preds = rand([16, 1, 16, 16])
            >>> target = preds * 0.75
            >>> metric = ErrorRelativeGlobalDimensionlessSynthesis()
            >>> values = [ ]
            >>> for _ in range(10):
            ...     values.append(metric(preds, target))
            >>> fig_, ax_ = metric.plot(values)

        )Ú_plot)r*   r4   r5   s      r,   Úplotz.ErrorRelativeGlobalDimensionlessSynthesis.plotr   s   € ðX �zŠz˜#˜rÑ"Ô"Ð"r-   )r   r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   Úfloatr   r   r	   r   r(   r1   r3   r   r   r   r   r   r8   Ú__classcell__)r+   s   @r,   r   r       s„  ø€ € € € € € ð)ð )ðV #Ð�dÐ"Ð"Ñ"Ø"Ð�tÐ"Ð"Ñ"Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!à�Œ<ÐÐÑØ�ŒLÐÐÑð ØFXð#ð #àð#ð ÐBÔCð#ð ð	#ð
 
ð#ð #ð #ð #ð #ð #ð$#˜Fð #¨Fð #°tð #ð #ð #ð #ðI˜ð Ið Ið Ið Ið _cð,#ð ,#Ø˜E &¨(°6Ô*:Ð":Ô;Ô<ð,#ØIQÐRZÔI[ð,#à	ð,#ð ,#ð ,#ð ,#ð ,#ð ,#ð ,#ð ,#r-   r   N)Úcollections.abcr   Útypingr   r   r   r   Útorchr   Útyping_extensionsr	   Ú#torchmetrics.functional.image.ergasr
   r   Útorchmetrics.metricr   Útorchmetrics.utilitiesr   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r&   r-   r,   ú<module>rL      s)  ðð %Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ &Ð &Ð &Ð &Ð &Ð &Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð JØHÐIÐð~#ð ~#ð ~#ð ~#ð ~#°ñ ~#ô ~#ð ~#ð ~#ð ~#r-   