You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oe...@apache.org on 2015/09/20 21:06:51 UTC
[8/8] [math] [MATH-1276] Improved performance of sampling and inverse
cumulative probability calculation for geometric distributions.
[MATH-1276] Improved performance of sampling and inverse cumulative
probability calculation for geometric distributions.
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/df1db29a
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/df1db29a
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/df1db29a
Branch: refs/heads/MATH_3_X
Commit: df1db29ab401e5fd867f142f949e8feda12604d4
Parents: 7fe8a8a
Author: Otmar Ertl <ot...@gmail.com>
Authored: Sun Sep 20 21:01:25 2015 +0200
Committer: Otmar Ertl <ot...@gmail.com>
Committed: Sun Sep 20 21:01:25 2015 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 4 ++++
.../math3/distribution/GeometricDistribution.java | 17 +++++++++++++++++
2 files changed, 21 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/df1db29a/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 61240bc..e7c9ca1 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -51,6 +51,10 @@ If the output is not quite correct, check for invisible trailing spaces!
</properties>
<body>
<release version="3.6" date="XXXX-XX-XX" description="">
+ <action dev="oertl" type="update" issue="MATH-1276">
+ Improved performance of sampling and inverse cumulative probability calculation
+ for geometric distributions.
+ </action>
<action dev="oertl" type="fix" issue="MATH-1277" due-to="Marc Rosen">
Fixed incorrect Kendall's tau coefficient calculation due to internal integer overflow.
</action>
http://git-wip-us.apache.org/repos/asf/commons-math/blob/df1db29a/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java b/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
index 20ff7bc..89ffcb6 100644
--- a/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
+++ b/src/main/java/org/apache/commons/math3/distribution/GeometricDistribution.java
@@ -165,4 +165,21 @@ public class GeometricDistribution extends AbstractIntegerDistribution {
public boolean isSupportConnected() {
return true;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int inverseCumulativeProbability(double p) throws OutOfRangeException {
+ if (p < 0 || p > 1) {
+ throw new OutOfRangeException(p, 0, 1);
+ }
+ if (p == 1) {
+ return Integer.MAX_VALUE;
+ }
+ if (p == 0) {
+ return 0;
+ }
+ return Math.max(0, (int) Math.ceil((FastMath.log1p(-p)/log1mProbabilityOfSuccess-1)));
+ }
}