§
    ÷óÉjo4  ã                   óâ   — d dl mZmZmZmZmZ d dlZd dlZd dl	Z
d dlZd dlmZmZ d dlmZmZ  G d„ d¦  «        ZdZdZd	Z G d
„ de¦  «        ZdZdZd	Z G d„ de¦  «        Zddededefd„ZdS )é    )ÚListÚUnionÚOptionalÚSetÚTupleN)Ú
AnnotationÚTimeline)ÚDetailsÚMetricComponentsc            
       ó„  ‡ — e Zd ZdZedefd„¦   «         Zedefd„¦   «         Zˆ fd„Z	d„ Z
d„ Zed„ ¦   «         Z	 ddeeef         deeef         dedee         fd„Zddedej        fd„Zd„ Zd„ Zdedeeef         fd„Zd„ Zdeeef         deeef         defd„Zdefd„Zddedeeeeef         f         fd„Z ˆ xZ!S ) Ú
BaseMetriczÌ
    :class:`BaseMetric` is the base class for most pyannote evaluation metrics.

    Attributes
    ----------
    name : str
        Human-readable name of the metric (eg. 'diarization error rate')
    Úreturnc                 ó0   — t          | j        dz   ¦  «        ‚)Nz\ is missing a 'metric_name' class method. It should return the name of the metric as string.©ÚNotImplementedErrorÚ__name__©Úclss    úx/home/lighthouse/badge-speaker-benchmark/.benchmark-venv-community/lib/python3.11/site-packages/pyannote/metrics/base.pyÚmetric_namezBaseMetric.metric_name1   s%   € å!ØŒLð Pñ Pñ
ô 
ð 	
ó    c                 ó0   — t          | j        dz   ¦  «        ‚)Nzh is missing a 'metric_components' class method. It should return the list of names of metric components.r   r   s    r   Úmetric_componentszBaseMetric.metric_components8   s%   € å!ØŒLð Vñ Vñ
ô 
ð 	
r   c                 ó  •— t          t          | ¦  «                             ¦   «          | j                             ¦   «         | _        t          | j                             ¦   «         ¦  «        | _        |  	                    ¦   «          d S ©N)
Úsuperr   Ú__init__Ú	__class__r   Úmetric_name_Úsetr   Úcomponents_Úreset)ÚselfÚkwargsr   s     €r   r   zBaseMetric.__init__?   sd   ø€ Ý�j˜$ÑÔ×(Ò(Ñ*Ô*Ð*Ø œN×6Ò6Ñ8Ô8ˆÔÝ%(¨¬×)IÒ)IÑ)KÔ)KÑ%LÔ%LˆÔØ�
Š
‰Œˆˆˆr   c                 ó$   — d„ | j         D ¦   «         S )Nc                 ó   — i | ]}|d “ŒS )ç        © )Ú.0Úvalues     r   ú
<dictcomp>z.BaseMetric.init_components.<locals>.<dictcomp>F   s   € Ð9Ð9Ð9˜u��sÐ9Ð9Ð9r   )r!   ©r#   s    r   Úinit_componentszBaseMetric.init_componentsE   s   € Ø9Ð9¨Ô(8Ð9Ñ9Ô9Ð9r   c                 óz   — t          ¦   «         | _        t          ¦   «         | _        | j        D ]}d| j        |<   ŒdS )z.Reset accumulated components and metric valuesr'   N)ÚdictÚaccumulated_ÚlistÚresults_r!   )r#   r*   s     r   r"   zBaseMetric.resetH   sE   € å%)¡V¤VˆÔÝ"™fœfˆŒØÔ%ð 	+ð 	+ˆEØ'*ˆDÔ˜eÑ$Ð$ð	+ð 	+r   c                 ó*   — |                       ¦   «         S )zMetric name.)r   r,   s    r   ÚnamezBaseMetric.nameO   s   € ð ×ÒÑ!Ô!Ð!r   FNÚ	referenceÚ
hypothesisÚdetailedÚuric                 ó$  —  | j         ||fi |¤Ž}|                      |¦  «        || j        <   |pt          |dd¦  «        }| j                             ||f¦  «         | j        D ]}| j        |xx         ||         z  cc<   Œ|r|S || j                 S )aÞ  Compute metric value and accumulate components

        Parameters
        ----------
        reference : type depends on the metric
            Manual `reference`
        hypothesis : type depends on the metric
            Evaluated `hypothesis`
        uri : optional
            Override uri.
        detailed : bool, optional
            By default (False), return metric value only.
            Set `detailed` to True to return dictionary where keys are
            components names and values are component values

        Returns
        -------
        value : float (if `detailed` is False)
            Metric value
        components : dict (if `detailed` is True)
            `components` updated with metric value
        r8   ÚNA)Úcompute_componentsÚcompute_metricr   Úgetattrr2   Úappendr!   r0   )r#   r5   r6   r7   r8   r$   Ú
