Ë
    ˆ\;jª  ã                   óR   — d dl Z d dlZd dlZd dlZd dlmZ d dlmZ  G d„ de«      Z	y)é    N)Ú	framework)ÚTransformedDistributionc                   óv   ‡ — e Zd ZdZˆ fd„Zed„ «       Zed„ «       Zed„ «       Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zd„ Zˆ xZS )ÚGumbela  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])
    c           
      óþ  •— t        |t        j                  t        j                  f«      st        dt        |«      › �«      ‚t        |t        j                  t        j                  f«      st        dt        |«      › �«      ‚t        |t        j                  «      rt        j                  d|¬«      }t        |t        j                  «      rt        j                  d|¬«      }|j                  |j                  k7  r%t        j                  ||g«      \  | _        | _        n||c| _        | _        t        j                  d¬«      }t        j                  j!                  t        j"                  | j                  t%        |j&                  «      «      t        j"                  | j                  t%        d|j(                  z
  «      «      «      | _        d| _        t.        ‰| �a  | j*                  | j,                  «       y )Nz/Expected type of loc is Real|Variable, but got z1Expected type of scale is Real|Variable, but got © )ÚshapeÚ
fill_valueÚfloat32)Údtypeé   )Ú
isinstanceÚnumbersÚRealr   ÚVariableÚ	TypeErrorÚtypeÚpaddleÚfullr	   Úbroadcast_tensorsÚlocÚscaleÚnpÚfinfoÚdistributionÚUniformÚ	full_likeÚfloatÚtinyÚepsÚ	base_distÚ
transformsÚsuperÚ__init__)Úselfr   r   r   Ú	__class__s       €úcG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/distribution/gumbel.pyr$   zGumbel.__init__U   sl  ø€ Ü˜#¤§¡¬i×.@Ñ.@ÐAÔBÜØAÄ$ÀsÃ)ÀÐMóð ô ˜%¤'§,¡,´	×0BÑ0BÐ!CÔDÜØCÄDÈÃKÀ=ÐQóð ô �cœ7Ÿ<™<Ô(Ü—+‘+ B°3Ô7ˆCä�eœWŸ\™\Ô*Ü—K‘K b°UÔ;ˆEà�9‰9˜Ÿ™Ò#Ü#)×#;Ñ#;¸SÀ%¸LÓ#IÑ ˆDŒH�d•jà#&¨Ð ˆDŒH�d”jä—‘˜yÔ)ˆÜ×,Ñ,×4Ñ4Ü×Ñ˜TŸX™X¤u¨U¯Z©ZÓ'8Ó9Ü×Ñ˜TŸX™X¤u¨Q°·±©]Ó';Ó<ó
ˆŒð
 ˆŒä‰Ñ˜Ÿ™¨¯©Õ9ó    c                 óV   — | j                   | j                  t        j                  z  z   S )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'   ÚmeanzGumbel.meant   s    € ð( �x‰x˜$Ÿ*™*¤r§~¡~Ñ5Ñ5Ð5r(   c                 ó  — t        j                  | j                  j                  t        j
                  t        j
                  z  | j                  j                  ¬«      }t        j                  | j                  d«      |z  dz  S )a  Variance 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'   ÚvariancezGumbel.varianceŠ   s[   € ô$ �{‰{Ø—(‘(—.‘.Ü—w‘w¤§¡Ñ(Ø—*‘*×"Ñ"ô
ˆô �z‰z˜$Ÿ*™* aÓ(¨4Ñ/°!Ñ3Ð3r(   c                 ó@   — t        j                  | j                  «      S )a  Standard 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   Úsqrtr5   r+   s    r'   ÚstddevzGumbel.stddev¤   s   € ô  �{‰{˜4Ÿ=™=Ó)Ð)r(   c                 óª   — | j                   |z
  | j                  z  }t        j                  |t        j                  |«      z
  «      | j                  z  S )z¼Probability density/mass function

        Args:
            value (Tensor): The input tensor.

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

        )r   r   r   Úexp)r%   ÚvalueÚys      r'   ÚprobzGumbel.prob¶   s@   € ð �X‰X˜Ñ §¡Ñ+ˆä�z‰z˜!œfŸj™j¨›mÑ+Ó,¨t¯z©zÑ9Ð9r(   c                 óJ   — t        j                  | j                  |«      «      S )zÅLog probability density/mass function.

        Args:
            value (Tensor): The input tensor.

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

        )r   Úlogr=   ©r%   r;   s     r'   Úlog_probzGumbel.log_probÄ   s   € ô �z‰z˜$Ÿ)™) EÓ*Ó+Ð+r(   c                 óŠ   — t        j                  t        j                  || j                  z
   | j                  z  «       «      S )z³Cumulative distribution function.
        Args:
            value (Tensor): value to be evaluated.

        Returns:
            Tensor: cumulative probability of value.

        )r   r:   r   r   r@   s     r'   Úcdfz
Gumbel.cdfÐ   s4   € ô �z‰zœ6Ÿ:™:¨°·±Ñ(8Ð&9¸D¿J¹JÑ&FÓGÐGÓHÐHr(   c                 óh   — t        j                  | j                  «      dz   t        j                  z   S )z`Entropy of Gumbel distribution.

        Returns:
            Entropy of distribution.

        r   )r   r?   r   r   r*   r+   s    r'   ÚentropyzGumbel.entropyÛ   s%   € ô �z‰z˜$Ÿ*™*Ó%¨Ñ)¬B¯N©NÑ:Ð:r(   c                 óx   — t        j                  «       5  | j                  |«      cddd«       S # 1 sw Y   yxY w)zèSample 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'   ÚsamplezGumbel.sampleä   s&   € ô �^‰^ÕØ—<‘< Ó&÷ ×Òús   •0°9c                 óN  — t         j                  j                  «       }t         j                  j                  t        j                  | j
                  j                  d| j                  j                  ¬«      t        j                  | j
                  «       «      }t         j                  j                  | j                  | j
                   «      }|j                  |j                  |j                  |j                  | j                  j                  |«      «      «      «      «      S )zæreparameterized sample
        Args:
            shape (Sequence[int]): 1D `int32`. Shape of the generated samples.

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

        r   r.   )r   r   ÚExpTransformÚAffineTransformr   r   r	   r   r   Ú	ones_likeÚforwardÚinverseÚ_baserI   )r%   r	   Ú	exp_transÚaffine_trans_1Úaffine_trans_2s        r'   rH   zGumbel.rsampleñ   sß   € ô ×'Ñ'×4Ñ4Ó6ˆ	Ü×,Ñ,×<Ñ<Ü�K‰KØ—j‘j×&Ñ&°1¸D¿H¹H¿N¹Nôô ×Ñ˜dŸj™jÓ)Ð)ó	
ˆô  ×,Ñ,×<Ñ<Ø�H‰H�t—z‘z�kó
ˆð ×%Ñ%Ø×ÑØ×&Ñ&Ø×%Ñ% d§j¡j×&7Ñ&7¸Ó&>Ó?óóó
ð 	
r(   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   Úpropertyr,   r5   r8   r=   rA   rC   rE   rI   rH   Ú__classcell__)r&   s   @r'   r   r      si   ø„ ñ9ôv:ð> ñ6ó ð6ð* ñ4ó ð4ð2 ñ*ó ð*ò":ò
,ò	Iò;ò'ö
r(   r   )
r1   r   Únumpyr   r   Úpaddle.baser   Ú,paddle.distribution.transformed_distributionr   r   r   r(   r'   Ú<module>r]      s(   ðó Û ã ã Ý !Ý Pôr
Ð$õ r
r(   