
    9i                         S SK JrJr  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)
    )OptionalUnionN)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S\\\4   S	\\   S
\\   S\\   SS4
U 4S j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\R8                  4S j5       r\S\4S j5       r\R8                  " 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logitsNr   r   r   validate_argsreturnc                   > 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        OGUc   e[        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.r   )

ValueErrorr	   r   r   type_asr   _paramsizesuper__init__)selfr   r   r   r   batch_shape	__class__s         e/var/www/html/land-doc-ocr/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.expandH   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._newV   s    {{///r$   c                 \    U R                   [        R                  " U R                  5      -  $ r0   )r   r'   expr   r   s    r"   meanNegativeBinomial.meanY   s     %))DKK"888r$   c                     U R                   S-
  U R                  R                  5       -  R                  5       R	                  SS9$ )N   r   )min)r   r   r6   floorclampr7   s    r"   modeNegativeBinomial.mode]   s:    !!A%)::AACIIcIRRr$   c                 ^    U R                   [        R                  " U R                  * 5      -  $ r0   )r8   r'   sigmoidr   r7   s    r"   varianceNegativeBinomial.variancea   s     yy5==$++666r$   c                 *    [        U R                  SS9$ NT)	is_binary)r   r   r7   s    r"   r   NegativeBinomial.logitse   s    tzzT::r$   c                 *    [        U R                  SS9$ rF   )r   r   r7   s    r"   r   NegativeBinomial.probsi   s    t{{d;;r$   c                 6    U R                   R                  5       $ r0   )r   r   r7   s    r"   param_shapeNegativeBinomial.param_shapem   s    {{!!r$   c                 j    [        U R                  [        R                  " U R                  * 5      SS9$ )NF)concentrationrater   )r   r   r'   r6   r   r7   s    r"   _gammaNegativeBinomial._gammaq   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_gradrQ   samplepoisson)r   rT   rP   s      r"   rV   NegativeBinomial.samplez   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_prob   s    !!%( $ 0 01<<[[L4
 !
ALL--!.
 \\$**U233ll3;'(ll4++,- 	 .99u$+S
 %88r$   )r   r   r   r   )NNNr0   )$__name__
__module____qualname____firstlineno____doc__r   greater_than_eqhalf_open_intervalrealarg_constraintsnonnegative_integersupportr   r   floatr   boolr   r)   r3   propertyr8   r?   rC   r
   r   r   r'   r(   rL   r   rQ   rV   rb   __static_attributes____classcell__)r!   s   @r"   r   r      s    #2215//S9""O
 --G
 #'#'(,C65=)C C  	C
  ~C 
C C:0 9f 9 9 Sf S S 7& 7 7 ; ; ; <v < < "UZZ " " 
 
 
 #(**, '
9 9r$   )typingr   r   r'   torch.nn.functionalnn
functionalr[   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.gammar   torch.distributions.utilsr	   r
   r   r   __all__r    r$   r"   <module>r~      s?    "     + 9 +  
~9| ~9r$   