§
    ’©ºjê	  ã                   óp   — d dl Z d dl mZ d dlmZ d dlmZ d dlmZ esdgZdedefd	„Z	d
edede
defd„ZdS )é    N)ÚTensor)Úmulticlass_confusion_matrix)Úcheck_cluster_labels)Ú"_TORCH_LINEAR_ASSIGNMENT_AVAILABLEÚcluster_accuracyÚconfmatÚreturnc                 ó2  — ddl m} | d         }  ||                      ¦   «         | z
  ¦  «        }| d         } | t          j        | j        d         ¦  «        |                     ¦   «         f         }|                     ¦   «         |                      ¦   «         z  S )z9Computes the clustering accuracy from a confusion matrix.r   )Úbatch_linear_assignmentN)Útorch_linear_assignmentr   ÚmaxÚtorchÚarangeÚshapeÚflattenÚsum)r   r   Ú
assignmentÚtpss       úƒ/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/clustering/cluster_accuracy.pyÚ_cluster_accuracy_computer      sŠ   € à?Ð?Ð?Ð?Ð?Ð?à�dŒm€Gà(Ð(¨¯ª©¬¸Ñ)@ÑAÔA€JØ�aŒj€Gà
•%”,˜wœ}¨QÔ/Ñ0Ô0°*×2DÒ2DÑ2FÔ2FÐFÔ
G€CØ�7Š7‰9Œ9�w—{’{‘}”}Ñ$Ð$ó    ÚpredsÚtargetÚnum_classesc                 ó�   — t           st          d¦  «        ‚t          | |¦  «         t          | ||¬¦  «        }t	          |¦  «        S )aƒ  Computes the clustering accuracy between the predicted and target clusters.

    Args:
        preds: predicted cluster labels
        target: ground truth cluster labels
        num_classes: number of classes

    Returns:
        Scalar tensor with clustering accuracy between 0.0 and 1.0

    Raises:
        RuntimeError:
            If `torch_linear_assignment` is not installed

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

    zaMissing `torch_linear_assignment`. Please install it with `pip install torchmetrics[clustering]`.)r   )r   ÚRuntimeErrorr   r   r   )r   r   r   r   s       r   r   r   &   sU   € õ. .ð 
ÝØoñ
ô 
ð 	
õ ˜ Ñ'Ô'Ð'Ý)¨%°À[ÐQÑQÔQ€GÝ$ WÑ-Ô-Ð-r   )r   r   Ú&torchmetrics.functional.classificationr   Ú(torchmetrics.functional.clustering.utilsr   Útorchmetrics.utilities.importsr   Ú__doctest_skip__r   Úintr   © r   r   ú<module>r#      sÅ   ðð €€€Ø Ð Ð Ð Ð Ð à NÐ NÐ NÐ NÐ NÐ NØ IÐ IÐ IÐ IÐ IÐ IØ MÐ MÐ MÐ MÐ MÐ Mà)ð ,Ø*Ð+Ðð
% vð 
%°&ð 
%ð 
%ð 
%ð 
%ð.˜Fð .¨Fð .Àð .Èð .ð .ð .ð .ð .ð .r   