a
    MSic                     @   st   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 dlmZmZ dd	 ZG d
d deZdS )    N)nan)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narg1Z	log_value r   [/var/www/html/django/DPS/env/lib/python3.9/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 )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      )locscale)r   r   r   r   finfodtyper   	full_liker   
reciprocalr   superr   __init__)selfr   r   r   r   	base_dist
transforms	__class__r   r   r!   '   s    
zKumaraswamy.__init__c                    s<   |  t|}| j||_| j||_tt| j||dS )N)	_instance)_get_checked_instancer   r   expandr   r    )r"   batch_shaper'   newr%   r   r   r)   2   s    zKumaraswamy.expandc                 C   s   t | j| jdS Nr
   )r   r   r   r"   r   r   r   mean8   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   mode<   s    
zKumaraswamy.modec                 C   s   t | j| jdt| jd S )N   )r   r   r   r   powr.   r-   r   r   r   varianceD   s    zKumaraswamy.variancec                 C   sT   d| j   }d| j  }t| jd t }|||  t| j  t| j S r,   )r   r   r   r   digammar	   log)r"   t1t0ZH0r   r   r   entropyH   s    zKumaraswamy.entropy)N)N)__name__
__module____qualname____doc__r   positivearg_constraintsunit_intervalsupporthas_rsampler!   r)   propertyr.   r0   r3   r8   __classcell__r   r   r%   r   r      s   


r   )r   Z
torch._sixr   Ztorch.distributionsr   torch.distributions.uniformr   ,torch.distributions.transformed_distributionr   Ztorch.distributions.transformsr   r   torch.distributions.utilsr   r	   r   r   r   r   r   r   <module>   s   	