o
    hD                     @   sz   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mZ dgZd	d
 ZG dd deZdS )    )OptionalUnionN)Tensor)constraints)ExponentialFamily)broadcast_all)_Number_sizeGammac                 C   s
   t | S N)torch_standard_gamma)concentration r   _/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/torch/distributions/gamma.pyr      s   
r   c                	       s   e Zd ZdZejejdZejZdZ	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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 fdedefddZdd Zdd Zedeeef fddZdd Zdd  Z  Z S )"r
   aS  
    Creates a Gamma distribution parameterized by shape :attr:`concentration` and :attr:`rate`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Gamma(torch.tensor([1.0]), torch.tensor([1.0]))
        >>> m.sample()  # Gamma distributed with concentration=1 and rate=1
        tensor([ 0.1046])

    Args:
        concentration (float or Tensor): shape parameter of the distribution
            (often referred to as alpha)
        rate (float or Tensor): rate parameter of the distribution
            (often referred to as beta), rate = 1 / scale
    r   rateTr   returnc                 C   s   | j | j S r   r   selfr   r   r   mean-   s   z
Gamma.meanc                 C   s   | j d | j jddS )N   r   min)r   r   clampr   r   r   r   mode1   s   z
Gamma.modec                 C   s   | j | jd S )N   )r   r   powr   r   r   r   variance5      zGamma.varianceNr   r   validate_argsc                    sN   t ||\| _| _t|trt|trt }n| j }t j	||d d S )Nr    )
r   r   r   
isinstancer   r   Sizesizesuper__init__)r   r   r   r    batch_shape	__class__r   r   r&   9   s
   

zGamma.__init__c                    sR   |  t|}t|}| j||_| j||_tt|j|dd | j	|_	|S )NFr!   )
Z_get_checked_instancer
   r   r#   r   expandr   r%   r&   _validate_args)r   r'   Z	_instancenewr(   r   r   r*   F   s   
zGamma.expandsample_shapec                 C   sD   |  |}t| j|| j| }| jt|j	j
d |S )Nr   )Z_extended_shaper   r   r*   r   detachZclamp_r   ZfinfodtypeZtiny)r   r-   shapevaluer   r   r   rsampleO   s   
zGamma.rsamplec                 C   s`   t j|| jj| jjd}| jr| | t | j| jt | jd | | j|  t 	| j S )N)r/   devicer   )
r   Z	as_tensorr   r/   r3   r+   _validate_sampleZxlogyr   lgammar   r1   r   r   r   log_probY   s   

zGamma.log_probc                 C   s4   | j t| j t| j  d| j  t| j   S )Ng      ?)r   r   logr   r5   Zdigammar   r   r   r   entropyd   s   

zGamma.entropyc                 C   s   | j d | j fS Nr   r   r   r   r   r   _natural_paramsl   r   zGamma._natural_paramsc                 C   s&   t |d |d t |    S r:   )r   r5   r8   Z
reciprocal)r   xyr   r   r   _log_normalizerp   s   &zGamma._log_normalizerc                 C   s&   | j r| | tj| j| j| S r   )r+   r4   r   ZspecialZgammaincr   r   r6   r   r   r   cdfs   s   
z	Gamma.cdfr   )!__name__
__module____qualname____doc__r   ZpositiveZarg_constraintsZnonnegativeZsupportZhas_rsampleZ_mean_carrier_measurepropertyr   r   r   r   r   floatr   boolr&   r*   r   r#   r	   r2   r7   r9   tupler;   r>   r?   __classcell__r   r   r(   r   r
      s@    

	
)typingr   r   r   r   Ztorch.distributionsr   Ztorch.distributions.exp_familyr   Ztorch.distributions.utilsr   Ztorch.typesr   r	   __all__r   r
   r   r   r   r   <module>   s   