Ë
    óÍ:jµ  ã                   ó’   — d dl mZmZ d dlZd dlmc 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mZmZ dgZ G d	„ de«      Zy)
é    )ÚOptionalÚUnionN)ÚTensor)Úconstraints)ÚDistribution)ÚGamma)Úbroadcast_allÚlazy_propertyÚlogits_to_probsÚprobs_to_logitsÚNegativeBinomialc                   óÄ  ‡ — e Zd ZdZ ej
                  d«       ej                  dd«      ej                  dœZej                  Z
	 	 	 ddeeef   dee   d	ee   d
ee   ddf
ˆ fd„Zdˆ fd„	Zd„ Zedefd„«       Zedefd„«       Zedefd„«       Zedefd„«       Zedefd„«       Zedej6                  fd„«       Zedefd„«       Z ej6                  «       fd„Zd„ Z ˆ xZ!S )r   ao  
    Creates a Negative Binomial distribution, i.e. distribution
    of the number of successful independent and identical Bernoulli trials
    before :attr:`total_count` failures are achieved. The probability
    of success of each Bernoulli trial is :attr:`probs`.

    Args:
        total_count (float or Tensor): non-negative number of negative Bernoulli
            trials to stop, although the distribution is still valid for real
            valued count
        probs (Tensor): Event probabilities of success in the half open interval [0, 1)
        logits (Tensor): Event log-odds for probabilities of success
    r   ç        ç      ð?)Útotal_countÚprobsÚlogitsNr   r   r   Úvalidate_argsÚreturnc                 óÜ  •— |d u |d u k(  rt        d«      ‚|�Dt        ||«      \  | _        | _        | j                  j	                  | j                  «      | _        nG|€J ‚t        ||«      \  | _        | _        | j                  j	                  | j
                  «      | _        |�| j                  n| j
                  | _        | j                  j                  «       }t        ‰| �%  ||¬«       y )Nz;Either `probs` or `logits` must be specified, but not both.©r   )
Ú
ValueErrorr	   r   r   Útype_asr   Ú_paramÚsizeÚsuperÚ__init__)Úselfr   r   r   r   Úbatch_shapeÚ	__class__s         €úz/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torch/distributions/negative_binomial.pyr   zNegativeBinomial.__init__+   så   ø€ ð �TˆM˜v¨˜~Ò.ÜØMóð ð Ðô ˜k¨5Ó1ñØÔ Ø”
à#×/Ñ/×7Ñ7¸¿
¹
ÓCˆDÕàÐ%Ð%Ð%ô ˜k¨6Ó2ñØÔ Ø”à#×/Ñ/×7Ñ7¸¿¹ÓDˆDÔà$)Ð$5�d—j’j¸4¿;¹;ˆŒØ—k‘k×&Ñ&Ó(ˆÜ‰Ñ˜°MÐÕBó    c                 óæ  •— | j                  t        |«      }t        j                  |«      }| j                  j                  |«      |_        d| j                  v r1| j                  j                  |«      |_        |j                  |_        d| j                  v r1| j                  j                  |«      |_	        |j                  |_        t        t        |�/  |d¬«       | j                  |_        |S )Nr   r   Fr   )Ú_get_checked_instancer   ÚtorchÚSizer   ÚexpandÚ__dict__r   r   r   r   r   Ú_validate_args)r   r   Ú	_instanceÚnewr    s       €r!   r'   zNegativeBinomial.expandH   s¾   ø€ Ø×(Ñ(Ô)9¸9ÓEˆÜ—j‘j Ó-ˆØ×*Ñ*×1Ñ1°+Ó>ˆŒØ�d—m‘mÑ#ØŸ
™
×)Ñ)¨+Ó6ˆCŒIØŸ™ˆCŒJØ�t—}‘}Ñ$ØŸ™×+Ñ+¨KÓ8ˆCŒJØŸ™ˆCŒJÜÔ Ñ-¨kÈÐ-ÔOØ!×0Ñ0ˆÔØˆ
r"   c                 ó:   —  | j                   j                  |i |¤ŽS ©N)r   r+   )r   ÚargsÚkwargss      r!   Ú_newzNegativeBinomial._newV   s   € Øˆt�{‰{�‰ Ð/¨Ñ/Ð/r"   c                 óZ   — | j                   t        j                  | j                  «      z  S r-   )r   r%   Úexpr   ©r   s    r!   ÚmeanzNegativeBinomial.meanY   s    € à×Ñ¤%§)¡)¨D¯K©KÓ"8Ñ8Ð8r"   c                 ó’   — | j                   dz
  | j                  j                  «       z  j                  «       j	                  d¬«      S )Né   r   )Úmin)r   r   r2   ÚfloorÚclampr3   s    r!   ÚmodezNegativeBinomial.mode]   s:   € à×!Ñ! AÑ%¨¯©¯©Ó):Ñ:×AÑAÓC×IÑIÈcÐIÓRÐRr"   c                 ó\   — | j                   t        j                  | j                   «      z  S r-   )r4   r%   Úsigmoidr   r3   s    r!   ÚvariancezNegativeBinomial.variancea   s    € à�y‰yœ5Ÿ=™=¨$¯+©+¨Ó6Ñ6Ð6r"   c                 ó0   — t        | j                  d¬«      S ©NT)Ú	is_binary)r   r   r3   s    r!   r   zNegativeBinomial.logitse   s   € ä˜tŸz™z°TÔ:Ð:r"   c                 ó0   — t        | j                  d¬«      S r?   )r   r   r3   s    r!   r   zNegativeBinomial.probsi   s   € ä˜tŸ{™{°dÔ;Ð;r"   c                 ó6   — | j                   j                  «       S r-   )r   r   r3   s    r!   Úparam_shapezNegativeBinomial.param_shapem   s   € à�{‰{×ÑÓ!Ð!r"   c                 ón   — t        | j                  t        j                  | j                   «      d¬«      S )NF)ÚconcentrationÚrater   )r   r   r%   r2   r   r3   s    r!   Ú_gammazNegativeBinomial._gammaq   s/   € ô Ø×*Ñ*Ü—‘˜DŸK™K˜<Ó(Øô
ð 	
r"   c                 ó¸   — t        j                  «       5  | j                  j                  |¬«      }t        j                  |«      cd d d «       S # 1 sw Y   y xY w)N)Úsample_shape)r%   Úno_gradrG   ÚsampleÚpoisson)r   rI   rF   s      r!   rK   zNegativeBinomial.samplez   sC   € Ü�]‰]‹_ñ 	'Ø—;‘;×%Ñ%°<Ð%Ó@ˆDÜ—=‘= Ó&÷	'÷ 	'ò 	'ús   •1AÁAc                 óâ  — | j                   r| j                  |«       | j                  t        j                  | j
                   «      z  |t        j                  | j
                  «      z  z   }t        j                  | j                  |z   «       t        j                  d|z   «      z   t        j                  | j                  «      z   }|j                  | j                  |z   dk(  d«      }||z
  S )Nr   r   )	r)   Ú_validate_sampler   ÚFÚ
