o
    h
                     @   sn   d dl mZmZ 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 )
    )OptionalUnionN)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ef deeef dee 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   Znew_onessuper__init__r   )selfr
   r   r   r   Zneg_one	__class__r   g/home/www/facesmatcher.com/frenv_anti/lib/python3.10/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   9   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   A   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   meanE   s   zInverseGamma.meanc                 C   s   | j | jd  S r   )r   r
   r   r   r   r   modeJ   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   varianceN   s   zInverseGamma.variancec                 C   s.   | j | j  | j   d| j  | j    S r   )r
   r   loglgammaZdigammar   r   r   r   entropyU   s   zInverseGamma.entropyr   )__name__
__module____qualname____doc__r   ZpositiveZarg_constraintsZsupportZhas_rsampler   __annotations__r   r   floatr   boolr   r   propertyr
   r   r$   r%   r'   r*   __classcell__r   r   r   r   r	      s<   
 

)typingr   r   r   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   