o
    h
                     @   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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	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rateTNc                    s6   t |||d}|jd }t j|t||d d S )N)validate_args )r   r	   new_onessuper__init__r   )selfr   r	   r
   	base_distneg_one	__class__r   u/var/www/html/construction_image-detection-poc/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   1   s   zInverseGamma.expandreturnc                 C      | j jS N)r   r   r   r   r   r   r   5      zInverseGamma.concentrationc                 C   r   r   )r   r	   r   r   r   r   r	   9   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   mean=   s   zInverseGamma.meanc                 C   s   | j | jd  S r   )r	   r   r   r   r   r   modeB   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   varianceF   s   zInverseGamma.variancec                 C   s.   | j | j  | j   d| j  | j    S r   )r   r	   loglgammadigammar   r   r   r   entropyM   s   zInverseGamma.entropyr   )__name__
__module____qualname____doc__r   positivearg_constraintssupporthas_rsampler   r   propertyr   r   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   