U
    ©Ê¹j¦  ã                   @   sz   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
 d dlmZmZ dgZd	d
„ ZG dd„ deƒZdS )é    N)Únan)Úconstraints)ÚTransformedDistribution)ÚAffineTransformÚPowerTransform)ÚUniform)Úbroadcast_allÚeuler_constantÚKumaraswamyc                 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   ú^/var/www/html/bwave/python/venv/lib/python3.8/site-packages/torch/distributions/kumaraswamy.pyÚ_moments   s    "r   c                       st   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edd„ ƒZdd„ Z‡  ZS )r
   aR  
    Samples from a Kumaraswamy distribution.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterinistic")
        >>> 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ƒ j|||d� d S )Nr   r   )Úvalidate_args)Úexponentg      ð?g      ð¿)ÚlocÚscale)r   r   r   r   ÚfinfoZdtyper   Z	full_liker   Ú
reciprocalr   ÚsuperÚ__init__)Úselfr   r   r   r   Z	base_distZ
transforms©Ú	__class__r   r   r   -   s     ÿý
ýzKumaraswamy.__init__c                    s8   |   t|¡}| j |¡|_| j |¡|_tƒ j||d�S )N)Ú	_instance)Z_get_checked_instancer
   r   Úexpandr   r   )r   Zbatch_shaper"   Únewr    r   r   r#   >   s    zKumaraswamy.expandc                 C   s   t | j| jdƒS ©Nr   )r   r   r   ©r   r   r   r   ÚmeanD   s    zKumaraswamy.meanc                 C   sH   | j  ¡ | j   ¡  | j  | j  ¡  }t|| j dk | jdk B < | ¡ S r%   )r   r   Úlog1pr   r   r   )r   Zlog_moder   r   r   ÚmodeH   s    ÿÿzKumaraswamy.modec                 C   s   t | j| jdƒt | jd¡ S )Né   )r   r   r   r   Úpowr'   r&   r   r   r   ÚvarianceR   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   ÚentropyX   s    ÿ
þ
ýÿzKumaraswamy.entropy)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZpositiveZarg_constraintsZunit_intervalZsupportZhas_rsampler   r#   Úpropertyr'   r)   r,   r0   Ú__classcell__r   r   r    r   r
      s   þ

	
)r   r   Ztorch.distributionsr   Z,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   Ztorch.distributions.uniformr   Ztorch.distributions.utilsr   r	   Ú__all__r   r
   r   r   r   r   Ú<module>   s   	