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
commit a5892daac03a09ad44478499c3dc28ab6da27a21 Author: aherbert <[email protected]> AuthorDate: Fri Jan 21 16:59:10 2022 +0000 Remove checkedProbability method from the inverse This method is only of use for bug reporting extremely an unlikely event. It will negatively impact performance for all distributions during computation of the inverse. The extreme bounds of discrete distributions are tested in unit tests. Any distributions where NaN values are potentially expected (e.g. zero divide by zero; infinity - infinity) should use units tests to check extreme parameterisations. --- .../distribution/AbstractDiscreteDistribution.java | 24 ++-------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java index e519bbc..81b426c 100644 --- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java +++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractDiscreteDistribution.java @@ -164,8 +164,8 @@ abstract class AbstractDiscreteDistribution // cdf(x) >= p // sf(x) <= q final IntUnaryOperator fun = complement ? - x -> Double.compare(q, checkedProbability(survivalProbability(x))) : - x -> Double.compare(checkedProbability(cumulativeProbability(x)), p); + x -> Double.compare(q, survivalProbability(x)) : + x -> Double.compare(cumulativeProbability(x), p); if (lower == Integer.MIN_VALUE) { if (fun.applyAsInt(lower) >= 0) { @@ -238,26 +238,6 @@ abstract class AbstractDiscreteDistribution return (int) upper; } - /** - * Checks the probability function result for {@code NaN}. - * Throws {@code IllegalStateException} if the cumulative - * probability function returns {@code NaN}. - * - * <p>TODO: Q. Is this required? The bisection search will - * eventually return if NaN is computed. Check the origin - * of this in Commons Math. Its origins may be for debugging. - * - * @param result Probability - * @return the probability. - * @throws IllegalStateException if the probability is {@code NaN}. - */ - private static double checkedProbability(double result) { - if (Double.isNaN(result)) { - throw new IllegalStateException("Internal error"); - } - return result; - } - /** {@inheritDoc} */ @Override public DiscreteDistribution.Sampler createSampler(final UniformRandomProvider rng) {
