Note
Go to the end to download the full example code.
The geometric distribution: waiting for the first success#
The number of independent trials up to and including the first success, with success probability \(p\), has mean \(1/p\) and is memoryless: \(P(X > m + n \mid X > m) = P(X > n)\).
import numpy as np
from mathematicskit.probability import Geometric
from mathematicskit.probability.visualizers.plots import plot_distribution
Mean = 1/p#
geometric = Geometric(p=0.3)
print(f"geometric(p=0.3) mean = {geometric.mean:.4f}, expected 1/p = {1.0 / 0.3:.4f}")
plot_distribution(geometric)

geometric(p=0.3) mean = 3.3333, expected 1/p = 3.3333
<Axes: title={'center': 'Geometric'}, xlabel='x', ylabel='P(X = k)'>
Memorylessness#
m, n = 4, 3
conditional = (1.0 - geometric.cdf(m + n)) / (1.0 - geometric.cdf(m))
print(f"P(X > {m + n} | X > {m}) = {conditional:.4f}, P(X > {n}) = {1.0 - geometric.cdf(n):.4f}")
print("memoryless:", bool(np.isclose(conditional, 1.0 - geometric.cdf(n))))
P(X > 7 | X > 4) = 0.3430, P(X > 3) = 0.3430
memoryless: True
Total running time of the script: (0 minutes 0.029 seconds)