
    9j
                     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U dZej
                  ej
                  dZej
                  ZdZe	e
d<   	 ddeez  deez  dedz  d	df 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rateT	base_distNr
   r   validate_argsreturnc                     t        |||      }|j                  j                  d       }t        |   |t        |      |       y )N)r    )r   r   new_onessuper__init__r   )selfr
   r   r   r   neg_one	__class__s         a/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/distributions/inverse_gamma.pyr   zInverseGamma.__init__.   sH     -]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.expand:   s(    ((yAw~kS~99r   c                 .    | j                   j                  S N)r   r
   r   s    r   r
   zInverseGamma.concentration>   s    ~~+++r   c                 .    | j                   j                  S r    )r   r   r!   s    r   r   zInverseGamma.rateB   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.meanF   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.modeK   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.varianceO   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.entropyV   sc    iimmo  '')* 4%%%););)C)C)EEF	
r   r    )__name__
__module____qualname____doc__r   positivearg_constraintssupporthas_rsampler   __annotations__r   floatboolr   r   propertyr
   r   r+   r-   r1   r6   __classcell__)r   s   @r   r   r      s   , %--$$O
 ""GK &*	

~

 un

 d{	


 


: ,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>rI      s2      + + P 9 
N
* N
r   