o
    +ôj  ã                   @   sZ   d dl mZ d dlZd dlmZ d dlmZ d dlmZ dgZ	dd„ Z
G d	d„ deƒZdS )
é    )ÚNumberN)Úconstraints)ÚExponentialFamily)Úbroadcast_allÚGammac                 C   s
   t  | ¡S ©N)ÚtorchÚ_standard_gamma)Úconcentration© r   úl/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torch/distributions/gamma.pyr	      s   
r	   c                       s¬   e Zd ZdZejejdœZejZdZ	dZ
edd„ ƒZedd„ ƒZed	d
„ ƒZd‡ fdd„	Zd‡ fdd„	Ze ¡ fdd„Zdd„ Zdd„ Zedd„ ƒZdd„ Zdd„ Z‡  ZS )r   aC  
    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 = 1 / scale of the distribution
            (often referred to as beta)
    ©r
   ÚrateTr   c                 C   s   | j | j S r   r   ©Úselfr   r   r   Úmean(   s   z
Gamma.meanc                 C   s   | j d | j jdd�S )Né   r   ©Úmin)r
   r   Úclampr   r   r   r   Úmode,   s   z
Gamma.modec                 C   s   | j | j d¡ S )Né   )r
   r   Úpowr   r   r   r   Úvariance0   ó   zGamma.varianceNc                    sN   t ||ƒ\| _| _t|tƒrt|tƒrt ¡ }n| j ¡ }tƒ j	||d� d S )N©Úvalidate_args)
r   r
   r   Ú
isinstancer   r   ÚSizeÚsizeÚsuperÚ__init__)r   r
   r   r   Úbatch_shape©Ú	__class__r   r   r!   4   s
   

zGamma.__init__c                    sR   |   t|¡}t |¡}| j |¡|_| j |¡|_tt|ƒj|dd� | j	|_	|S )NFr   )
Ú_get_checked_instancer   r   r   r
   Úexpandr   r    r!   Ú_validate_args)r   r"   Ú	_instanceÚnewr#   r   r   r&   <   s   
zGamma.expandc                 C   sD   |   |¡}t| j |¡ƒ| j |¡ }| ¡ jt |j	¡j
d� |S )Nr   )Ú_extended_shaper	   r
   r&   r   ÚdetachÚclamp_r   ÚfinfoÚdtypeÚtiny)r   Úsample_shapeÚshapeÚvaluer   r   r   ÚrsampleE   s   
ÿÿzGamma.rsamplec                 C   s`   t j|| jj| jjd�}| jr|  |¡ t  | j| j¡t  | jd |¡ | j|  t  	| j¡ S )N)r.   Údevicer   )
r   Ú	as_tensorr   r.   r4   r'   Ú_validate_sampleÚxlogyr
   Úlgamma©r   r2   r   r   r   Úlog_probO   s   
ÿþ
ýÿzGamma.log_probc                 C   s4   | j t | j¡ t | j ¡ d| j  t | j ¡  S )Ng      ð?)r
   r   Úlogr   r8   Údigammar   r   r   r   ÚentropyZ   s   
ÿ
þýÿzGamma.entropyc                 C   s   | j d | j fS ©Nr   r   r   r   r   r   Ú_natural_paramsb   r   zGamma._natural_paramsc                 C   s&   t  |d ¡|d t  | ¡  ¡  S r>   )r   r8   r;   Ú
reciprocal)r   ÚxÚyr   r   r   Ú_log_normalizerf   s   &zGamma._log_normalizerc                 C   s&   | j r|  |¡ tj | j| j| ¡S r   )r'   r6   r   ÚspecialÚgammaincr
   r   r9   r   r   r   Úcdfi   s   
z	Gamma.cdfr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚpositiveÚarg_constraintsÚnonnegativeÚsupportÚhas_rsampleÚ_mean_carrier_measureÚpropertyr   r   r   r!   r&   r   r   r3   r:   r=   r?   rC   rF   Ú__classcell__r   r   r#   r   r      s.    þ


	

)Únumbersr   r   Útorch.distributionsr   Útorch.distributions.exp_familyr   Útorch.distributions.utilsr   Ú__all__r	   r   r   r   r   r   Ú<module>   s    