
    [Th                         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	  S SK
Jr  S SKJrJrJrJr  S/r " S S\	5      rg)	    N)Tensor)constraints)Distribution)Gamma)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
\4S j5       r\S
\4S j5       r\S
\4S j5       r\S
\4S j5       r\S
\4S j5       r\S
\R0                  4S j5       r\S
\4S j5       r\R0                  " 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         ]/var/www/auris/envauris/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._newM   s    {{///r!   returnc                 \    U R                   [        R                  " U R                  5      -  $ r-   )r   r$   expr   r   s    r   meanNegativeBinomial.meanP   s     %))DKK"888r!   c                     U R                   S-
  U R                  R                  5       -  R                  5       R	                  SS9$ )N   r   )min)r   r   r4   floorclampr5   s    r   modeNegativeBinomial.modeT   s:    !!A%)::AACIIcIRRr!   c                 ^    U R                   [        R                  " U R                  * 5      -  $ r-   )r6   r$   sigmoidr   r5   s    r   varianceNegativeBinomial.varianceX   s     yy5==$++666r!   c                 *    [        U R                  SS9$ NT)	is_binary)r
   r   r5   s    r   r   NegativeBinomial.logits\   s    tzzT::r!   c                 *    [        U R                  SS9$ rD   )r	   r   r5   s    r   r   NegativeBinomial.probs`   s    t{{d;;r!   c                 6    U R                   R                  5       $ r-   )r   r   r5   s    r   param_shapeNegativeBinomial.param_shaped   s    {{!!r!   c                 j    [        U R                  [        R                  " U R                  * 5      SS9$ )NF)concentrationrater   )r   r   r$   r4   r   r5   s    r   _gammaNegativeBinomial._gammah   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_gradrO   samplepoisson)r   rR   rN   s      r   rT   NegativeBinomial.sampleq   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_probv   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&   r0   propertyr   r6   r=   rA   r   r   r   r$   r%   rJ   r   rO   rT   r`   __static_attributes____classcell__)r   s   @r   r   r      s3    #2215//S9""O
 --GC,0 9f 9 9 Sf S S 7& 7 7 ; ; ; <v < < "UZZ " " 
 
 
 #(**, '
9 9r!   )r$   torch.nn.functionalnn
functionalrY   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.gammar   torch.distributions.utilsr   r   r	   r
   __all__r    r!   r   <module>ry      s<        + 9 +  
w9| w9r!   