
    IЦi[                     j    S SK r S SKJs  Jr  S SKJr  S SKJr  S SK	J
r
JrJrJr  S/r " S S\5      rg)    N)constraints)Distribution)broadcast_alllazy_propertylogits_to_probsprobs_to_logitsNegativeBinomialc                   `  ^  \ rS rSrSr\R                  " S5      \R                  " SS5      \R                  S.r	\R                  rSU 4S jjrSU 4S jjrS	 r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\R2                  " 5       4S jrS rSrU =r$ )r	      aC  
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logitsc                   > US L US L :X  a  [        S5      eUbC  [        X5      u  U l        U l        U R                  R	                  U R                  5      U l        OB[        X5      u  U l        U l        U R                  R	                  U R
                  5      U l        Ub  U R                  OU R
                  U l        U R                  R                  5       n[        TU ]%  XTS9  g )Nz;Either `probs` or `logits` must be specified, but not both.validate_args)

ValueErrorr   r   r   type_asr   _paramsizesuper__init__)selfr   r   r   r   batch_shape	__class__s         d/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torch/distributions/negative_binomial.pyr   NegativeBinomial.__init__&   s    TMv~.M   k1 
#//77

CD
 k2 #//77DD$)$5djj4;;kk&&(B    c                   > U R                  [        U5      n[        R                  " U5      nU R                  R                  U5      Ul        SU R                  ;   a1  U R                  R                  U5      Ul        UR                  Ul        SU R                  ;   a1  U R                  R                  U5      Ul	        UR                  Ul        [        [        U]/  USS9  U R                  Ul        U$ )Nr   r   Fr   )_get_checked_instancer	   torchSizer   expand__dict__r   r   r   r   r   _validate_args)r   r   	_instancenewr   s       r   r$   NegativeBinomial.expand<   s    (()99Ejj-**11+>dmm#

))+6CICJt}}$++K8CJCJ-k-O!00
r   c                 :    U R                   R                  " U0 UD6$ N)r   r(   )r   argskwargss      r   _newNegativeBinomial._newJ   s    {{///r   c                 \    U R                   [        R                  " U R                  5      -  $ r+   )r   r"   expr   r   s    r   meanNegativeBinomial.meanM   s     %))DKK"888r   c                     U R                   S-
  U R                  R                  5       -  R                  5       R	                  SS9$ )N   r   )min)r   r   r1   floorclampr2   s    r   modeNegativeBinomial.modeQ   s:    !!A%)::AACIIcIRRr   c                 ^    U R                   [        R                  " U R                  * 5      -  $ r+   )r3   r"   sigmoidr   r2   s    r   varianceNegativeBinomial.varianceU   s     yy5==$++666r   c                 *    [        U R                  SS9$ NT)	is_binary)r   r   r2   s    r   r   NegativeBinomial.logitsY   s    tzzT::r   c                 *    [        U R                  SS9$ rA   )r   r   r2   s    r   r   NegativeBinomial.probs]   s    t{{d;;r   c                 6    U R                   R                  5       $ r+   )r   r   r2   s    r   param_shapeNegativeBinomial.param_shapea   s    {{!!r   c                     [         R                  R                  U R                  [         R                  " U R
                  * 5      SS9$ )NF)concentrationrater   )r"   distributionsGammar   r1   r   r2   s    r   _gammaNegativeBinomial._gammae   s@     ""((**DKK<( ) 
 	
r   c                     [         R                  " 5          U R                  R                  US9n[         R                  " U5      sS S S 5        $ ! , (       d  f       g = f)N)sample_shape)r"   no_gradrN   samplepoisson)r   rQ   rK   s      r   rS   NegativeBinomial.samplen   s8    ]]_;;%%<%@D==& __s   /A
Ac                    U R                   (       a  U R                  U5        U R                  [        R                  " U R
                  * 5      -  U[        R                  " U R
                  5      -  -   n[        R                  " U R                  U-   5      * [        R                  " SU-   5      -   [        R                  " U R                  5      -   nUR                  U R                  U-   S:H  S5      nX#-
  $ )Nr   r   )	r&   _validate_sampler   F
logsigmoidr   r"   lgammamasked_fill)r   valuelog_unnormalized_problog_normalizations       r   log_probNegativeBinomial.log_probs   s    !!%( $ 0 01<<[[L4
 !
ALL--!.
 \\$**U233ll3;'(ll4++,- 	 .99u$+S
 %88r   )r   r   r   r   )NNNr+   )__name__
__module____qualname____firstlineno____doc__r   greater_than_eqhalf_open_intervalrealarg_constraintsnonnegative_integersupportr   r$   r.   propertyr3   r:   r>   r   r   r   rG   rN   r"   r#   rS   r_   __static_attributes____classcell__)r   s   @r   r	   r	      s     #2215//S9""O
 --GC,0 9 9 S S 7 7 ; ; < < " " 
 
 #(**, '
9 9r   )r"   torch.nn.functionalnn
functionalrX   torch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   r   r   r   __all__r	    r   r   <module>rw      s6       + 9  
v9| v9r   