o
    ei
                     @   s^   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	 dgZ
G dd deZdS )	    N)Tensor)constraints)Gamma)TransformedDistribution)PowerTransformInverseGammac                	       s   e Zd ZU dZejejdZejZdZe	e
d< 	ddeeB deeB dedB d	df fd
dZd fdd	Zed	efddZed	efddZed	efddZed	efddZed	ef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rateT	base_distNr   r	   validate_argsreturnc                    s6   t |||d}|jd }t j|t||d d S )N)r    )r   r	   new_onessuper__init__r   )selfr   r	   r   r
   neg_one	__class__r   k/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/distributions/inverse_gamma.pyr   .   s
   

zInverseGamma.__init__c                    s   |  t|}t j||dS )N)	_instance)_get_checked_instancer   r   expand)r   batch_shaper   newr   r   r   r   :   s   zInverseGamma.expandc                 C      | j jS N)r
   r   r   r   r   r   r   >      zInverseGamma.concentrationc                 C   r   r   )r
   r	   r   r   r   r   r	   B   r   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   meanF   s   zInverseGamma.meanc                 C   s   | j | jd  S r   )r	   r   r   r   r   r   modeK   s   zInverseGamma.modec                 C   s8   | j  | jd  | jd   }t| jdk|tjS )Nr       )r	   squarer   r!   r"   r#   r$   r   r   r   varianceO   s   zInverseGamma.variancec                 C   s.   | j | j  | j   d| j  | j    S r   )r   r	   loglgammadigammar   r   r   r   entropyV   s   zInverseGamma.entropyr   )__name__
__module____qualname____doc__r   positivearg_constraintssupporthas_rsampler   __annotations__r   floatboolr   r   propertyr   r	   r&   r'   r*   r.   __classcell__r   r   r   r   r      s<   
 )r!   r   torch.distributionsr   torch.distributions.gammar   ,torch.distributions.transformed_distributionr   torch.distributions.transformsr   __all__r   r   r   r   r   <module>   s   