§
    ’©º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 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)Úfowlkes_mallows_index)ÚMetric)Údim_zero_cat)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzFowlkesMallowsIndex.plotc                   ó  ‡ — e Zd ZU dZdZeed<   dZe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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         df         dee         defd„Zˆ xZS )ÚFowlkesMallowsIndexa€  Compute `Fowlkes-Mallows Index`_.

    .. math::
        FMI(U,V) = \frac{TP}{\sqrt{(TP + FP) * (TP + FN)}}

    Where :math:`TP` is the number of true positives, :math:`FP` is the number of false positives, and :math:`FN` is
    the number of false negatives.

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

    - ``preds`` (:class:`~torch.Tensor`): single integer tensor with shape ``(N,)`` with predicted cluster labels
    - ``target`` (:class:`~torch.Tensor`): single integer tensor with shape ``(N,)`` with ground truth cluster labels

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

    - ``fmi`` (:class:`~torch.Tensor`): A tensor with the Fowlkes-Mallows index.

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

    Example::
        >>> import torch
        >>> from torchmetrics.clustering import FowlkesMallowsIndex
        >>> preds = torch.tensor([2, 2, 0, 1, 0])
        >>> target = torch.tensor([2, 2, 1, 1, 0])
        >>> fmi = FowlkesMallowsIndex()
        >>> fmi(preds, target)
        tensor(0.5000)

    TÚis_differentiableÚhigher_is_betterFÚfull_state_updateg        Úplot_lower_boundg      ð?Úplot_upper_boundÚpredsÚtargetÚkwargsÚreturnNc                 óš   •—  t          ¦   «         j        di |¤Ž |                      dg d¬¦  «         |                      dg d¬¦  «         d S )Nr   Úcat)ÚdefaultÚdist_reduce_fxr   © )ÚsuperÚ__init__Ú	add_state)Úselfr   Ú	__class__s     €ú}/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/clustering/fowlkes_mallows_index.pyr    zFowlkesMallowsIndex.__init__E   sV   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"à�Š�w¨¸5ˆÑAÔAÐAØ�Š�x¨¸EˆÑBÔBÐBÐBÐBó    c                 ón   — | j                              |¦  «         | j                             |¦  «         dS )z*Update state with predictions and targets.N)r   Úappendr   )r"   r   r   s      r$   ÚupdatezFowlkesMallowsIndex.updateK   s4   € àŒ
×Ò˜%Ñ Ô Ð ØŒ×Ò˜6Ñ"Ô"Ð"Ð"Ð"r%   c                 ój   — t          t          | j        ¦  «        t          | j        ¦  «        ¦  «        S )z)Compute Fowlkes-Mallows index over state.)r	   r   r   r   )r"   s    r$   ÚcomputezFowlkesMallowsIndex.computeP   s&   € å$¥\°$´*Ñ%=Ô%=½|ÈDÌKÑ?XÔ?XÑYÔYÐYr%   ÚvalÚaxc                 ó.   — |                       ||¦  «        S )aX  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
            >>> import torch
            >>> from torchmetrics.clustering import FowlkesMallowsIndex
            >>> metric = FowlkesMallowsIndex()
            >>> metric.update(torch.randint(0, 4, (10,)), torch.randint(0, 4, (10,)))
            >>> fig_, ax_ = metric.plot(metric.compute())

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> import torch
            >>> from torchmetrics.clustering import FowlkesMallowsIndex
            >>> metric = FowlkesMallowsIndex()
            >>> values = [ ]
            >>> for _ in range(10):
            ...     values.append(metric(torch.randint(0, 4, (10,)), torch.randint(0, 4, (10,))))
            >>> fig_, ax_ = metric.plot(values)

        )Ú_plot)r"   r+   r,   s      r$   ÚplotzFowlkesMallowsIndex.plotT   s   € ðL �zŠz˜#˜rÑ"Ô"Ð"r%   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚboolÚ__annotations__r   r   r   r   Úfloatr   r   r   r   r    r(   r*   r   r   r   r   r/   Ú__classcell__)r#   s   @r$   r   r      si  ø€ € € € € € ðð ð> #Ð�tÐ"Ð"Ñ"Ø'+Ð�h˜t”nÐ+Ð+Ñ+Ø#Ð�tÐ#Ð#Ñ#Ø!Ð�eÐ!Ð!Ñ!Ø!Ð�eÐ!Ð!Ñ!Ø�Œ<ÐÐÑØ�ŒLÐÐÑðC ð C¨ð Cð Cð Cð Cð Cð Cð#˜Fð #¨Fð #°tð #ð #ð #ð #ð
Z˜ð Zð Zð Zð Zð&#ð &#˜˜f h¨vÔ&6¸Ð<Ô=ð &#È(ÐS[ÔJ\ð &#Ðhvð &#ð &#ð &#ð &#ð &#ð &#ð &#ð &#r%   r   N)Úcollections.abcr   Útypingr   r   r   r   Útorchr   Ú"torchmetrics.functional.clusteringr	   Útorchmetrics.metricr
   Útorchmetrics.utilities.datar   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r   r%   r$   ú<module>rA      sþ   ðð %Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -à Ð Ð Ð Ð Ð à DÐ DÐ DÐ DÐ DÐ DØ &Ð &Ð &Ð &Ð &Ð &Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 4Ø2Ð3Ðð]#ð ]#ð ]#ð ]#ð ]#˜&ñ ]#ô ]#ð ]#ð ]#ð ]#r%   