logsigmoidr   r%   ÚlgammaÚmasked_fill)r   ÚvalueÚlog_unnormalized_probÚlog_normalizations       r!   Úlog_probzNegativeBinomial.log_prob   sÛ   € Ø×ÒØ×!Ñ! %Ô(à $× 0Ñ 0´1·<±<Ø�[‰[ˆLó4
ñ !
à”A—L‘L §¡Ó-Ñ-ñ!.Ðô
 �\‰\˜$×*Ñ*¨UÑ2Ó3Ð3Ü�l‰l˜3 ™;Ó'ñ(ä�l‰l˜4×+Ñ+Ó,ñ-ð 	ð .×9Ñ9Ø×Ñ˜uÑ$¨Ñ+¨Só
Ðð %Ð'8Ñ8Ð8r"   )NNNr-   )"Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úgreater_than_eqÚhalf_open_intervalÚrealÚarg_constraintsÚnonnegative_integerÚsupportr   r   Úfloatr   Úboolr   r'   r0   Úpropertyr4   r:   r=   r
   r   r   r%   r&   rC   r   rG   rK   rV   Ú__classcell__)r    s   @r!   r   r      s‹  ø„ ñð 3�{×2Ñ2°1Ó5Ø/�×/Ñ/°°SÓ9Ø×"Ñ"ñ€Oð
 ×-Ñ-€Gð
 #'Ø#'Ø(,ñCà˜6 5˜=Ñ)ðCð ˜ÑðCð ˜Ñ ð	Cð
   ‘~ðCð 
õCõ:ò0ð ð9�fò 9ó ð9ð ðS�fò Só ðSð ð7˜&ò 7ó ð7ð ð;˜ò ;ó ð;ð ð<�vò <ó ð<ð ð"˜UŸZ™Zò "ó ð"ð ð
˜ò 
ó ð
ð #- %§*¡*£,ó 'ö
9r"   )Útypingr   r   r%   Útorch.nn.functionalÚnnÚ
functionalrO   r   Útorch.distributionsr   Ú torch.distributions.distributionr   Útorch.distributions.gammar   Útorch.distributions.utilsr	   r
   r   r   Ú__all__r   © r"   r!   ú<module>ro      s?   ðç "ã ß Ð Ý Ý +Ý 9Ý +÷ó ð Ð
€ô~9�|õ ~9r"   