U
    9%e                     @   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/Darija-Ai-API/env/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   	