
    Αi                        S SK Jr  S SKJ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\S'         SU 4S jjr\SS j5       r\SS	 j5       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S jrSS jrSS jrSrU =r$ )Gamma    a>  
Gamma distribution parameterized by :attr:`concentration` (aka "alpha") and :attr:`rate` (aka "beta").

The probability density function (pdf) is

.. math::

    f(x; \alpha, \beta, x > 0) = \frac{\beta^{\alpha}}{\Gamma(\alpha)} x^{\alpha-1}e^{-\beta x}

    \Gamma(\alpha)=\int_{0}^{\infty} x^{\alpha-1} e^{-x} \mathrm{~d} x, (\alpha>0)

Args:
    concentration (float|Tensor): Concentration parameter. It supports broadcast semantics.
        The value of concentration must be positive. When the parameter is a tensor,
        it represents multiple independent distribution with
        a batch_shape(refer to :ref:`api_paddle_distribution_Distribution`).
    rate (float|Tensor): Rate parameter. It supports broadcast semantics.
        The value of rate must be positive. When the parameter is tensor,
        it represent multiple independent distribution with
        a batch_shape(refer to :ref:`api_paddle_distribution_Distribution`).

Example:
    .. code-block:: python

        >>> import paddle

        >>> # scale input
        >>> gamma = paddle.distribution.Gamma(0.5, 0.5)
        >>> print(gamma.mean)
        Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               1.)

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

        >>> print(gamma.entropy())
        Tensor(shape=[], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               0.78375685)

        >>> # tensor input with broadcast
        >>> gamma = paddle.distribution.Gamma(paddle.to_tensor([0.2, 0.4]), paddle.to_tensor(0.6))
        >>> print(gamma.mean)
        Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [0.33333331, 0.66666663])

        >>> print(gamma.variance)
        Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [0.55555552, 1.11111104])

        >>> print(gamma.entropy())
        Tensor(shape=[2], dtype=float32, place=Place(gpu:0), stop_gradient=True,
               [-1.99634242,  0.17067254])
r   concentrationrater   c                  > [        5       (       db  [        US[        [        [        R
                  R                  4S5        [        US[        [        [        R
                  R                  4S5        U R                  X5      (       a'  Xl        X l	        [        UR                  5      U l        O8U R                  X5      u  U l        U l	        [        R                  " 5       U l        [        TU ]=  U R                  R                   5        g )Nr   r   r   )r
   r   floatr   paddlepirValue_validate_argsr   r   r   r   
_to_tensorget_default_dtypesuper__init__shape)selfr   r   	__class__s      Y/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/gamma.pyr   Gamma.__init__\   s       &**"2"23	 &**"2"23	 }33!.I&}':':;DJ.2oo/+T  113DJ++112    c                4    U R                   U R                  -  $ )z>Mean of gamma distribution.

Returns:
    Tensor: mean value.
r   r   r   s    r    mean
Gamma.meanz   s     !!DII--r"   c                R    U R                   U R                  R                  S5      -  $ )zFVariance of gamma distribution.

Returns:
    Tensor: variance value.
   )r   r   powr%   s    r    varianceGamma.variance   s"     !!DIIMM!$444r"   c                L    [         R                  " U R                  U5      5      $ )zProbability density function evaluated at value

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

Returns:
    Tensor: Probability.
)r   explog_probr   values     r    prob
Gamma.prob   s     zz$--.//r"   c                   U R                   [        R                  " U R                  5      -  U R                   S-
  [        R                  " U5      -  -   U R                  U-  -
  [        R                  " U R                   5      -
  $ )zLog probability density function evaluated at value

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

Returns:
    Tensor: Log probability.
   )r   r   logr   lgammar0   s     r    r/   Gamma.log_prob   so     DII!66!!A%E)::;ii%  mmD../0	
r"   c                    U R                   [        R                  " U R                  5      -
  [        R                  " U R                   5      -   SU R                   -
  [        R
                  " U R                   5      -  -   $ )z=Entropy of gamma distribution

Returns:
    Tensor: Entropy.
g      ?)r   r   r6   r   r7   digammar%   s    r    entropyGamma.entropy   sh     jj#$mmD../0 T'''6>>$:L:L+MMN	
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Gamma.sample   s&     ^^<<& s   1
?c                    [         R                  R                  XS9n[        R                  " U R
                  R                  U5      5      U R                  R                  U5      -  $ )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)r   Distribution_extend_shaper   standard_gammar   expandr   r@   s     r    r?   Gamma.rsample   sb     ))77 8 
 $$%%e,
IIU#$ 	$r"   c                >   [        U[        5      (       d  [        S[        U5       35      eUR                  [
        R                  " U R                  UR                  -  5      -  n[
        R                  " UR                  5      [
        R                  " U R                  5      -
  nU R                  UR                  -
  [
        R                  " U R                  5      -  nUR                  U R                  -
  U R                  U R                  -  -  nX#-   U-   U-   $ )zThe KL-divergence between two gamma distributions.

Args:
    other (Gamma): instance of Gamma.

Returns:
    Tensor: kl-divergence between two gamma distributions.
z/Expected type of other is Exponential, but got )

isinstancer   	TypeErrortyper   r   r6   r   r7   r:   )r   othert1t2t3t4s         r    kl_divergenceGamma.kl_divergence   s     %''A$u+O    6::dii%**.D#EE]]5../&--3
 
   5#6#66&..;
 
 jj499$););dii)GHw|b  r"   c                :    U R                   S-
  U R                  * 4$ Nr5   r$   r%   s    r    _natural_parametersGamma._natural_parameters   s    ""Q&
33r"   c                    [         R                  " US-   5      US-   [         R                  " UR                  5       * 5      -  -   $ rV   )r   r7   r6   
reciprocal)r   xys      r    _log_normalizerGamma._log_normalizer   s4    }}QU#q1u

ALLN?0K&KKKr"   )r   r   r   )r   float | Tensorr   r_   returnNone)r`   r   )r1   r_   r`   r   )r   zSequence[int]r`   r   )rN   r   r`   r   )r[   r   r\   r   r`   r   )__name__
__module____qualname____firstlineno____doc____annotations__r   propertyr&   r+   r2   r/   r;   rA   r?   rS   rW   r]   __static_attributes____classcell__)r   s   @r    r   r       s    5n 
LL3+33A3	3< . . 5 5	0
 
 -/ 
' .0 $ !04L Lr"   r   )
__future__r   typingr   r   r   paddle.base.data_feederr   r   paddle.base.frameworkr   paddle.distributionr	   paddle.frameworkr
   collections.abcr   r   r   ExponentialFamilyr    r"   r    <module>rt      s?    #     = * 2 ,($LL00 LLr"   