a
    –¥»ao  ã                   @   sh   d dl Z d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZ dd„ ZG d	d
„ d
eƒZdS )é    N)Úconstraints)ÚUniform)ÚTransformedDistribution)ÚAffineTransformÚPowerTransform)Úbroadcast_allÚeuler_constantc                 C   s<   d||   }t  |¡t  |¡ t  || ¡ }|t  |¡ S )zE
    Computes nth moment of Kumaraswamy using using torch.lgamma
    é   )ÚtorchÚlgammaÚexp)ÚaÚbÚnZarg1Z	log_value© r   úY/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/torch/distributions/kumaraswamy.pyÚ_moments	   s    "r   c                       sh   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	d
„ ƒZedd„ ƒZdd„ Z‡  ZS )ÚKumaraswamya  
    Samples from a Kumaraswamy distribution.

    Example::

        >>> m = Kumaraswamy(torch.tensor([1.0]), torch.tensor([1.0]))
        >>> m.sample()  # sample from a Kumaraswamy distribution with concentration alpha=1 and beta=1
        tensor([ 0.1729])

    Args:
        concentration1 (float or Tensor): 1st concentration parameter of the distribution
            (often referred to as alpha)
        concentration0 (float or Tensor): 2nd concentration parameter of the distribution
            (often referred to as beta)
    )Úconcentration1Úconcentration0TNc                    s†   t ||ƒ\| _| _t | jj¡}tt | jd¡t | jd¡|d�}t| j 	¡ d�t
ddd�t| j 	¡ d�g}tt| ƒj|||d� d S )Nr   r	   )Úvalidate_args)Úexponentg      ð?g      ð¿)ÚlocZscale)r   r   r   r
   ÚfinfoZdtyper   Z	full_liker   Ú
reciprocalr   Úsuperr   Ú__init__)Úselfr   r   r   r   Z	base_distZ
transforms©Ú	__class__r   r   r   &   s    þ
þzKumaraswamy.__init__c                    s<   |   t|¡}| j |¡|_| j |¡|_tt| ƒj||d�S )N)Ú	_instance)Z_get_checked_instancer   r   Úexpandr   r   )r   Zbatch_shaper    Únewr   r   r   r!   1   s    zKumaraswamy.expandc                 C   s   t | j| jdƒS ©Nr	   )r   r   r   ©r   r   r   r   Úmean7   s    zKumaraswamy.meanc                 C   s   t | j| jdƒt | jd¡ S )Né   )r   r   r   r
   Úpowr%   r$   r   r   r   Úvariance;   s    zKumaraswamy.variancec                 C   sT   d| j  ¡  }d| j ¡  }t | jd ¡t }|||  t | j ¡ t | j¡ S r#   )r   r   r   r
   Zdigammar   Úlog)r   Út1Út0ZH0r   r   r   Úentropy?   s    zKumaraswamy.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZunit_intervalZsupportZhas_rsampler   r!   Úpropertyr%   r(   r,   Ú__classcell__r   r   r   r   r      s   

r   )r
   Ztorch.distributionsr   Ztorch.distributions.uniformr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   Ztorch.distributions.utilsr   r   r   r   r   r   r   r   Ú<module>   s   	