componentsr4   s           r   Ú__call__zBaseMetric.__call__W   sÇ   € ð6 -�TÔ,¨Y¸
ÐMÐMÀfÐMÐMˆ
ð )-×(;Ò(;¸JÑ(GÔ(Gˆ
�4Ô$Ñ%ð Ð4•W˜Y¨¨tÑ4Ô4ˆØŒ×Ò˜c :Ð.Ñ/Ô/Ð/ð Ô$ð 	8ð 	8ˆDØÔ˜dÐ#Ð#Ô# z°$Ô'7Ñ7Ð#Ð#Ñ#Ð#àð 	ØÐà˜$Ô+Ô,Ð,r   Údisplayc                 óh  — g }g }d|                       ¦   «         v }| j        D ]§\  }}i }|r|d         }|                     ¦   «         D ]W\  }	}
|	| j        k    rd|
z  ||	df<   Œ|	dk    r|
||	df<   Œ)|
||	df<   |r%|dk    rd|
z  |z  ||	df<   ŒFt          j        ||	df<   ŒX|                     |¦  «         |                     |¦  «         Œ¨i }| j        }|r|d         }|                     ¦   «         D ]W\  }	}
|	| j        k    rd|
z  ||	df<   Œ|	dk    r|
||	df<   Œ)|
||	df<   |r%|dk    rd|
z  |z  ||	df<   ŒFt          j        ||	df<   ŒXdt          | ¦  «        z  || j        df<   |                     |¦  «         |                     d¦  «         t          j
        |¦  «        }||d<   |                     d¦  «        }t          j                             |j        ¦  «        |_        || j        g|                       ¦   «         z            }|r't          |                     dd	d
d„ ¬¦  «        ¦  «         |S )ak  Evaluation report

        Parameters
        ----------
        display : bool, optional
            Set to True to print the report to stdout.

        Returns
        -------
        report : pandas.DataFrame
            Dataframe with one column per metric component, one row per
            evaluated item, and one final row for accumulated results.
        Útotaléd   ú%Ú r   ÚTOTALÚitemTFÚrightc                 ó,   — d                      | ¦  «        S ©Nz{0:.2f}©Úformat©Úfs    r   ú<lambda>z#BaseMetric.report.<locals>.<lambda>Ò   s   € ¨9×+;Ò+;¸AÑ+>Ô+>€ r   )ÚindexÚsparsifyÚjustifyÚfloat_format)r   r2   Úitemsr4   ÚnpÚnanr>   r0   ÚabsÚpdÚ	DataFrameÚ	set_indexÚ
