MATH-1356
Handle special cases for which the computation would otherwise produce NaN. Thanks to Thomas Lacroix for the report.
This commit is contained in:
parent
3066a8085f
commit
0880a21c56
|
@ -159,6 +159,9 @@ final class SaddlePointExpansion {
|
|||
}
|
||||
ret = s1;
|
||||
} else {
|
||||
if (x == 0) {
|
||||
return mu;
|
||||
}
|
||||
ret = x * FastMath.log(x / mu) + mu - x;
|
||||
}
|
||||
return ret;
|
||||
|
@ -180,6 +183,9 @@ final class SaddlePointExpansion {
|
|||
if (p < 0.1) {
|
||||
ret = -getDeviancePart(n, n * q) - n * p;
|
||||
} else {
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
}
|
||||
ret = n * FastMath.log(q);
|
||||
}
|
||||
} else if (x == n) {
|
||||
|
|
|
@ -311,6 +311,32 @@ public class HypergeometricDistributionTest extends IntegerDistributionAbstractT
|
|||
Assert.assertTrue(Precision.compareTo(1.0, upper, 1) == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroTrial() {
|
||||
final int n = 11; // population
|
||||
final int m = 4; // successes in population
|
||||
final int s = 0; // number of trials
|
||||
|
||||
final HypergeometricDistribution dist = new HypergeometricDistribution(n, m, 0);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
final double p = dist.probability(i);
|
||||
Assert.assertEquals("p=" + p, 0, p, 0d);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMath1356() {
|
||||
final int n = 11; // population
|
||||
final int m = 11; // successes in population
|
||||
|
||||
for (int s = 0; s <= n; s++) {
|
||||
final HypergeometricDistribution dist = new HypergeometricDistribution(n, m, s);
|
||||
final double p = dist.probability(s);
|
||||
Assert.assertEquals("p=" + p, 1, p, 0d);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMath1021() {
|
||||
final int N = 43130568;
|
||||
|
|
Loading…
Reference in New Issue