From 66dece126a7a3130cc79b44e0527b8b5eea41bcc Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Sat, 8 Sep 2012 22:15:32 +0000 Subject: [PATCH] Clarified definition of isSupportXxxBoundInclusive in RealDistribution interface, made code consistent with the definition, and deprecated these methods, marking for removal in 4.0. JIRA: MATH-859 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1382380 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 5 +++ .../math3/distribution/FDistribution.java | 2 +- .../math3/distribution/RealDistribution.java | 20 ++++++++---- .../distribution/UniformRealDistribution.java | 2 +- .../RealDistributionAbstractTest.java | 32 +++++++++++++++++++ 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e07d8c3ae..ec44dd50f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -52,6 +52,11 @@ If the output is not quite correct, check for invisible trailing spaces! + + Clarified definition of isSupportXxxBoundInclusive in RealDistribution + interface, made code consistent with the definition, and deprecated + these methods, marking for removal in 4.0. + Performance improvement in computation of the greatest common divisor (in class "o.a.c.m.util.ArithmeticUtils"). diff --git a/src/main/java/org/apache/commons/math3/distribution/FDistribution.java b/src/main/java/org/apache/commons/math3/distribution/FDistribution.java index 8b0993c4d..e301e2ef5 100644 --- a/src/main/java/org/apache/commons/math3/distribution/FDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/FDistribution.java @@ -272,7 +272,7 @@ public class FDistribution extends AbstractRealDistribution { /** {@inheritDoc} */ public boolean isSupportLowerBoundInclusive() { - return true; + return false; } /** {@inheritDoc} */ diff --git a/src/main/java/org/apache/commons/math3/distribution/RealDistribution.java b/src/main/java/org/apache/commons/math3/distribution/RealDistribution.java index f09c5acbe..90dc8fdeb 100644 --- a/src/main/java/org/apache/commons/math3/distribution/RealDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/RealDistribution.java @@ -137,18 +137,26 @@ public interface RealDistribution { double getSupportUpperBound(); /** - * Use this method to get information about whether the lower bound - * of the support is inclusive or not. + * Whether or not the lower bound of support is in the domain of the density + * function. Returns true iff {@code getSupporLowerBound()} is finite and + * {@code density(getSupportLowerBound())} returns a non-NaN, non-infinite + * value. * - * @return whether the lower bound of the support is inclusive or not + * @return true if the lower bound of support is finite and the density + * function returns a non-NaN, non-infinite value there + * @deprecated to be removed in 4.0 */ boolean isSupportLowerBoundInclusive(); /** - * Use this method to get information about whether the upper bound - * of the support is inclusive or not. + * Whether or not the upper bound of support is in the domain of the density + * function. Returns true iff {@code getSupportUpperBound()} is finite and + * {@code density(getSupportUpperBound())} returns a non-NaN, non-infinite + * value. * - * @return whether the upper bound of the support is inclusive or not + * @return true if the upper bound of support is finite and the density + * function returns a non-NaN, non-infinite value there + * @deprecated to be removed in 4.0 */ boolean isSupportUpperBoundInclusive(); diff --git a/src/main/java/org/apache/commons/math3/distribution/UniformRealDistribution.java b/src/main/java/org/apache/commons/math3/distribution/UniformRealDistribution.java index 5d32f6ebf..0d279de1f 100644 --- a/src/main/java/org/apache/commons/math3/distribution/UniformRealDistribution.java +++ b/src/main/java/org/apache/commons/math3/distribution/UniformRealDistribution.java @@ -181,7 +181,7 @@ public class UniformRealDistribution extends AbstractRealDistribution { /** {@inheritDoc} */ public boolean isSupportUpperBoundInclusive() { - return false; + return true; } /** diff --git a/src/test/java/org/apache/commons/math3/distribution/RealDistributionAbstractTest.java b/src/test/java/org/apache/commons/math3/distribution/RealDistributionAbstractTest.java index 1c41113fa..c693b1404 100644 --- a/src/test/java/org/apache/commons/math3/distribution/RealDistributionAbstractTest.java +++ b/src/test/java/org/apache/commons/math3/distribution/RealDistributionAbstractTest.java @@ -338,6 +338,38 @@ public abstract class RealDistributionAbstractTest { integrationTestPoints.get(i)), tol); } } + + /** + * Verify that isSupportLowerBoundInclusvie returns true iff the lower bound + * is finite and density is non-NaN, non-infinite there. + */ + @Test + public void testIsSupportLowerBoundInclusive() { + final double lowerBound = distribution.getSupportLowerBound(); + double result = Double.NaN; + result = distribution.density(lowerBound); + Assert.assertEquals( + !Double.isInfinite(lowerBound) && !Double.isNaN(result) && + !Double.isInfinite(result), + distribution.isSupportLowerBoundInclusive()); + + } + + /** + * Verify that isSupportUpperBoundInclusvie returns true iff the upper bound + * is finite and density is non-NaN, non-infinite there. + */ + @Test + public void testIsSupportUpperBoundInclusive() { + final double upperBound = distribution.getSupportUpperBound(); + double result = Double.NaN; + result = distribution.density(upperBound); + Assert.assertEquals( + !Double.isInfinite(upperBound) && !Double.isNaN(result) && + !Double.isInfinite(result), + distribution.isSupportUpperBoundInclusive()); + + } //------------------ Getters / Setters for test instance data ----------- /**