Ë
    ˆ\;j  ã                   óN   — d dl Z d dlZd dlmZmZ  G d„ dej
                  «      Zy)é    N)Ú	dirichletÚexponential_familyc                   ór   ‡ — e Zd ZdZˆ fd„Zed„ «       Zed„ «       Zd„ Zd„ Z	dd„Z
d„ Zed	„ «       Zd
„ Zˆ xZS )ÚBetaa
  
    Beta distribution parameterized by alpha and beta.

    In probability theory and statistics, the beta distribution is a family of
    continuous probability distributions defined on the interval [0, 1]
    parameterized by two positive shape parameters, denoted by alpha and beta,
    that appear as exponents of the random variable and control the shape of
    the distribution. The generalization to multiple variables is called a
    Dirichlet distribution.

    The probability density function (pdf) is

    .. math::

        f(x; \alpha, \beta) = \frac{1}{B(\alpha, \beta)}x^{\alpha-1}(1-x)^{\beta-1}

    where the normalization, B, is the beta function,

    .. math::

        B(\alpha, \beta) = \int_{0}^{1} t^{\alpha - 1} (1-t)^{\beta - 1}\mathrm{d}t


    Args:
        alpha (float|Tensor): Alpha parameter. It supports broadcast semantics.
            The value of alpha must be positive. When the parameter is a tensor,
            it represents multiple independent distribution with
            a batch_shape(refer to ``Distribution`` ).
        beta (float|Tensor): Beta parameter. It supports broadcast semantics.
            The value of beta must be positive(>0). When the parameter is tensor,
            it represent multiple independent distribution with
            a batch_shape(refer to ``Distribution`` ).

    Examples:

        .. code-block:: python

            >>> import paddle

            >>> # scale input
            >>> beta = paddle.distribution.Beta(alpha=0.5, beta=0.5)
            >>> print(beta.mean)
            Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
            0.50000000)

            >>> print(beta.variance)
            Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
            0.12500000)

            >>> print(beta.entropy())
            Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
            -0.24156499)

            >>> # tensor input with broadcast
            >>> beta = paddle.distribution.Beta(alpha=paddle.to_tensor([0.2, 0.4]), beta=0.6)
            >>> print(beta.mean)
            Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
            [0.25000000, 0.40000001])

            >>> print(beta.variance)
            Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
            [0.10416666, 0.12000000])

            >>> print(beta.entropy())
            Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
            [-1.91923141, -0.38095081])
    c                 óà  •— t        |t        j                  «      rt        j                  g |¬«      }t        |t        j                  «      rt        j                  g |¬«      }t        j
                  ||g«      \  | _        | _        t        j                  t        j                  | j                  | j                  gd«      «      | _        t        ‰| �5  | j                  j                  «       y )N)ÚshapeÚ
fill_valueéÿÿÿÿ)Ú
isinstanceÚnumbersÚRealÚpaddleÚfullÚbroadcast_tensorsÚalphaÚbetar   Ú	DirichletÚstackÚ
_dirichletÚsuperÚ__init__Ú_batch_shape)Úselfr   r   Ú	__class__s      €úaG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\paddle/distribution/beta.pyr   zBeta.__init__Y   s¢   ø€ Ü�eœWŸ\™\Ô*Ü—K‘K b°UÔ;ˆEä�dœGŸL™LÔ)Ü—;‘; R°DÔ9ˆDä &× 8Ñ 8¸%À¸Ó GÑˆŒ
�D”Iä#×-Ñ-Ü�L‰L˜$Ÿ*™* d§i¡iÐ0°"Ó5ó
ˆŒô 	‰Ñ˜Ÿ™×5Ñ5Õ6ó    c                 óN   — | j                   | j                   | j                  z   z  S )zMean of beta distribution.©r   r   ©r   s    r   Úmeanz	Beta.meanh   s    € ð �z‰z˜TŸZ™Z¨$¯)©)Ñ3Ñ4Ð4r   c                 ó–   — | j                   | j                  z   }| j                   | j                  z  |j                  d«      |dz   z  z  S )zVariance of beat distributioné   é   )r   r   Úpow)r   Úsums     r   ÚvariancezBeta.variancem   s?   € ð �j‰j˜4Ÿ9™9Ñ$ˆØ�z‰z˜DŸI™IÑ%¨¯©°«°s¸Q±wÑ)?Ñ@Ð@r   c                 óJ   — t        j                  | j                  |«      «      S )z­Probability density funciotn evaluated at value

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

        Returns:
            Tensor: Probability.
        )r   ÚexpÚlog_prob©r   Úvalues     r   Úprobz	Beta.probs   s   € ô �z‰z˜$Ÿ-™-¨Ó.Ó/Ð/r   c                 ój   — | j                   j                  t        j                  |d|z
  gd«      «      S )z´Log probability density function evaluated at value

        Args:
            value (Tensor): Value to be evaluated

        Returns:
            Tensor: Log probability.
        g      ð?r
   )r   r)   r   r   r*   s     r   r)   zBeta.log_prob~   s-   € ð �‰×'Ñ'¬¯©°e¸SÀ5¹[Ð5IÈ2Ó(NÓOÐOr   c                 ó¢   — t        |t        «      r|n
t        |«      }t        j                  | j                  j                  |«      d   d¬«      S )zéSample from beta distribution with sample shape.

        Args:
            shape (Sequence[int], optional): Sample shape.

        Returns:
            Sampled data with shape `sample_shape` + `batch_shape` + `event_shape`.
        ).r   r
   )Úaxis)r   Útupler   Úsqueezer   Úsample)r   r   s     r   r2   zBeta.sample‰   s=   € ô $ E¬5Ô1‘´u¸U³|ˆÜ�~‰~˜dŸo™o×4Ñ4°UÓ;¸FÑCÈ"ÔMÐMr   c                 ó6   — | j                   j                  «       S )zYEntropy of dirichlet distribution

        Returns:
            Tensor: Entropy.
        )r   Úentropyr   s    r   r4   zBeta.entropy•   s   € ð �‰×&Ñ&Ó(Ð(r   c                 ó2   — | j                   | j                  fS ©Nr   r   s    r   Ú_natural_parameterszBeta._natural_parameters�   s   € à—
‘
˜DŸI™IÐ&Ð&r   c                 óŠ   — t        j                  |«      t        j                  |«      z   t        j                  ||z   «      z
  S r6   )r   Úlgamma)r   ÚxÚys      r   Ú_log_normalizerzBeta._log_normalizer¡   s1   € Ü�}‰}˜QÓ¤&§-¡-°Ó"2Ñ2´V·]±]À1ÀqÁ5Ó5IÑIÐIr   )© )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr    r&   r,   r)   r2   r4   r7   r<   Ú__classcell__)r   s   @r   r   r      si   ø„ ñBôH7ð ñ5ó ð5ð ñAó ðAò
	0ò	Pó
Nò)ð ñ'ó ð'öJr   r   )r   r   Úpaddle.distributionr   r   ÚExponentialFamilyr   r=   r   r   Ú<module>rF      s'   ðó ã ß =ôNJÐ×/Ñ/õ NJr   