U
    ©Ê¹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   úX/var/www/html/bwave/python/venv/lib/python3.8/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   aB  
    Creates a Gamma distribution parameterized by shape :attr:`concentration` and :attr:`rate`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterinistic")
        >>> 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   s    zGamma.varianceNc                    sN   t ||ƒ\| _| _t|tƒr0t|tƒr0t ¡ }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   )
Z_get_checked_instancer   r   r   r
   Úexpandr   r   r    Ú_validate_args)r   r!   Z	_instanceÚnewr"   r   r   r$   <   s    
zGamma.expandc                 C   sD   |   |¡}t| j |¡ƒ| j |¡ }| ¡ jt |j	¡j
d� |S )Nr   )Z_extended_shaper	   r
   r$   r   ÚdetachZclamp_r   ZfinfoÚdtypeZtiny)r   Z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   Z	as_tensorr   r(   r,   r%   Ú_validate_sampleZxlogyr
   Úlgamma©r   r*   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   r.   Zdigammar   r   r   r   ÚentropyZ   s    
ÿ
þýÿzGamma.entropyc                 C   s   | j d | j fS ©Nr   r   r   r   r   r   Ú_natural_paramsb   s    zGamma._natural_paramsc                 C   s&   t  |d ¡|d t  | ¡  ¡  S r3   )r   r.   r1   Z
reciprocal)r   ÚxÚyr   r   r   Ú_log_normalizerf   s    zGamma._log_normalizerc                 C   s&   | j r|  |¡ tj | j| j| ¡S r   )r%   r-   r   ÚspecialZgammaincr
   r   r/   r   r   r   Úcdfi   s    
z	Gamma.cdf)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZnonnegativeZsupportZhas_rsampleZ_mean_carrier_measureÚpropertyr   r   r   r    r$   r   r   r+   r0   r2   r4   r7   r9   Ú__classcell__r   r   r"   r   r      s,   þ


	

)Únumbersr   r   Ztorch.distributionsr   Ztorch.distributions.exp_familyr   Ztorch.distributions.utilsr   Ú__all__r	   r   r   r   r   r   Ú<module>   s   