
    Αi;                        S SK Jr  S SKJr  S SKrS SKrS SKJr  S SKJ	r	J
r
  S SKJr  S SKJr  S SKJr  \(       a  S S	KJr  S S
KJrJr   " S S\R*                  5      rg)    )annotations)TYPE_CHECKINGN)distribution)
check_typeconvert_dtype)Variable)exponential_family)in_dynamic_mode)Sequence)Tensordtypec                     ^  \ rS rSr% SrS\S'   S\S'   SU 4S jjr\SS j5       r\SS j5       r	/ 4SS	 jjr
/ 4SS
 jjrSS jrSS jrSS jrSS jrSS jrSS jr\SS j5       rSS jrSrU =r$ )Exponential"   at  
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   c                  > [        5       (       d1  [        US[        [        [        R
                  R                  4S5        U R                  U5      (       a!  Xl        [        UR                  5      U l
        O2U R                  U5      u  U l        [        R                  " 5       U l
        [        TU ]9  U R                  R                  5        g )Nr   r   )r
   r   floatr   paddlepirValue_validate_argsr   r   r   
_to_tensorget_default_dtypesuper__init__shape)selfr   	__class__s     _/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/exponential.pyr   Exponential.__init__I   s      &**"2"23	 t$$I&tzz2DJ//$/KTY113DJ)    c                6    U R                   R                  5       $ )zDMean of exponential distribution.

Returns:
    Tensor: mean value.
)r   
reciprocalr   s    r   meanExponential.mean\   s     yy##%%r!   c                8    U R                   R                  S5      $ )zLVariance of exponential distribution.

Returns:
    Tensor: variance value.
)r   powr$   s    r   varianceExponential.variancee   s     yy}}R  r!   c                    [         R                  " 5          U R                  U5      sSSS5        $ ! , (       d  f       g= f)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   sampleExponential.samplen   s&     ^^<<& s   1
?c           	     $   [         R                  R                  XS9n[        R                  " U[        [        R                  " SS9R                  5      SU R                  R                  S9n[        R                  " U5      * U R                  -  $ )zGenerate 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   r9   s      r   r.   Exponential.rsamplez   sw     ))77 8 
 ..bhhY/445))//	
 

7##dii//r!   c                d    U R                   [        R                  " U R                   * U-  5      -  $ )zProbability 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   values     r   probExponential.prob   s'     yy6::tyyj5&8999r!   c                b    [         R                  " U R                  5      U R                  U-  -
  $ )zLog probability density function evaluated at value.

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

Returns:
    Tensor: Log probability.
r   r=   r   rA   s     r   log_probExponential.log_prob   s%     zz$))$tyy5'888r!   c                H    S[         R                  " U R                  5      -
  $ )zDEntropy of exponential distribution.

Returns:
    Tensor: Entropy.
r4   rF   r$   s    r   entropyExponential.entropy   s     VZZ		***r!   c                P    S[         R                  " U R                  * U-  5      -
  $ )a  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.
r4   )r   r@   r   rA   s     r   cdfExponential.cdf   s#     VZZ
U 2333r!   c                L    [         R                  " U* 5      * U R                  -  $ )a  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   rA   s     r   icdfExponential.icdf   s!     eV$$tyy00r!   c                    [        U[        5      (       d  [        S[        U5       35      eUR                  U R                  -  n[
        R                  " U5      * nX2-   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   other
rate_ratiot1s       r   kl_divergenceExponential.kl_divergence   s^     %--A$u+O  ZZ$))+
jj$$""r!   c                    U R                   * 4$ N)r   r$   s    r   _natural_parametersExponential._natural_parameters   s    
}r!   c                2    [         R                  " U* 5      * $ r^   )r   r=   )r   xs     r   _log_normalizerExponential._log_normalizer   s    

A2r!   )r   r   )r   float | TensorreturnNone)rf   r   )r   zSequence[int]rf   r   )rB   re   rf   r   )rX   r   rf   r   )rf   ztuple[Tensor])rb   r   rf   r   )__name__
__module____qualname____firstlineno____doc____annotations__r   propertyr%   r*   r/   r.   rC   rG   rJ   rM   rQ   r[   r_   rc   __static_attributes____classcell__)r   s   @r   r   r   "   s    !F LL*& & & ! ! -/ 
' .0 0,:	9+4 1 #$   r!   r   )
__future__r   typingr   numpyr:   r   r   paddle.base.data_feederr   r   paddle.base.frameworkr   paddle.distributionr	   paddle.frameworkr
   collections.abcr   r   r   ExponentialFamilyr    r!   r   <module>r{      s@    #      = * 2 ,($G$66 Gr!   