MultiIndexÚfrom_tuplesÚcolumnsÚprintÚ	to_string)r#   rA   ÚreportÚurisÚpercentr8   r?   ÚrowrC   Úkeyr*   Údfs               r   ra   zBaseMetric.report„   sµ  € ð ˆØˆà˜T×3Ò3Ñ5Ô5Ð5ˆà#œ}ð 	ð 	‰OˆC�ØˆCØð ,Ø" 7Ô+�Ø(×.Ò.Ñ0Ô0ð 3ð 3‘
��UØ˜$œ)Ò#Ð#Ø$'¨%¡K�C˜˜S˜‘M�MØ˜G’^�^Ø#(�C˜˜R˜‘L�Là#(�C˜˜R˜‘LØð 3Ø  1š9˜9Ø,/°%©K¸%Ñ,?˜C  S ™M˜Må,.¬F˜C  S ™Møà�MŠM˜#ÑÔÐØ�KŠK˜ÑÔÐÐàˆØÔ&ˆ
àð 	(Ø˜wÔ'ˆEà$×*Ò*Ñ,Ô,ð 	/ð 	/‰JˆC�Ø�d”iÒÐØ # e¡��C˜�H‘�Ø˜’�Ø$��C˜�G‘�à$��C˜�G‘Øð /Ø˜q’y�yØ(+¨e©°eÑ(;˜˜C ˜H™˜å(*¬˜˜C ˜H™øà!¥C¨¡I¤I™oˆˆDŒI�sˆNÑØ�Š�cÑÔÐØ�Š�GÑÔÐåŒ\˜&Ñ!Ô!ˆàˆˆ6‰
Ø�\Š\˜&Ñ!Ô!ˆå”]×.Ò.¨r¬zÑ:Ô:ˆŒ
à�”�˜d×4Ò4Ñ6Ô6Ñ6Ô7ˆàð 	ÝØ—’ØØ"Ø#Ø!>Ð!>ð	 ñ ô ñô ð ð ˆ	r   c                 ó^   — |                       d¬¦  «        }|                     dd„ ¬¦  «        S )NF)rA   c                 ó,   — d                      | ¦  «        S rK   rL   rN   s    r   rP   z$BaseMetric.__str__.<locals>.<lambda>Û   s   € °9×3CÒ3CÀAÑ3FÔ3F€ r   )rR   rT   )ra   r`   )r#   ra   s     r   Ú__str__zBaseMetric.__str__Ø   s;   € Ø—’ U�Ñ+Ô+ˆØ×ÒØÐ)FÐ)Fð  ñ 
ô 
ð 	
r   c                 ó6   — |                       | j        ¦  «        S )z0Compute metric value from accumulated components)r<   r0   r,   s    r   Ú__abs__zBaseMetric.__abs__Þ   s   € à×"Ò" 4Ô#4Ñ5Ô5Ð5r   Ú	componentc                 ón   — |t          ddd¦  «        k    rt          | j        ¦  «        S | j        |         S )a  Get value of accumulated `component`.

        Parameters
        ----------
        component : str
            Name of `component`

        Returns
        -------
        value : type depends on the metric
            Value of accumulated `component`

        N)Úslicer/   r0   )r#   rl   s     r   Ú__getitem__zBaseMetric.__getitem__â   s:   € ð �˜d D¨$Ñ/Ô/Ò/Ð/Ý˜Ô)Ñ*Ô*Ð*àÔ$ YÔ/Ð/r   c              #   ó0   K  — | j         D ]\  }}||fV — ŒdS )z*Iterator over the accumulated (uri, value)N)r2   )r#   r8   rl   s      r   Ú__iter__zBaseMetric.__iter__õ   s8   è è € à"œmð 	!ð 	!‰NˆC�Ø�y�.Ð Ð Ð Ð ð	!ð 	!r   c                 ó:   — t          | j        j        dz   ¦  «        ‚)a�  Compute metric components

        Parameters
        ----------
        reference : type depends on the metric
            Manual `reference`
        hypothesis : same as `reference`
            Evaluated `hypothesis`

        Returns
        -------
        components : dict
            Dictionary where keys are component names and values are component
            values

        z‡ is missing a 'compute_components' method.It should return a dictionary where keys are component names and values are component values.©r   r   r   )r#   r5   r6   r$   s       r   r;   zBaseMetric.compute_componentsú   s*   € õ( "ØŒNÔ#ð 'Iñ Iñ
ô 
ð 	
r   r?   c                 ó:   — t          | j        j        dz   ¦  «        ‚)aA  Compute metric value from computed `components`

        Parameters
        ----------
        components : dict
            Dictionary where keys are components names and values are component
            values

        Returns
        -------
        value : type depends on the metric
            Metric value
        z” is missing a 'compute_metric' method. It should return the actual value of the metric based on the precomputed component dictionary given as input.rs   )r#   r?   s     r   r<   zBaseMetric.compute_metric  s*   € õ "ØŒNÔ#ð '`ñ `ñ
