
    zj;                        d dl mZ d dlmZ d dlZd dlZd dlmZ d dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ erd d	lmZ d d
lmZmZ  G d dej                  ZdS )    )annotations)TYPE_CHECKINGN)distribution)
check_typeconvert_dtype)Variable)exponential_family)in_dynamic_mode)Sequence)Tensordtypec                       e Zd ZU dZded<   ded<   d fdZedd	            Zedd
            Zg fddZ	g fddZ
ddZddZddZddZddZddZed d            Zd!dZ xZS )"Exponentiala  
    Exponential distribution parameterized by :attr:`rate`.

    The probability density function (pdf) is

    .. math::

        f(x; \theta) =  \theta e^{- \theta x },  (x \ge 0) $$

    In the above equation:

    * :math:`rate = \theta`: is the rate parameter.

    Args:
        rate (float|Tensor): Rate parameter. The value of rate must be positive.

    Example:
        .. code-block:: python

            >>> import paddle

            >>> expon = paddle.distribution.Exponential(paddle.to_tensor([0.5]))
            >>> print(expon.mean)
            Tensor(shape=[1], dtype=float32, place=Place(gpu:0), stop_gradient=True,
                   [2.])

            >>> print(expon.variance)
            Tensor(shape=[1], dtype=float32, place=Place(gpu:0), stop_gradient=True,
                   [4.])

            >>> print(expon.entropy())
            Tensor(shape=[1], dtype=float32, place=Place(gpu:0), stop_gradient=True,
                   [1.69314718])
    r   rater   float | TensorreturnNonec                   t                      s.t          |dt          t          t          j        j        fd           |                     |          r!|| _        t          |j
                  | _
        n4|                     |          \  | _        t	          j                    | _
        t                                          | j        j                   d S )Nr   r   )r
   r   floatr   paddlepirValue_validate_argsr   r   r   
_to_tensorget_default_dtypesuper__init__shape)selfr   	__class__s     o/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/paddle/distribution/exponential.pyr   zExponential.__init__I   s       	&*"23	   t$$ 	4DI&tz22DJJ//$//KTY133DJ)))))    c                4    | j                                         S )z\Mean of exponential distribution.

        Returns:
            Tensor: mean value.
        )r   
reciprocalr   s    r!   meanzExponential.mean\   s     y##%%%r"   c                6    | j                             d          S )zdVariance of exponential distribution.

        Returns:
            Tensor: variance value.
        )r   powr%   s    r!   variancezExponential.variancee   s     y}}R   r"   r   Sequence[int]c                    t          j                    5  |                     |          cddd           S # 1 swxY w Y   dS )zGenerate samples of the specified shape.

        Args:
            shape (Sequence[int], optional): Shape of the generated samples.

        Returns:
            Tensor, A tensor with prepended dimensions shape. The data type is float32.
        N)r   no_gradrsample)r   r   s     r!   samplezExponential.samplen   s     ^ 	' 	'<<&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's   6::c                   t           j                            | |          }t          j        |t          t          j        d          j                  d| j	        j
                  }t          j        |           | j	        z  S )a  Generate reparameterized samples of the specified shape.

        Args:
            shape (Sequence[int], optional): Shape of the generated samples.

        Returns:
            Tensor: A tensor with prepended dimensions shape. The data type is float32.
        )sample_shapefloat32)r         ?)r   minmaxr   )r   Distribution_extend_shaper   uniformr   npfinfotinyr   r   log)r   r   r8   s      r!   r.   zExponential.rsamplez   s     )77u 8 
 
 .bhY///455)/	
 
 
 
7###di//r"   valuec                L    | j         t          j        | j          |z            z  S )a	  Probability density function evaluated at value.

        .. math::

            { f(x; \theta) = \theta e^{- \theta x}, (x \ge 0 ) }

        Args:
            value (float|Tensor): Value to be evaluated.

        Returns:
            Tensor: Probability.
        )r   r   expr   r=   s     r!   probzExponential.prob   s$     y6:tyj5&89999r"   c                J    t          j        | j                  | j        |z  z
  S )zLog probability density function evaluated at value.

        Args:
            value (float|Tensor): Value to be evaluated

        Returns:
            Tensor: Log probability.
        r   r<   r   r@   s     r!   log_probzExponential.log_prob   s"     z$)$$ty5'888r"   c                :    dt          j        | j                  z
  S )z\Entropy of exponential distribution.

        Returns:
            Tensor: Entropy.
        r3   rC   r%   s    r!   entropyzExponential.entropy   s     VZ	****r"   c                B    dt          j        | j         |z            z
  S )aH  Cumulative distribution function(CDF) evaluated at value.

        .. math::


            { cdf(x; \theta) = 1 - e^{- \theta x }, (x \ge 0) }

        Args:
            value (float|Tensor): Input value to evaluate the cumulative probability.

        Returns:
            Tensor: The evaluated cumulative probability.
        r3   )r   r?   r   r@   s     r!   cdfzExponential.cdf   s"     VZ
U 23333r"   c                >    t          j        |            | j        z  S )aO  Inverse cumulative distribution function(CDF) evaluated at value.

        .. math::


            { icdf(x; \theta) = -\frac{ 1 }{ \theta } ln(1 - x), (0 < x < 1) }

        Args:
            value (float|Tensor): Input probability to evaluate the quantile.

        Returns:
            Tensor: The evaluated quantile value.
        )r   log1pr   r@   s     r!   icdfzExponential.icdf   s      eV$$$ty00r"   otherc                    t          |t                    st          dt          |                     |j        | j        z  }t          j        |           }||z   dz
  S )zThe KL-divergence between two exponential distributions.

        Args:
            other (Exponential): instance of Exponential.

        Returns:
            Tensor: kl-divergence between two exponential distributions.
        z/Expected type of other is Exponential, but got    )
isinstancer   	TypeErrortyper   r   r<   )r   rL   
rate_ratiot1s       r!   kl_divergencezExponential.kl_divergence   sj     %-- 	O$u++OO   Z$)+
j$$$J""r"   tuple[Tensor]c                    | j          fS N)r   r%   s    r!   _natural_parameterszExponential._natural_parameters   s    
}r"   xc                .    t          j        |            S rW   )r   r<   )r   rY   s     r!   _log_normalizerzExponential._log_normalizer   s    
A2r"   )r   r   r   r   )r   r   )r   r+   r   r   )r=   r   r   r   )rL   r   r   r   )r   rU   )rY   r   r   r   )__name__
__module____qualname____doc____annotations__r   propertyr&   r*   r/   r.   rA   rD   rF   rH   rK   rT   rX   r[   __classcell__)r    s   @r!   r   r   "   s        ! !F LLLLLL* * * * * *& & & & X& ! ! ! X! -/ 
' 
' 
' 
' 
' .0 0 0 0 0 0,: : : :	9 	9 	9 	9+ + + +4 4 4 4 1 1 1 1 # # # #$    X       r"   r   )
__future__r   typingr   numpyr9   r   r   paddle.base.data_feederr   r   paddle.base.frameworkr   paddle.distributionr	   paddle.frameworkr
   collections.abcr   r   r   ExponentialFamilyr    r"   r!   <module>rm      s   # " " " " "                        = = = = = = = = * * * * * * 2 2 2 2 2 2 , , , , , , %(((((($$$$$$$$G G G G G$6 G G G G Gr"   