
    ȅi3                         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S\\-  S	\S-  S
\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\R4                  4S j5       r\S\4S j5       r\R4                  " 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        OPUc  [        S5      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.zlogits is unexpectedly Noner   )
ValueErrorr   r   r   type_asAssertionErrorr   _paramsizesuper__init__)selfr   r   r   r   batch_shape	__class__s         _/home/james-whalen/.local/lib/python3.13/site-packages/torch/distributions/negative_binomial.pyr   NegativeBinomial.__init__+   s     TMv~.M  
 k1	 
#//77

CD~$%BCC
 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.expandK   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._newY   s    {{///r#   c                 \    U R                   [        R                  " U R                  5      -  $ r/   )r   r&   expr   r   s    r!   meanNegativeBinomial.mean\   s     %))DKK"888r#   c                     U R                   S-
  U R                  R                  5       -  R                  5       R	                  SS9$ )N   r   )min)r   r   r5   floorclampr6   s    r!   modeNegativeBinomial.mode`   s:    !!A%)::AACIIcIRRr#   c                 ^    U R                   [        R                  " U R                  * 5      -  $ r/   )r7   r&   sigmoidr   r6   s    r!   varianceNegativeBinomial.varianced   s     yy5==$++666r#   c                 *    [        U R                  SS9$ NT)	is_binary)r
   r   r6   s    r!   r   NegativeBinomial.logitsh   s    tzzT::r#   c                 *    [        U R                  SS9$ rE   )r	   r   r6   s    r!   r   NegativeBinomial.probsl   s    t{{d;;r#   c                 6    U R                   R                  5       $ r/   )r   r   r6   s    r!   param_shapeNegativeBinomial.param_shapep   s    {{!!r#   c                 j    [        U R                  [        R                  " U R                  * 5      SS9$ )NF)concentrationrater   )r   r   r&   r5   r   r6   s    r!   _gammaNegativeBinomial._gammat   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_gradrP   samplepoisson)r   rS   rO   s      r!   rU   NegativeBinomial.sample}   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   )NNNr/   )"__name__
__module____qualname____firstlineno____doc__r   greater_than_eqhalf_open_intervalrealarg_constraintsnonnegative_integersupportr   floatboolr   r(   r2   propertyr7   r>   rB   r   r   r   r&   r'   rK   r   rP   rU   ra   __static_attributes____classcell__)r    s   @r!   r   r      s     #2215//S9""O
 --G
  $ $%)Ce^C }C 	C
 d{C 
C C@0 9f 9 9 Sf S S 7& 7 7 ; ; ; <v < < "UZZ " " 
 
 
 #(**, '
9 9r#   )r&   torch.nn.functionalnn
functionalrZ   r   torch.distributionsr    torch.distributions.distributionr   torch.distributions.gammar   torch.distributions.utilsr   r   r	   r
   __all__r    r#   r!   <module>r|      s>        + 9 +  
B9| B9r#   