§
    ’©ºj­	  ã                   óz   — d dl Z d dl mZmZ d dlmZmZ dededeeef         fd„Zded	edefd
„Z	dededefd„Z
dS )é    N)ÚTensorÚtensor)Úcalculate_contingency_matrixÚcheck_cluster_labelsÚpredsÚtargetÚreturnc                 ól   — t          | |¦  «         t          | |¦  «        |                      d¦  «        fS )zßReturn contingency matrix required to compute the Fowlkes-Mallows index.

    Args:
        preds: predicted class labels
        target: ground truth class labels

    Returns:
        contingency: contingency matrix

    r   )r   r   Úsize)r   r   s     úˆ/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/clustering/fowlkes_mallows_index.pyÚ_fowlkes_mallows_index_updater      s3   € õ ˜ Ñ'Ô'Ð'Ý'¨¨vÑ6Ô6¸¿
º
À1¹¼ÐEÐEó    ÚcontingencyÚnc                 óÆ  — t          j        | dz  ¦  «        |z
  }t          j        |t          d¦  «        ¦  «        rt          j        d| j        ¬¦  «        S t          j        |                      d¬¦  «        dz  ¦  «        |z
  }t          j        |                      d¬¦  «        dz  ¦  «        |z
  }t          j        ||z  ¦  «        t          j        ||z  ¦  «        z  S )zÕCompute the Fowlkes-Mallows index based on the contingency matrix.

    Args:
        contingency: contingency matrix
        n: number of samples

    Returns:
        fowlkes_mallows: Fowlkes-Mallows index

    é   r   g        )Údevice)Údimé   )ÚtorchÚsumÚallcloser   r   Úsqrt)r   r   ÚtkÚpkÚqks        r   Ú_fowlkes_mallows_index_computer   $   sÃ   € õ 
Œ�; ‘>Ñ	"Ô	" QÑ	&€BÝ„~�b�& ™)œ)Ñ$Ô$ð <ÝŒ|˜C¨Ô(:Ð;Ñ;Ô;Ð;å	Œ�;—?’? q�?Ñ)Ô)¨QÑ.Ñ	/Ô	/°!Ñ	3€BÝ	Œ�;—?’? q�?Ñ)Ô)¨QÑ.Ñ	/Ô	/°!Ñ	3€BåŒ:�b˜2‘gÑÔ¥¤¨B°©GÑ!4Ô!4Ñ4Ð4r   c                 óH   — t          | |¦  «        \  }}t          ||¦  «        S )aÿ  Compute Fowlkes-Mallows index between two clusterings.

    Args:
        preds: predicted cluster labels
        target: ground truth cluster labels

    Returns:
        Scalar tensor with Fowlkes-Mallows index

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

    )r   r   )r   r   r   r   s       r   Úfowlkes_mallows_indexr   9   s'   € õ& 3°5¸&ÑAÔA�N€K�Ý)¨+°qÑ9Ô9Ð9r   )r   r   r   Ú(torchmetrics.functional.clustering.utilsr   r   ÚtupleÚintr   r   r   © r   r   ú<module>r$      sÖ   ðð €€€Ø  Ð  Ð  Ð  Ð  Ð  Ð  Ð  à gÐ gÐ gÐ gÐ gÐ gÐ gÐ gðF¨ð F¸ð FÀEÈ&ÐRUÈ+ÔDVð Fð Fð Fð Fð5°ð 5¸3ð 5À6ð 5ð 5ð 5ð 5ð*: ð :°ð :¸Fð :ð :ð :ð :ð :ð :r   