
    Vh
                     d    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e      Zy)	    N)Tensor)constraints)Gamma)TransformedDistribution)PowerTransformInverseGammac                        e Zd ZdZej
                  ej
                  dZej
                  ZdZd fd	Z	d fd	Z
edefd       Zedefd       Zedefd	       Zedefd
       Zedefd       Zd Z x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rateTc                     t        |||      }|j                  j                  d       }t        |   |t        |      |       y )N)validate_args )r   r   new_onessuper__init__r   )selfr
   r   r   	base_distneg_one	__class__s         Q/home/dcms/DCMS/lib/python3.12/site-packages/torch/distributions/inverse_gamma.pyr   zInverseGamma.__init__*   sF    -]K	>>**2..~g.m 	 	
    c                 R    | j                  t        |      }t        |   ||      S )N)	_instance)_get_checked_instancer   r   expand)r   batch_shaper   newr   s       r   r   zInverseGamma.expand1   s(    ((yAw~kS~99r   returnc                 .    | j                   j                  S N)r   r
   r   s    r   r
   zInverseGamma.concentration5   s    ~~+++r   c                 .    | j                   j                  S r    )r   r   r!   s    r   r   zInverseGamma.rate9   s    ~~"""r   c                     | j                   | j                  dz
  z  }t        j                  | j                  dkD  |t        j                        S N   )r   r
   torchwhereinfr   results     r   meanzInverseGamma.mean=   s=    d00145{{4--16599EEr   c                 :    | j                   | j                  dz   z  S r$   )r   r
   r!   s    r   modezInverseGamma.modeB   s    yyD..233r   c                     | j                   j                         | j                  dz
  j                         | j                  dz
  z  z  }t        j                  | j                  dkD  |t        j
                        S )Nr%      )r   squarer
   r&   r'   r(   r)   s     r   variancezInverseGamma.varianceF   sd    !!#!#++-1C1Ca1GH
 {{4--16599EEr   c                     | j                   | j                  j                         z   | j                   j                         z   d| j                   z   | j                   j	                         z  z
  S r$   )r
   r   loglgammadigammar!   s    r   entropyzInverseGamma.entropyM   sc    iimmo  '')* 4%%%););)C)C)EEF	
r   r    )__name__
__module____qualname____doc__r   positivearg_constraintssupporthas_rsampler   r   propertyr   r
   r   r+   r-   r1   r6   __classcell__)r   s   @r   r   r      s    , %--$$O ""GK
: ,v , , #f # # Ff F F 4f 4 4 F& F F
r   )r&   r   torch.distributionsr   torch.distributions.gammar   ,torch.distributions.transformed_distributionr   torch.distributions.transformsr   __all__r   r   r   r   <module>rF      s0      + + P 9 
F
* F
r   