
    Αi|*                        S SK J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	\R                  5      rg)
    )annotationsN)TYPE_CHECKING)	framework)distribution)Sequence)Tensorc                     ^  \ rS rSr% Sr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/ 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$ )	Geometric    a  
Geometric distribution parameterized by probs.

In probability theory and statistics, the geometric distribution is one of
discrete probability distributions, parameterized by one positive shape parameter, denoted by probs.
In n Bernoulli trials, it takes k+1 trials to get the probability of success for the first time.
In detail, it is: the probability that the first k times failed and the kth time succeeded.
The geometric distribution is a special case of the Pascal distribution when r=1.

The probability mass function (pmf) is

.. math::
        Pr(Y=k)=(1-p)^kp

where k is number of trials failed before seeing a success, and p is probability of success for each trial and k=0,1,2,3,4..., p belong to (0,1].

Args:
    probs (Real|Tensor): Probability parameter.
        The value of probs must be positive. When the parameter is a tensor, probs is probability of success for each trial.

Returns:
    Geometric distribution for instantiation of probs.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> geom = Geometric(0.5)

        >>> print(geom.mean)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.)

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

        >>> print(geom.stddev)
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.41421354)
r   probsc                  > [        U[        R                  [        R                  [
        R                  [        R                  R                  45      (       a  [        U[        R                  5      (       a$  [        R                  " SU[        R                  S9n[        R                  " UR                  SUR                  S9n[        R                  " UR                  SUR                  S9n[        R                  " UR                  S[        S9nX:*  nX:  nO[        S[        U5       35      e[!        UR                  5      nXl        [$        TU ]M  U5        g )N )shape
fill_valuedtype   r   FzOExpected type of probs is Number.Real|Tensor|framework.Variable|Value, but got )
isinstancenumbersRealpaddler   r   VariablepirValuefullfloat32r   r   bool	TypeErrortypetupler   super__init__)	selfr   all_ones	all_zeros	all_false
lessthen_0
morethen_1batch_shape	__class__s	           ]/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/geometric.pyr!   Geometric.__init__P   s   \\6==)*<*<fjj>N>NO
 
 %..fnn {{kkau{{H kkau{{I kke4I +J)J abfglbmano  EKK(
%    c                &    SU R                   -  S-
  $ )zMean of geometric distribution.      ?r   r"   s    r*   meanGeometric.meanq   s     TZZ#%%r,   c                    [         R                  " SU R                  -  S-
  U R                  -  U R                  R                  S9$ )z#Variance of geometric distribution.r.   r   )r   	to_tensorr   r   r0   s    r*   varianceGeometric.variancev   s>     4::#tzz1**""
 	
r,   c                B    [         R                  " U R                  5      $ )z-Standard deviation of Geometric distribution.)r   sqrtr6   r0   s    r*   stddevGeometric.stddev~   s     {{4==))r,   c                "   [        U[        R                  [        R                  [
        R                  R                  45      (       a1  [
        R                  " SU R                  -
  U5      U R                  -  $ [        S[        U5       35      e)a  Probability mass function evaluated at k.

.. math::

    P(X=k) = (1-p)^{k} p, \quad k=0,1,2,3,\ldots

Args:
    k (int): Value to be evaluated.

Returns:
    Tensor: Probability.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> geom = Geometric(0.5)
        >>> print(geom.pmf(2))
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.12500000)
r.   DExpected type of k is number.Real|framework.Variable|Value, but got r   r   Integralr   r   r   r   r   powr   r   r   r"   ks     r*   pmfGeometric.pmf   sw    2   )"4"4fjj6F6FG
 
 ::sTZZ/!4tzzAAVW[\]W^V_` r,   c                
   [        U[        R                  [        R                  [
        R                  R                  45      (       a%  [
        R                  " U R                  U5      5      $ [        S[        U5       35      e)a  Log probability mass function evaluated at k.

.. math::
    \log P(X = k) = \log(1-p)^k p

Args:
    k (int): Value to be evaluated.

Returns:
    Tensor: Log probability.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> geom = Geometric(0.5)
        >>> print(geom.log_pmf(2))
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        -2.07944131)
r=   )r   r   r?   r   r   r   r   r   logrC   r   r   rA   s     r*   log_pmfGeometric.log_pmf   sk    0   )"4"4fjj6F6FG
 
 ::dhhqk**VW[\]W^V_` r,   c                    [         R                  " 5          U R                  U5      sSSS5        $ ! , (       d  f       g= f)a  Sample from Geometric distribution with sample shape.

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

Returns:
    Sampled data with shape `sample_shape` + `batch_shape` + `event_shape`.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> paddle.seed(2023)
        >>> geom = Geometric(0.5)
        >>> print(geom.sample((2,2)))
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0., 0.],
         [1., 0.]])
N)r   no_gradrsample)r"   r   s     r*   sampleGeometric.sample   s&    . ^^<<& s   1
?c           	     t   [         R                  R                  XS9n[        R                  " U[        [        R                  " SS9R                  5      SU R                  R                  S9n[        R                  " [        R                  " U5      [        R                  " U R                  * 5      -  5      $ )a  Generate samples of the specified shape.

Args:
    shape(Sequence[int]): The shape of generated samples.

Returns:
    Tensor: A sample tensor that fits the Geometric distribution.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> paddle.seed(2023)
        >>> geom = Geometric(0.5)
        >>> print(geom.rsample((2,2)))
        Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[0., 0.],
         [1., 0.]])

)sample_shaper   r4   r.   )r   minmaxr   )r   Distribution_extend_shaper   uniformfloatnpfinfotinyr   r   floorrF   log1p)r"   r   rT   s      r*   rK   Geometric.rsample   s    0 ))77 8 
 ..bhhY/445**""	
 ||FJJw/&,,}2MMNNr,   c                    SU R                   -
  [        R                  " SU R                   -
  5      -  nU R                   [        R                  " U R                   5      -  nX-   * U R                   -  $ )a  Entropy of dirichlet distribution.

.. math::

    H(X) = -\left[\frac{1}{p} \log p + \frac{1-p}{p^2} \log (1-p) \right]

Returns:
    Tensor: Entropy.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> geom = Geometric(0.5)
        >>> print(geom.entropy())
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        1.38629425)
r.   )r   r   rF   )r"   xys      r*   entropyGeometric.entropy  sW    , 4::C$**,<!==JJDJJ//x$**$$r,   c                   [        U[        R                  [        R                  [
        R                  R                  45      (       a*  S[
        R                  " SU R                  -
  US-   5      -
  $ [        S[        U5       35      e)a  Cdf of geometric distribution.

.. math::

    F(X \leq k) = 1 - (1-p)^(k+1), \quad k=0,1,2,\ldots

Args:
    k: The number of trials performed.

Returns:
    Tensor: Entropy.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> geom = Geometric(0.5)
        >>> print(geom.cdf(4))
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.96875000)
r.   r   r=   r>   rA   s     r*   cdfGeometric.cdf   sw    2   )"4"4fjj6F6FG
 
 S4::%5A>>>VW[\]W^V_` r,   c                
   [        U[        5      (       aX  U R                  UR                  p2U[        R                  " X#-  5      -  SU-
  [        R                  " SU-
  SU-
  -  5      -  -   $ [        S[        U5       35      e)ax  Calculate the KL divergence KL(self || other) with two Geometric instances.

.. math::

    KL(P \| Q) = \frac{p}{q} \log \frac{p}{q} + \log (1-p) - \log (1-q)

Args:
    other (Geometric): An instance of Geometric.

Returns:
    Tensor: The kl-divergence between two geometric distributions.

Examples:

    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import Geometric

        >>> geom_p = Geometric(0.5)
        >>> geom_q = Geometric(0.1)
        >>> print(geom_p.kl_divergence(geom_q))
        Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True,
        0.51082563)
r.   z6Exacted type of other is geometric.Geometric, but got )r   r
   r   r   rF   r   r   )r"   otherpqs       r*   kl_divergenceGeometric.kl_divergenceB  s    4 eY''::u{{qvzz!%((C!GvzzqS1W%8 ,   HeV r,   r/   )r   zfloat | TensorreturnNone)rj   r   )rB   zint | Tensorrj   r   )r   zSequence[int]rj   r   )re   r
   rj   r   )__name__
__module____qualname____firstlineno____doc____annotations__r!   propertyr1   r6   r:   rC   rG   rL   rK   r_   rb   rh   __static_attributes____classcell__)r)   s   @r*   r
   r
       s    +Z M&B & & 
 
 * * DB -/ '4 .0 #OJ%6 D" "r,   r
   )
__future__r   r   typingr   numpyrV   r   paddle.baser   paddle.distributionr   collections.abcr   r   rR   r
   r   r,   r*   <module>r{      s9    #      ! ,(D)) Dr,   