Details
-
Improvement
-
Status: Closed
-
Trivial
-
Resolution: Fixed
-
1.0
-
None
Description
The Geometric distribution is defined by the probability of success (p).
The PMF is:
pmf(x) = pow(1 - p, x) * p
This can be implemented directly or using exponential functions:
double p1 = Math.pow(1.0 - p, x) * p; double p2 = Math.exp(Math.log1p(-p) * x) * p;
The current code uses exponential functions. Implementations in Matlab, R and SciPy all use the power function. Both have advantages depending on the value of p.
When p is >= 0.5 the value (1-p) is exact. As p becomes increasingly small then (1-p) loses precision due to the limited precision of a double value close to 1.