
    Αi                         S SK Jr  S SKrS SKrS SKJr  S SKrS SKrS SK	J
r
  S SKJr  \(       a  S SKJr  S SKJr  S SKJrJr   " S	 S
\5      rg)    )annotationsN)TYPE_CHECKING)	framework)TransformedDistribution)Sequence)Tensor)	TransformUniformc                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   SU 4S
 jjr\SS j5       r\SS j5       r	\SS j5       r
SS jrSS jrSS jrSS jr/ 4SS jjr/ 4SS jjrSrU =r$ )Gumbel"   a  The Gumbel distribution with location `loc` and `scale` parameters.

Mathematical details

The probability density function (pdf) is

.. math::

    pdf(x; mu, sigma) = exp(-(x - mu) / sigma - exp(-(x - mu) / sigma)) / sigma


In the above equation:

* :math:`loc = \mu`: is the mean.
* :math:`scale = \sigma`: is the std.

Args:
    loc(int|float|tensor): The mean of gumbel distribution.The data type is int, float, tensor.
    scale(int|float|tensor): The std of gumbel distribution.The data type is int, float, tensor.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution.gumbel import Gumbel

        >>> # Gumbel distributed with loc=0, scale=1
        >>> dist = Gumbel(paddle.full([1], 0.0), paddle.full([1], 1.0))

        >>> # doctest: +SKIP
        >>> print(dist.sample([2]))
        Tensor(shape=[2, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0.40484068],
        [3.19400501]])

        >>> print(dist.rsample([2]))
        Tensor(shape=[2, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-0.95093185],
        [ 0.32422572]])

        >>> # doctest: -SKIP
        >>> value = paddle.full([1], 0.5)
        >>> print(dist.prob(value))
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.33070430])

        >>> print(dist.log_prob(value))
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [-1.10653067])

        >>> print(dist.cdf(value))
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.54523921])

        >>> print(dist.entropy())
        Tensor(shape=[1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [1.57721567])
r   locscaler
   	base_distztuple[Transform, ...]
transformsc           
       > [        U[        R                  [        R                  [
        R                  R                  45      (       d  [        S[        U5       35      e[        U[        R                  [        R                  [
        R                  R                  45      (       d  [        S[        U5       35      e[        U[        R                  5      (       a  [
        R                  " SUS9n[        U[        R                  5      (       a  [
        R                  " SUS9nUR                  UR                  :w  a%  [
        R                  " X/5      u  U l        U l        OXsU l        U l        [        R                   " SS9n[
        R"                  R%                  [
        R&                  " U R                  [)        UR*                  5      5      [
        R&                  " U R                  [)        SUR,                  -
  5      5      5      U l        SU l        [2        TU ]i  U R.                  U R0                  5        g )Nz5Expected type of loc is Real|Variable|Value, but got z7Expected type of scale is Real|Variable|Value, but got  )shape
fill_valuefloat32)dtype   )
isinstancenumbersRealr   VariablepaddlepirValue	TypeErrortypefullr   broadcast_tensorsr   r   npfinfodistributionr
   	full_likefloattinyepsr   r   super__init__)selfr   r   r%   	__class__s       Z/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/gumbel.pyr,   Gumbel.__init__c   s   ',,	 2 2FJJ4D4DE
 
 GS	{S  GLL)"4"4fjj6F6FG
 
 I$u+W  c7<<((++B37CeW\\**KKbU;E99##)#;#;SL#I DHdj#& DHdjy),,44TXXuUZZ'89TXXuQ]';<

 9    c                V    U R                   U R                  [        R                  -  -   $ )u  Mean of distribution

The mean is

.. math::

    mean = \mu + \sigma * γ

In the above equation:

* :math:`loc = \mu`: is the location parameter.
* :math:`scale = \sigma`: is the scale parameter.
* :math:`γ`: is the euler's constant.

Returns:
    Tensor: mean value.

)r   r   r$   euler_gammar-   s    r/   meanGumbel.mean   s     ( xx$**r~~555r1   c                
   [         R                  " U R                  R                  [        R
                  [        R
                  -  U R                  R                  S9n[         R                  " U R                  S5      U-  S-  $ )zVariance of distribution.

The variance is

.. math::

    variance = \sigma^2 * \pi^2 / 6

In the above equation:

* :math:`scale = \sigma`: is the scale parameter.

Returns:
    Tensor: The variance value.

r   r   r         )	r   r"   r   r   mathpir   r   pow)r-   temps     r/   varianceGumbel.variance   s[    $ {{((..ww(**""
 zz$**a(4/!33r1   c                B    [         R                  " U R                  5      $ )zStandard deviation of distribution

The standard deviation is

.. math::

    stddev = \sqrt{\sigma^2 * \pi^2 / 6}

In the above equation:
* :math:`scale = \sigma`: is the scale parameter.

Returns:
    Tensor: std value
)r   sqrtr?   r4   s    r/   stddevGumbel.stddev   s      {{4==))r1   c                l   U R                   UR                  U R                   R                  5      -
  U R                  R                  U R                   R                  5      -  n[        R
                  " U[        R
                  " U5      -
  5      U R                  R                  UR                  5      -  $ )zProbability density/mass function

Args:
    value (Tensor): The input tensor.

Returns:
    Tensor: probability.The data type is same with value.

)r   astyper   r   r   exp)r-   valueys      r/   probGumbel.prob   sz     XXTXX^^44

8I8IHHNN9
 
 zz!fjjm+,tzz/@/@/IIIr1   c                L    [         R                  " U R                  U5      5      $ )zLog probability density/mass function.

Args:
    value (Tensor): The input tensor.

Returns:
    Tensor: log probability.The data type is same with value.

)r   logrJ   r-   rH   s     r/   log_probGumbel.log_prob   s     zz$))E*++r1   c                    [         R                  " [         R                  " XR                  R                  UR                  5      -
  * U R
                  R                  UR                  5      -  5      * 5      $ )zCumulative distribution function.
Args:
    value (Tensor): value to be evaluated.

Returns:
    Tensor: cumulative probability of value.

)r   rG   r   rF   r   r   rN   s     r/   cdf
Gumbel.cdf   s[     zzZZ((//%++667**##EKK01 
 	
r1   c                j    [         R                  " U R                  5      S-   [        R                  -   $ )zHEntropy of Gumbel distribution.

Returns:
    Entropy of distribution.

r   )r   rM   r   r$   r3   r4   s    r/   entropyGumbel.entropy   s%     zz$**%)BNN::r1   c                    [         R                  " 5          U R                  U5      sSSS5        $ ! , (       d  f       g= f)zSample from ``Gumbel``.

Args:
    shape (Sequence[int], optional): The sample shape. Defaults to [].

Returns:
    Tensor: A tensor with prepended dimensions shape.The data type is float32.

N)r   no_gradrsample)r-   r   s     r/   sampleGumbel.sample   s&     ^^<<& s   1
?c                L   [         R                  R                  5       n[         R                  R                  [         R                  " U R
                  R                  SU R                  R                  S9[         R                  " U R
                  5      * 5      n[         R                  R                  U R                  U R
                  * 5      nUR                  UR                  UR                  UR                  U R                  R                  U5      5      5      5      5      $ )zreparameterized sample
Args:
    shape (Sequence[int], optional): 1D `int32`. Shape of the generated samples. Defaults to [].

Returns:
    Tensor: A tensor with prepended dimensions shape.The data type is float32.

r   r8   )r   r&   ExpTransformAffineTransformr"   r   r   r   r   	ones_likeforwardinverse_baserZ   )r-   r   	exp_transaffine_trans_1affine_trans_2s        r/   rY   Gumbel.rsample
  s     ''446	,,<<KKjj&&1DHHNN djj))	
  ,,<<HHtzzk
 %%&&%%djj&7&7&>?
 	
r1   )r   r   r   r   )r   float | Tensorr   rg   returnNone)rh   r   )rH   r   rh   r   )r   zSequence[int]rh   r   )__name__
__module____qualname____firstlineno____doc____annotations__r,   propertyr5   r?   rC   rJ   rO   rR   rU   rZ   rY   __static_attributes____classcell__)r.   s   @r/   r   r   "   s    9v 
KM%%!:F 6 6* 4 42 * *"J 
,
 ; -/ ' .0 
 
r1   r   )
__future__r   r;   r   typingr   numpyr$   r   paddle.baser   ,paddle.distribution.transformed_distributionr   collections.abcr   r   paddle.distributionr	   r
   r   r   r1   r/   <module>rz      s:    #       ! P(6B
$ B
r1   