
    }Yh                         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dS )
    )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j        fd            Zedefd            Z ej                    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          |Bt          ||          \  | _        | _        | j                            | j                  | _        nE|J t          ||          \  | _        | _        | j                            | j                  | _        || j        n| j        | _        | j                                        }t                      	                    ||           d S )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         w/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/distributions/negative_binomial.pyr   zNegativeBinomial.__init__+   s    TMv~..M    k511 
#/77
CCD%%% k622 #/77DDD$)$5djj4;k&&((MBBBBB    c                    |                      t          |          }t          j        |          }| j                            |          |_        d| j        v r+| j                            |          |_        |j        |_        d| j        v r+| 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    (()99EEj--*11+>>dm##
))+66CICJt}$$++K88CJCJ$$--k-OOO!0
r"   c                 &     | j         j        |i |S N)r   r+   )r   argskwargss      r!   _newzNegativeBinomial._newV   s    t{////r"   c                 D    | j         t          j        | j                  z  S r-   )r   r%   expr   r   s    r!   meanzNegativeBinomial.meanY   s    %)DK"8"888r"   c                     | j         dz
  | j                                        z                                                      d          S )N   r   )min)r   r   r2   floorclampr3   s    r!   modezNegativeBinomial.mode]   s>    !A%):)::AACCIIcIRRRr"   c                 F    | j         t          j        | j                   z  S r-   )r4   r%   sigmoidr   r3   s    r!   variancezNegativeBinomial.variancea   s    y5=$+6666r"   c                 .    t          | j        d          S NT)	is_binary)r   r   r3   s    r!   r   zNegativeBinomial.logitse   s    tzT::::r"   c                 .    t          | j        d          S r?   )r   r   r3   s    r!   r   zNegativeBinomial.probsi   s    t{d;;;;r"   c                 4    | j                                         S r-   )r   r   r3   s    r!   param_shapezNegativeBinomial.param_shapem   s    {!!!r"   c                 `    t          | j        t          j        | j                   d          S )NF)concentrationrater   )r   r   r%   r2   r   r3   s    r!   _gammazNegativeBinomial._gammaq   s5     *DK<((
 
 
 	
r"   c                     t          j                    5  | j                            |          }t          j        |          cd d d            S # 1 swxY w Y   d S )N)sample_shape)r%   no_gradrG   samplepoisson)r   rI   rF   s      r!   rK   zNegativeBinomial.samplez   s    ]__ 	' 	';%%<%@@D=&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   /AAAc                    | j         r|                     |           | j        t          j        | j                   z  |t          j        | j                  z  z   }t          j        | j        |z              t          j        d|z             z   t          j        | j                  z   }|                    | 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     	)!!%((( $ 01<[L4
 4
 !
AL---!.
 \$*U2333l3;''(l4+,,- 	 .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{2155//S99" O
 -G
 #'#'(,C C65=)C C  	C
  ~C 
C C C C C C:     0 0 0 9f 9 9 9 X9 Sf S S S XS 7& 7 7 7 X7 ; ; ; ; ]; <v < < < ]< "UZ " " " X" 
 
 
 
 ]
 #-%*,, ' ' ' '
9 9 9 9 9 9 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 9 9 9 9 + + + + + +            
~9 ~9 ~9 ~9 ~9| ~9 ~9 ~9 ~9 ~9r"   