You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/11/12 14:04:55 UTC

[commons-statistics] branch master updated: Special case of CDF/SF for the Poisson distribution with x=0

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git


The following commit(s) were added to refs/heads/master by this push:
     new 008d103  Special case of CDF/SF for the Poisson distribution with x=0
008d103 is described below

commit 008d103958253b469c12619d0250b6c345b952a4
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Nov 12 14:03:45 2021 +0000

    Special case of CDF/SF for the Poisson distribution with x=0
    
    The value can be computed exactly without having to call the
    RegularizedGamma function.
---
 .../apache/commons/statistics/distribution/PoissonDistribution.java  | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/PoissonDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/PoissonDistribution.java
index e40aaf1..b1b3d45 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/PoissonDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/PoissonDistribution.java
@@ -111,6 +111,8 @@ public final class PoissonDistribution extends AbstractDiscreteDistribution {
     public double cumulativeProbability(int x) {
         if (x < 0) {
             return 0;
+        } else if (x == 0) {
+            return Math.exp(-mean);
         }
         return RegularizedGamma.Q.value((double) x + 1, mean, epsilon,
                                         maxIterations);
@@ -121,6 +123,9 @@ public final class PoissonDistribution extends AbstractDiscreteDistribution {
     public double survivalProbability(int x) {
         if (x < 0) {
             return 1;
+        } else if (x == 0) {
+            // 1 - exp(-mean)
+            return -Math.expm1(-mean);
         }
         return RegularizedGamma.P.value((double) x + 1, mean, epsilon,
                                         maxIterations);