a
    hD                     @   s   d dl mZmZ d dlZd dlmZ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 )    )OptionalUnionN)nanTensor)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   M/var/www/auris/lib/python3.9/site-packages/torch/distributions/kumaraswamy.py_moments   s    "r   c                       s   e Zd ZdZejejdZejZdZ	de
eef e
eef ee dd fddZd fdd		Zeed
ddZeed
ddZeed
ddZdd Z  ZS )r   aS  
    Samples from a Kumaraswamy distribution.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> 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concentration0TN)r   r   validate_argsreturnc                    st   t ||\| _| _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   )r   )exponentg      ?g      )locZscale)r   r   r   r
   r   Z	full_liker	   
reciprocalr   super__init__)selfr   r   r   Z	base_distZ
transforms	__class__r   r   r    2   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%   G   s    zKumaraswamy.expand)r   c                 C   s   t | j| jdS Nr   )r   r   r   r!   r   r   r   meanM   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   modeQ   s    zKumaraswamy.modec                 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   entropya   s    

zKumaraswamy.entropy)N)N)__name__
__module____qualname____doc__r   ZpositiveZarg_constraintsZunit_intervalZsupportZhas_rsampler   r   floatr   boolr    r%   propertyr)   r+   r.   r2   __classcell__r   r   r"   r   r      s*    

	)typingr   r   r   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   	