Skip to content

Commit

Permalink
MATH-1462: Extend workaround for bins that contain up to 3 values.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles Sadowski committed Sep 26, 2021
1 parent d4de59a commit 3a5cf27
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Expand Up @@ -409,7 +409,8 @@ public double inverseCumulativeProbability(final double p) {
++i;
}

final ContinuousDistribution kernel = getKernel(binStats.get(i));
final SummaryStatistics stats = binStats.get(i);
final ContinuousDistribution kernel = getKernel(stats);
final double kB = kB(i);
final double[] binBounds = getUpperBounds();
final double lower = i == 0 ? min : binBounds[i - 1];
Expand Down Expand Up @@ -546,7 +547,7 @@ private ContinuousDistribution getKernel(SummaryStatistics stats) {
*/
private static Function<SummaryStatistics, ContinuousDistribution> defaultKernel() {
return stats -> {
if (stats.getN() <= 1 ||
if (stats.getN() <= 3 ||
stats.getVariance() == 0) {
return new ConstantContinuousDistribution(stats.getMean());
} else {
Expand Down
Expand Up @@ -489,13 +489,12 @@ public void testMath1462InfiniteQuantile() {
6212, 5961, 711
};

final EmpiricalDistribution ed = EmpiricalDistribution.from(1000, data);
final double p = 0.32;
for (int i = 745; i <= 1100; i++) {
final EmpiricalDistribution ed = EmpiricalDistribution.from(i, data);
final double v = ed.inverseCumulativeProbability(p);

double v;
double p;

p = 0.32;
v = ed.inverseCumulativeProbability(p);
Assert.assertTrue("p=" + p + " => v=" + v, Double.isFinite(v));
Assert.assertTrue("p=" + p + " => v=" + v, Double.isFinite(v));
}
}
}
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Expand Up @@ -97,6 +97,9 @@ Caveat:
nightmare was one of the main reasons for creating more focused
components.]
">
<action dev="erans" type="fix" issue="MATH-1462">
"EmpiricalDistribution": Use constant kernel for bins that contain up to 3 values.
</action>
<action dev="aherbert" due-to="Arturo Bernal" type="update">
Simplify assertions with simpler equivalent.
</action>
Expand Down

0 comments on commit 3a5cf27

Please sign in to comment.