# 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+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

$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].

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)

>>> print(geom.mean)
1.)

>>> print(geom.variance)
2.)

>>> print(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 function evaluated at k.

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

k (int) – Value to be evaluated.

Returns

Probability.

Return type

Tensor

Examples

>>> import paddle

>>> geom = Geometric(0.5)
>>> print(geom.pmf(2))
0.12500000)

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)
>>> print(geom.log_pmf(2))
-2.07944131)

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)
>>> print(geom.sample((2,2)))
[[0., 0.],
[1., 0.]])

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)
>>> print(geom.rsample((2,2)))
[[0., 0.],
[1., 0.]])

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)
>>> print(geom.entropy())
1.38629425)

cdf ( k )

Cdf of geometric distribution.

$F(X \leq k) = 1 - (1-p)^(k+1), \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)
>>> print(geom.cdf(4))
0.96875000)

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)
>>> print(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