ô 
ð 	
r   çÍÌÌÌÌÌì?Úalphac                 ó.  ‡ — ˆ fd„‰ j         D ¦   «         }t          |¦  «        dk    rt          d¦  «        ‚t          |¦  «        dk    r&t          j        d¦  «         |d         x}x}}|||ffS t
          j                             ||¬¦  «        d         S )aP  Compute confidence interval on accumulated metric values

        Parameters
        ----------
        alpha : float, optional
            Probability that the returned confidence interval contains
            the true metric value.

        Returns
        -------
        (center, (lower, upper))
            with center the mean of the conditional pdf of the metric value
            and (lower, upper) is a confidence interval centered on the median,
            containing the estimate to a probability alpha.

        See Also:
        ---------
        scipy.stats.bayes_mvs

        c                 ó0   •— g | ]\  }}|‰j                  ‘ŒS r(   )r   )r)   Ú_Úrr#   s      €r   ú
<listcomp>z2BaseMetric.confidence_interval.<locals>.<listcomp>?  s%   ø€ ÐAÐAÐA©4¨1¨a�!�DÔ%Ô&ÐAÐAÐAr   r   zFPlease evaluate a bunch of files before computing confidence interval.é   zCCannot compute a reliable confidence interval out of just one file.)rv   )r2   ÚlenÚ
ValueErrorÚwarningsÚwarnÚscipyÚstatsÚ	bayes_mvs)r#   rv   ÚvaluesÚcenterÚlowerÚuppers   `     r   Úconfidence_intervalzBaseMetric.confidence_interval(  s§   ø€ ð. BÐAÐAÐA°4´=ÐAÑAÔAˆåˆv‰;Œ;˜!ÒÐÝÐeÑfÔfÐfå�‰[Œ[˜AÒÐÝŒMÐ_Ñ`Ô`Ð`Ø%+¨A¤YÐ.ˆFÐ.�U˜UØ˜E 5˜>Ð)Ð)õ ”;×(Ò(¨°uÐ(Ñ=Ô=¸aÔ@Ð@r   )FN)F)ru   )"r   Ú
__module__Ú__qualname__Ú__doc__ÚclassmethodÚstrr   r   r   r   r-   r"   Úpropertyr4   r   r	   r   Úboolr   r@   rY   rZ   ra   ri   rk   Úfloatr
   ro   rq   r;   r<   r   rˆ   Ú__classcell__)r   s   @r   r   r   '   sM  ø€ € € € € ðð ð ð
