U
    yh	                     @   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
   S/var/www/html/venv/lib/python3.8/site-packages/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   