
    }YhD                         d dl mZmZ d dl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 dgZd	 Z G d
 de          ZdS )    )OptionalUnionN)Tensor)constraints)ExponentialFamily)broadcast_all)_Number_sizeGammac                 *    t          j        |           S N)torch_standard_gamma)concentrations    k/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/torch/distributions/gamma.pyr   r      s     ///    c            	       j    e Zd ZdZej        ej        dZej        ZdZ	dZ
edefd            Zedefd            Zedefd            Z	 dd
eeef         deeef         dee         dd	f fdZd fd	Z ej                    fdedefdZd Zd Zedeeef         fd            Zd Zd Z xZ S )r   aS  
    Creates a Gamma distribution parameterized by shape :attr:`concentration` and :attr:`rate`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0]))
        >>> m.sample()  # Gamma distributed with concentration=1 and rate=1
        tensor([ 0.1046])

    Args:
        concentration (float or Tensor): shape parameter of the distribution
            (often referred to as alpha)
        rate (float or Tensor): rate parameter of the distribution
            (often referred to as beta), rate = 1 / scale
    r   rateTr   returnc                      | j         | j        z  S r   r   selfs    r   meanz
Gamma.mean-   s    !DI--r   c                 N    | j         dz
  | j        z                      d          S )N   r   min)r   r   clampr   s    r   modez
Gamma.mode1   s(    #a'494;;;BBBr   c                 F    | j         | j                            d          z  S )N   )r   r   powr   s    r   variancezGamma.variance5   s    !DIMM!$4$444r   Nr   r   validate_argsc                 6   t          ||          \  | _        | _        t          |t                    r)t          |t                    rt          j                    }n| j                                        }t                      	                    ||           d S )Nr%   )
r   r   r   
isinstancer	   r   Sizesizesuper__init__)r   r   r   r%   batch_shape	__class__s        r   r,   zGamma.__init__9   s     )6mT(J(J%DImW-- 	4*T72K2K 	4*,,KK,1133KMBBBBBr   c                 N   |                      t          |          }t          j        |          }| j                            |          |_        | j                            |          |_        t          t          |                              |d           | j	        |_	        |S )NFr'   )
_get_checked_instancer   r   r)   r   expandr   r+   r,   _validate_args)r   r-   	_instancenewr.   s       r   r1   zGamma.expandF   s    ((	::j-- .55kBB9##K00eS"";e"DDD!0
r   sample_shapec                 <   |                      |          }t          | j                            |                    | j                            |          z  }|                                                    t          j        |j	                  j
                   |S )Nr   )_extended_shaper   r   r1   r   detachclamp_r   finfodtypetiny)r   r5   shapevalues       r   rsamplezGamma.rsampleO   s    $$\22 2 9 9% @ @AADIDTDTE
 E
 
 	EK((- 	 	
 	
 	
 r   c                 T   t          j        || j        j        | j        j                  }| j        r|                     |           t          j        | j        | j                  t          j        | j        dz
  |          z   | j        |z  z
  t          j	        | j                  z
  S )N)r;   devicer   )
r   	as_tensorr   r;   rA   r2   _validate_samplexlogyr   lgammar   r>   s     r   log_probzGamma.log_probY   s    TY_TYEUVVV 	)!!%(((K*DI66k$,q0%889i%  l4-../	
r   c                     | j         t          j        | j                  z
  t          j        | j                   z   d| j         z
  t          j        | j                   z  z   S )Ng      ?)r   r   logr   rE   digammar   s    r   entropyzGamma.entropyd   s[    i	""#l4-../ T''5=9K+L+LLM	
r   c                 &    | j         dz
  | j         fS Nr   r   r   s    r   _natural_paramszGamma._natural_paramsl   s    "Q&
33r   c                     t          j        |dz             |dz   t          j        |                                           z  z   S rM   )r   rE   rI   
reciprocal)r   xys      r   _log_normalizerzGamma._log_normalizerp   s8    |AE""a!euy!,,../I/I%IIIr   c                     | j         r|                     |           t          j                            | j        | j        |z            S r   )r2   rC   r   specialgammaincr   r   rF   s     r   cdfz	Gamma.cdfs   sC     	)!!%(((}%%d&8$)e:KLLLr   r   )!__name__
__module____qualname____doc__r   positivearg_constraintsnonnegativesupporthas_rsample_mean_carrier_measurepropertyr   r   r    r$   r   floatr   boolr,   r1   r   r)   r
   r?   rG   rK   tuplerN   rS   rW   __classcell__)r.   s   @r   r   r      s        $ %-$ O %GK.f . . . X. Cf C C C XC 5& 5 5 5 X5 )-	C CVU]+C FEM"C  ~	C
 
C C C C C C      -7EJLL  E V    	
 	
 	

 
 
 4vv~!6 4 4 4 X4J J JM M M M M M Mr   )typingr   r   r   r   torch.distributionsr   torch.distributions.exp_familyr   torch.distributions.utilsr   torch.typesr	   r
   __all__r   r    r   r   <module>rn      s    " " " " " " " "        + + + + + + < < < < < < 3 3 3 3 3 3 & & & & & & & & )0 0 0cM cM cM cM cM cM cM cM cM cMr   