˜Cð 
ð 
ð 
ñ „[ð
ð ð
Ð"2ð 
ð 
ð 
ñ „[ð
ðð ð ð ð ð:ð :ð :ð+ð +ð +ð ð"ð "ñ „Xð"ð ?Cð+-ð +- %¨°*Ð(<Ô"=ð +-Ø" 8¨ZÐ#7Ô8ð+-àð+-à.6°s¬mð+-ð +-ð +-ð +-ðZRð R˜dð R¨r¬|ð Rð Rð Rð Rðh
ð 
ð 
ð6ð 6ð 6ð0 Sð 0¨U°5¸'°>Ô-Bð 0ð 0ð 0ð 0ð&!ð !ð !ð

Ø&+¨H°jÐ,@Ô&Að
à',¨X°zÐ-AÔ'Bð
ð )0ð
ð 
ð 
ð 
ð4
¨ð 
ð 
ð 
ð 
ð("Að "A¨ð "AØ�U˜E %¨ ,Ô/Ð/Ô0ð"Að "Að "Að "Að "Að "Að "Að "Ar   r   Ú	precisionz# retrievedz# relevant retrievedc                   óT   — e Zd ZdZed„ ¦   «         Zedefd„¦   «         Zdede	fd„Z
dS )Ú	PrecisionaU  
    :class:`Precision` is a base class for precision-like evaluation metrics.

    It defines two components '# retrieved' and '# relevant retrieved' and the
    compute_metric() method to compute the actual precision:

        Precision = # retrieved / # relevant retrieved

    Inheriting classes must implement compute_components().
    c                 ó   — t           S r   )ÚPRECISION_NAMEr   s    r   r   zPrecision.metric_name^  s   € åÐr   r   c                 ó   — t           t          gS r   )ÚPRECISION_RETRIEVEDÚPRECISION_RELEVANT_RETRIEVEDr   s    r   r   zPrecision.metric_componentsb  s   € å#Õ%AÐBÐBr   r?   c                 óz   — |t                    }|t                   }|dk    r|dk    rdS t          d¦  «        ‚||z  S )z#Compute precision from `components`r'   r   ç      ð?rF   )r™   r˜   r~   ©r#   r?   Ú	numeratorÚdenominators       r   r<   zPrecision.compute_metricf  sH   € àÕ;Ô<ˆ	Ø Õ!4Ô5ˆØ˜#ÒÐØ˜AŠ~ˆ~Ø�så  ‘n”nÐ$à˜{Ñ*Ð*r   N©r   r‰   rŠ   r‹   rŒ   r   r   r   r
   r�   r<   r(   r   r   r”   r”   R  sˆ   € € € € € ð	ð 	ð ðð ñ „[ðð ðCÐ"2ð Cð Cð Cñ „[ðCð
+¨ð 
+°Uð 
+ð 
+ð 
+ð 
+ð 
+ð 
+r   r”   Úrecallz
# relevantc                   óT   — e Zd ZdZed„ ¦   «         Zedefd„¦   «         Zdede	fd„Z
dS )ÚRecallaG  
    :class:`Recall` is a base class for recall-like evaluation metrics.

    It defines two components '# relevant' and '# relevant retrieved' and the
    compute_metric() method to compute the actual recall:

        Recall = # relevant retrieved / # relevant

    Inheriting classes must implement compute_components().
    c                 ó   — t           S r   )ÚRECALL_NAMEr   s    r   r   zRecall.metric_name„  s   € åÐr   r   c                 ó   — t           t          gS r   )ÚRECALL_RELEVANTÚRECALL_RELEVANT_RETRIEVEDr   s    r   r   zRecall.metric_componentsˆ  s   € åÕ!:Ð;Ð;r   r?   c                 óz   — |t                    }|t                   }|dk    r|dk    rdS t          d¦  «        ‚||z  S )z Compute recall from `components`r'   r   r›   rF   )r§   r¦   r~   rœ   s       r   r<   zRecall.compute_metricŒ  sG   € àÕ8Ô9ˆ	Ø ¥Ô1ˆØ˜#ÒÐØ˜AŠ~ˆ~Ø�så  ‘n”nÐ$à˜{Ñ*Ð*r   NrŸ   r(   r   r   r¢   r¢   x  sƒ   € € € € € ð	ð 	ð ðð ñ „[ðð ð<Ð"2ð <ð <ð <ñ „[ð<ð
+¨ð 
+°Uð 
+ð 
+ð 
+ð 
+ð 
+ð 
+r   r¢   r›   r   c                 óL   — | |z   dk    rdS d||z  z   | z  |z  ||z  | z  |z   z  S )u¦   Compute f-measure

    f-measure is defined as follows:
        F(P, R, b) = (1+bÂ²).P.R / (bÂ².P + R)

    where P is `precision`, R is `recall` and b is `beta`
    r'   r   r|   r(   )r’   r    Úbetas      r   Ú	f_measurer«   ™  sD   € ð �6Ñ˜SÒ Ð ØˆqØ��t‘‰O˜yÑ(¨6Ñ1°T¸D±[À9Ñ5LÈvÑ5UÑVÐVr   )r›   )Útypingr   r   r   r   r   r   ÚnumpyrV   ÚpandasrY   Úscipy.statsr�   Úpyannote.corer   r	   Úpyannote.metrics.typesr
   r   r   r–   r˜   r™   r”   r¤   r¦   r§   r¢   r�   r«   r(   r   r   ú<module>r²      s„  ðð8 5Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4à €€€Ø Ð Ð Ð Ø Ð Ð Ð Ø Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .à <Ð <Ð <Ð <Ð <Ð <Ð <Ð <ðcAð cAð cAð cAð cAñ cAô cAð cAðL	 €Ø#Ð Ø5Ð ð+ð +ð +ð +ð +�
ñ +ô +ð +ðB €Ø€Ø2Ð ð+ð +ð +ð +ð +ˆZñ +ô +ð +ðB
Wð 
W˜ð 
W¨ð 
W¸Eð 
Wð 
Wð 
Wð 
Wð 
Wð 
Wr   