[MATH-1276] Improved performance of sampling and inverse cumulative

probability calculation for geometric distributions.
This commit is contained in:
Otmar Ertl 2015-09-20 21:01:25 +02:00
parent 7fe8a8aff6
commit df1db29ab4
2 changed files with 21 additions and 0 deletions

View File

@ -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>

View File

@ -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)));
}
}