§
    ’©ºj‚  ã                   óz   — d dl Z d dl mZ d dlmZ ddeded         defd	„Zdedefd
„Zddeded         defd„ZdS )é    N)ÚTensor)ÚLiteralÚcountsÚratingsÚmode©r   ÚprobsÚreturnc                 ó¼  — |dk    r¡| j         dk    s|                      ¦   «         st          d¦  «        ‚|                      d¬¦  «        } t          j        j                             | | j        d         ¬¦  «         	                    ddd¦  «        }| 
                    d	¬¦  «        } n4|d
k    r.| j         dk    s|                      ¦   «         rt          d¦  «        ‚| S )z¢Updates the counts for fleiss kappa metric.

    Args:
        ratings: ratings matrix
        mode: whether ratings are provided as counts or probabilities

    r	   é   zŠIf argument ``mode`` is 'probs', ratings must have 3 dimensions with the format [n_samples, n_categories, n_raters] and be floating point.é   ©Údim)Únum_classesr   é   éÿÿÿÿr   z†If argument ``mode`` is `counts`, ratings must have 2 dimensions with the format [n_samples, n_categories] and be none floating point.)ÚndimÚis_floating_pointÚ
ValueErrorÚargmaxÚtorchÚnnÚ
functionalÚone_hotÚshapeÚpermuteÚsum)r   r   r   s      ú|/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/nominal/fleiss_kappa.pyÚ_fleiss_kappa_updater      sî   € ð ˆw‚€ØŒ<˜1ÒÐ G×$=Ò$=Ñ$?Ô$?ÐÝðNñô ð ð —.’. Q�.Ñ'Ô'ˆÝ”(Ô%×-Ò-¨gÀ7Ä=ÐQRÔCSÐ-ÑTÔT×\Ò\Ð]^Ð`aÐcdÑeÔeˆØ—+’+ "�+Ñ%Ô%ˆˆØ	�Ò	Ð	˜wœ|¨qÒ0Ð0°G×4MÒ4MÑ4OÔ4OÐ0ÝðEñ
ô 
ð 	
ð €Nó    c                 ó^  — | j         d         }|                      d¦  «                             ¦   «         }|                      d¬¦  «        ||z  z  }| dz                       d¬¦  «        |z
  ||dz
  z  z  }|                     ¦   «         }|dz                       ¦   «         }||z
  d|z
  dz   z  S )z{Computes fleiss kappa from counts matrix.

    Args:
        counts: counts matrix of shape [n_samples, n_categories]

    r   r   r   r   gñhãˆµøä>)r   r   ÚmaxÚmean)r   ÚtotalÚ
num_ratersÚp_iÚp_jÚp_barÚpe_bars          r   Ú_fleiss_kappa_computer*   ,   s§   € ð ŒL˜ŒO€EØ—’˜A‘”×"Ò"Ñ$Ô$€Jà
�*Š*˜ˆ*Ñ
Ô
˜u zÑ1Ñ
2€CØ�A‰I�?Š?˜qˆ?Ñ!Ô! JÑ.°:ÀÈaÁÑ3PÑ
Q€CØ�HŠH‰JŒJ€EØ�1‰f�\Š\‰^Œ^€FØ�F‰N˜q 6™z¨DÑ0Ñ1Ð1r    c                 óf   — |dvrt          d¦  «        ‚t          | |¦  «        }t          |¦  «        S )a¨  Calculatees `Fleiss kappa`_ a statistical measure for inter agreement between raters.

    .. math::
        \kappa = \frac{\bar{p} - \bar{p_e}}{1 - \bar{p_e}}

    where :math:`\bar{p}` is the mean of the agreement probability over all raters and :math:`\bar{p_e}` is the mean
    agreement probability over all raters if they were randomly assigned. If the raters are in complete agreement then
    the score 1 is returned, if there is no agreement among the raters (other than what would be expected by chance)
    then a score smaller than 0 is returned.

    Args:
        ratings: Ratings of shape [n_samples, n_categories] or [n_samples, n_categories, n_raters] depedenent on `mode`.
            If `mode` is `counts`, `ratings` must be integer and contain the number of raters that chose each category.
            If `mode` is `probs`, `ratings` must be floating point and contain the probability/logits that each rater
            chose each category.
        mode: Whether `ratings` will be provided as counts or probabilities.

    Example:
        >>> # Ratings are provided as counts
        >>> from torch import randint
        >>> from torchmetrics.functional.nominal import fleiss_kappa
        >>> ratings = randint(0, 10, size=(100, 5)).long()  # 100 samples, 5 categories, 10 raters
        >>> fleiss_kappa(ratings)
        tensor(0.0089)

    Example:
        >>> # Ratings are provided as probabilities
        >>> from torch import randn
        >>> from torchmetrics.functional.nominal import fleiss_kappa
        >>> ratings = randn(100, 5, 10).softmax(dim=1)  # 100 samples, 5 categories, 10 raters
        >>> fleiss_kappa(ratings, mode='probs')
        tensor(-0.0075)

    r   z5Argument ``mode`` must be one of ['counts', 'probs'].)r   r   r*   )r   r   r   s      r   Úfleiss_kappar,   =   s=   € ðF Ð&Ð&Ð&ÝÐPÑQÔQÐQÝ! '¨4Ñ0Ô0€FÝ  Ñ(Ô(Ð(r    )r   )r   r   Útyping_extensionsr   r   r*   r,   © r    r   ú<module>r/      sÊ   ðð €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %ðð  &ð °Ð8IÔ0Jð ÐZ`ð ð ð ð ð22 &ð 2¨Vð 2ð 2ð 2ð 2ð"&)ð &)˜&ð &)¨Ð0AÔ(Bð &)ÐRXð &)ð &)ð &)ð &)ð &)ð &)r    