U
    D‹ÑhÉ	  ã                   @   sR   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gZ	G dd„ deƒZ
dS )é    N)Úconstraints)ÚGamma)ÚTransformedDistribution)ÚPowerTransformÚInverseGammac                       sŒ   e Zd ZdZejejdœZejZdZd‡ fdd„	Z	d‡ fdd„	Z
ed	d
„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Z‡  ZS )r   a€  
    Creates an inverse gamma distribution parameterized by :attr:`concentration` and :attr:`rate`
    where::

        X ~ Gamma(concentration, rate)
        Y = 1 / X ~ InverseGamma(concentration, rate)

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterinistic")
        >>> m = InverseGamma(torch.tensor([2.0]), torch.tensor([3.0]))
        >>> m.sample()
        tensor([ 1.2953])

    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)
    )ÚconcentrationÚrateTNc                    s6   t |||d�}|j d¡ }tƒ j|t|ƒ|d� d S )N)Úvalidate_args© )r   r   Znew_onesÚsuperÚ__init__r   )Úselfr   r   r	   Ú	base_distZneg_one©Ú	__class__r
   úO/tmp/user/2202/pip-unpacked-wheel-bf9o3bgk/torch/distributions/inverse_gamma.pyr   (   s      ÿzInverseGamma.__init__c                    s   |   t|¡}tƒ j||d�S )N)Ú	_instance)Z_get_checked_instancer   r   Úexpand)r   Zbatch_shaper   Únewr   r
   r   r   /   s    zInverseGamma.expandc                 C   s   | j jS ©N)r   r   ©r   r
   r
   r   r   3   s    zInverseGamma.concentrationc                 C   s   | j jS r   )r   r   r   r
   r
   r   r   7   s    zInverseGamma.ratec                 C   s&   | j | jd  }t | jdk|tj¡S ©Né   )r   r   ÚtorchÚwhereÚinf©r   Úresultr
   r
   r   Úmean;   s    zInverseGamma.meanc                 C   s   | j | jd  S r   )r   r   r   r
   r
   r   Úmode@   s    zInverseGamma.modec                 C   s8   | j  ¡ | jd  ¡ | jd   }t | jdk|tj¡S )Nr   é   )r   Zsquarer   r   r   r   r   r
   r
   r   ÚvarianceD   s    ÿzInverseGamma.variancec                 C   s.   | j | j ¡  | j  ¡  d| j  | j  ¡   S r   )r   r   ÚlogÚlgammaZdigammar   r
   r
   r   ÚentropyK   s    ÿþýÿzInverseGamma.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZsupportZhas_rsampler   r   Úpropertyr   r   r   r   r!   r$   Ú__classcell__r
   r
   r   r   r      s&   þ




)r   Ztorch.distributionsr   Ztorch.distributions.gammar   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   Ú__all__r   r
   r
   r
   r   Ú<module>   s   