# Geometric¶

class paddle.distribution. Geometric ( probs ) [source]

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 trials to get the probability of success for the first time. In detail, it is: the probability that the first k-1 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

$Pr(Y=k)=(1-p)^kp$

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

Parameters

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

import paddle

geom = Geometric(0.5)

geom.mean
#        2.)

geom.variance
#        2.)

geom.stddev
#        1.41421354)

probs ( value )

Probability density/mass function.

Note

This method will be deprecated in the future, please use prob instead.

property mean

Mean of geometric distribution.

property variance

Variance of geometric distribution.

property stddev

Standard deviation of Geometric distribution.

pmf ( k )

Probability mass funciotn evaluated at k.

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

k (int) – Value to be evaluated.

Returns

Probability.

Return type

Tensor

Examples

import paddle

geom = Geometric(0.5)
geom.pmf(2)
#        0.25000000)

log_pmf ( k )

Log probability mass function evaluated at k.

$\log P(X = k) = \log(1-p)^k p$
Parameters

k (int) – Value to be evaluated.

Returns

Log probability.

Return type

Tensor

Examples

import paddle

geom = Geometric(0.5)
geom.log_pmf(2)
#        -1.38629436)

sample ( shape=() )

Sample from Geometric distribution with sample shape.

Parameters

shape (tuple(int)) – Sample shape.

Returns

Sampled data with shape sample_shape + batch_shape + event_shape.

Examples

import paddle

geom = Geometric(0.5)
geom.sample((2,2))
# Tensor(shape=[2, 2, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
#        [[[4.28128004],
#         [0.53546447]],
#         [[0.88012987],
#         [0.54070371]]])

rsample ( shape=() )

Generate samples of the specified shape.

Parameters

shape (tuple(int)) – The shape of generated samples.

Returns

A sample tensor that fits the Geometric distribution.

Return type

Tensor

Examples

import paddle
geom = Geometric(0.5)
geom.rsample((2,2))
# Tensor(shape=[2, 2, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
#        [[[2.90974379],
#         [1.28049409]],
#         [[4.60141420],
#         [2.98836184]]])

entropy ( )

Entropy of dirichlet distribution.

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

Entropy.

Return type

Tensor

Examples

import paddle

geom = Geometric(0.5)
geom.entropy()
#        1.38629436)

cdf ( k )

Cdf of geometric distribution.

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

k – The number of trials performed.

Returns

Entropy.

Return type

Tensor

Examples

import paddle

geom = Geometric(0.5)
geom.cdf(4)
#        0.93750000)

kl_divergence ( other ) [source]

Calculate the KL divergence KL(self || other) with two Geometric instances.

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

other (Geometric) – An instance of Geometric.

Returns

The kl-divergence between two geometric distributions.

Return type

Tensor

Examples

import paddle

geom_p = Geometric(0.5)
geom_q = Geometric(0.1)
geom_p.kl_divergence(geom_q)
#        0.51082563)

property batch_shape

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

property event_shape

Returns event shape of distribution

Returns

event shape

Return type

Sequence[int]

log_prob ( value )

Log probability density/mass function.

prob ( value )

Probability density/mass function evaluated at value.

Parameters

value (Tensor) – value which will be evaluated