From 79c2fc7a523977cd8b567980de4f8be73633c1ea Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Mon, 3 Jan 2011 04:59:18 +0000 Subject: [PATCH] Restored backward compatibility in distributions classes. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1054524 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractContinuousDistribution.java | 13 -- .../distribution/AbstractDistribution.java | 114 ------------------ .../AbstractIntegerDistribution.java | 16 --- .../distribution/BetaDistributionImpl.java | 53 +++----- .../BinomialDistributionImpl.java | 26 ++-- .../distribution/CauchyDistributionImpl.java | 54 +++------ .../ChiSquaredDistributionImpl.java | 41 ++----- .../math/distribution/Distribution.java | 54 --------- .../ExponentialDistributionImpl.java | 48 +++----- .../math/distribution/FDistributionImpl.java | 48 +++----- .../distribution/GammaDistributionImpl.java | 48 +++----- .../HypergeometricDistributionImpl.java | 27 ++--- .../distribution/NormalDistributionImpl.java | 46 ++----- .../distribution/PascalDistributionImpl.java | 36 ++---- .../distribution/PoissonDistributionImpl.java | 36 ++---- .../math/distribution/TDistributionImpl.java | 40 ++---- .../distribution/WeibullDistributionImpl.java | 76 +++++++++--- .../distribution/ZipfDistributionImpl.java | 26 ++-- .../distribution/BetaDistributionTest.java | 2 +- .../BinomialDistributionTest.java | 2 +- .../distribution/CauchyDistributionTest.java | 2 +- .../ChiSquareDistributionTest.java | 2 +- .../ExponentialDistributionTest.java | 2 +- .../math/distribution/FDistributionTest.java | 2 +- .../distribution/GammaDistributionTest.java | 2 +- .../HypergeometricDistributionTest.java | 2 +- .../distribution/NormalDistributionTest.java | 5 +- .../distribution/PascalDistributionTest.java | 2 +- .../distribution/PoissonDistributionTest.java | 4 +- .../math/distribution/TDistributionTest.java | 2 +- .../distribution/WeibullDistributionTest.java | 2 +- .../distribution/ZipfDistributionTest.java | 2 +- 32 files changed, 239 insertions(+), 596 deletions(-) diff --git a/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java b/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java index 15b65b971..7b3827e3d 100644 --- a/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java +++ b/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java @@ -228,17 +228,4 @@ public abstract class AbstractContinuousDistribution return solverAbsoluteAccuracy; } - /** - * Access the lower bound of the support. - * - * @return lower bound of the support (might be Double.NEGATIVE_INFINITY) - */ - public abstract double getSupportLowerBound(); - - /** - * Access the upper bound of the support. - * - * @return upper bound of the support (might be Double.POSITIVE_INFINITY) - */ - public abstract double getSupportUpperBound(); } diff --git a/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java b/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java index 469f2edd1..8c22e4f63 100644 --- a/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java +++ b/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java @@ -33,18 +33,6 @@ public abstract class AbstractDistribution /** Serializable version identifier */ private static final long serialVersionUID = -38038050983108802L; - /** Cached numerical mean */ - private double numericalMean = Double.NaN; - - /** Whether or not the numerical mean has been calculated */ - private boolean numericalMeanIsCalculated = false; - - /** Cached numerical variance */ - private double numericalVariance = Double.NaN; - - /** Whether or not the numerical variance has been calculated */ - private boolean numericalVarianceIsCalculated = false; - /** * Default constructor. */ @@ -78,106 +66,4 @@ public abstract class AbstractDistribution } return cumulativeProbability(x1) - cumulativeProbability(x0); } - - /** - * This method invalidates cached moments when parameters change. - * Usually it is called from a sub-class when the distribution - * gets its parameters updated. - * - * @deprecated as of 2.2 (sub-classes will become immutable in 3.0) - */ - @Deprecated - protected void invalidateParameterDependentMoments() { - numericalMeanIsCalculated = false; - numericalVarianceIsCalculated = false; - } - - /** - * Use this method to actually calculate the mean for the - * specific distribution. Use {@link #getNumericalMean()} - * (which implements caching) to actually get the mean. - * - * @return the mean or Double.NaN if it's not defined - */ - protected abstract double calculateNumericalMean(); - - /** - * Use this method to get the numerical value of the mean of this - * distribution. - * - * @return the mean or Double.NaN if it's not defined - */ - public double getNumericalMean() { - if (!numericalMeanIsCalculated) { - numericalMean = calculateNumericalMean(); - numericalMeanIsCalculated = true; - } - - return numericalMean; - } - - /** - * Use this method to actually calculate the variance for the - * specific distribution. Use {@link #getNumericalVariance()} - * (which implements caching) to actually get the variance. - * - * @return the variance or Double.NaN if it's not defined - */ - protected abstract double calculateNumericalVariance(); - - /** - * Use this method to get the numerical value of the variance of this - * distribution. - * - * @return the variance (possibly Double.POSITIVE_INFINITY as - * for certain cases in {@link TDistributionImpl}) or - * Double.NaN if it's not defined - */ - public double getNumericalVariance() { - if (!numericalVarianceIsCalculated) { - numericalVariance = calculateNumericalVariance(); - numericalVarianceIsCalculated = true; - } - - return numericalVariance; - } - - /** - * Use this method to get information about whether the lower bound - * of the support is inclusive or not. - * - * @return whether the lower bound of the support is inclusive or not - */ - public abstract boolean isSupportLowerBoundInclusive(); - - /** - * Use this method to get information about whether the upper bound - * of the support is inclusive or not. - * - * @return whether the upper bound of the support is inclusive or not - */ - public abstract boolean isSupportUpperBoundInclusive(); - - /** - * Use this method to get information about whether the support is connected, - * i.e. whether all values between the lower and upper bound of the support - * is included in the support. - * - * For {@link AbstractIntegerDistribution} the support is discrete, so - * if this is true, then the support is - * {lower bound, lower bound + 1, ..., upper bound}. - * - * For {@link AbstractContinuousDistribution} the support is continuous, so - * if this is true, then the support is the interval - * [lower bound, upper bound] - * where the limits are inclusive or not according to - * {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()} - * (in the example both are true). If both are false, then the support is the interval - * (lower bound, upper bound) - * - * @return whether the support limits given by subclassed methods are connected or not - */ - public boolean isSupportConnected() { - return true; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java b/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java index c20c7f825..bfe6abf32 100644 --- a/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java +++ b/src/main/java/org/apache/commons/math/distribution/AbstractIntegerDistribution.java @@ -293,20 +293,6 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution */ protected abstract int getDomainUpperBound(double p); - /** - * Access the lower bound of the support. - * - * @return lower bound of the support (Integer.MIN_VALUE for negative infinity) - */ - public abstract int getSupportLowerBound(); - - /** - * Access the upper bound of the support. - * - * @return upper bound of the support (Integer.MAX_VALUE for positive infinity) - */ - public abstract int getSupportUpperBound(); - /** * Use this method to get information about whether the lower bound * of the support is inclusive or not. For discrete support, @@ -314,7 +300,6 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution * * @return true (always but at Integer.MIN_VALUE because of the nature of discrete support) */ - @Override public boolean isSupportLowerBoundInclusive() { return true; } @@ -326,7 +311,6 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution * * @return true (always but at Integer.MAX_VALUE because of the nature of discrete support) */ - @Override public boolean isSupportUpperBoundInclusive() { return true; } diff --git a/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java index 3ab3b594b..a2752500d 100644 --- a/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java @@ -39,7 +39,7 @@ public class BetaDistributionImpl extends AbstractContinuousDistribution implements BetaDistribution { /** - * Default inverse cumulative probability accurac + * Default inverse cumulative probability accuracy * @since 2.1 */ public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9; @@ -92,7 +92,6 @@ public class BetaDistributionImpl public void setAlpha(double alpha) { this.alpha = alpha; z = Double.NaN; - invalidateParameterDependentMoments(); } /** {@inheritDoc} */ @@ -107,7 +106,6 @@ public class BetaDistributionImpl public void setBeta(double beta) { this.beta = beta; z = Double.NaN; - invalidateParameterDependentMoments(); } /** {@inheritDoc} */ @@ -227,75 +225,60 @@ public class BetaDistributionImpl } /** - * {@inheritDoc} - * - * The lower bound of the support is always 0 no matter the parameters. + * Returns the lower bound of the support for this distribution. + * The support of the Beta distribution is always [0, 1], regardless + * of the parameters, so this method always returns 0. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for this distribution. + * The support of the Beta distribution is always [0, 1], regardless + * of the parameters, so this method always returns 1. * - * The upper bound of the support is always 1 no matter the parameters. - * - * @return upper bound of the support (always 1) + * @return lower bound of the support (always 1) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return 1; } /** - * {@inheritDoc} + * Returns the mean. * * For first shape parameter s1 and * second shape parameter s2, the mean is * s1 / (s1 + s2) * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { final double a = getAlpha(); return a / (a + getBeta()); } /** - * {@inheritDoc} + * Returns the variance. * * For first shape parameter s1 and * second shape parameter s2, * the variance is * [ s1 * s2 ] / [ (s1 + s2)^2 * (s1 + s2 + 1) ] * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double a = getAlpha(); final double b = getBeta(); final double alphabetasum = a + b; return (a * b) / ((alphabetasum * alphabetasum) * (alphabetasum + 1)); } - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java index 11fe7a6e7..aa808eb29 100644 --- a/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/BinomialDistributionImpl.java @@ -83,7 +83,6 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setNumberOfTrials(int trials) { setNumberOfTrialsInternal(trials); - invalidateParameterDependentMoments(); } /** @@ -112,7 +111,6 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setProbabilityOfSuccess(double p) { setProbabilityOfSuccessInternal(p); - invalidateParameterDependentMoments(); } /** @@ -226,55 +224,55 @@ public class BinomialDistributionImpl extends AbstractIntegerDistribution } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always 0 no matter the number of trials * and probability parameter. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public int getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * * The upper bound of the support is the number of trials. * * @return upper bound of the support (equal to number of trials) + * @since 2.2 */ - @Override public int getSupportUpperBound() { return getNumberOfTrials(); } /** - * {@inheritDoc} + * Returns the mean. * * For n number of trials and * probability parameter p, the mean is * n * p * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { return (double)getNumberOfTrials() * getProbabilityOfSuccess(); } /** - * {@inheritDoc} + * Returns the variance. * * For n number of trials and * probability parameter p, the variance is * n * p * (1 - p) * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double p = getProbabilityOfSuccess(); return (double)getNumberOfTrials() * p * (1 - p); } diff --git a/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java index 764b9425f..1952141d4 100644 --- a/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java @@ -86,7 +86,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution /** * For this distribution, X, this method returns P(X < x). * @param x the value at which the CDF is evaluated. - * @return CDF evaluted at x. + * @return CDF evaluated at x. */ public double cumulativeProbability(double x) { return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI); @@ -157,7 +157,6 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution @Deprecated public void setMedian(double median) { setMedianInternal(median); - invalidateParameterDependentMoments(); } /** @@ -177,7 +176,6 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution @Deprecated public void setScale(double s) { setScaleInternal(s); - invalidateParameterDependentMoments(); } /** @@ -273,68 +271,50 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution } /** - * {@inheritDoc} - * - * The lower bound of the support is always negative infinity no matter - * the parameters. + * Returns the lower bound of the support for this distribution. + * The lower bound of the support of the Cauchy distribution is always + * negative infinity, regardless of the parameters. * * @return lower bound of the support (always Double.NEGATIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return Double.NEGATIVE_INFINITY; } /** - * {@inheritDoc} - * - * The upper bound of the support is always positive infinity no matter - * the parameters. + * Returns the upper bound of the support for this distribution. + * The upper bound of the support of the Cauchy distribution is always + * positive infinity, regardless of the parameters. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the mean. * - * The mean is always undefined no matter the parameters. + * The mean is always undefined, regardless of the parameters. * * @return mean (always Double.NaN) + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { return Double.NaN; } /** - * {@inheritDoc} + * Returns the variance. * - * The variance is always undefined no matter the parameters. + * The variance is always undefined, regardless of the parameters. * * @return variance (always Double.NaN) + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { return Double.NaN; } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java index 3611895d8..dca4028da 100644 --- a/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java @@ -91,7 +91,6 @@ public class ChiSquaredDistributionImpl @Deprecated public void setDegreesOfFreedom(double degreesOfFreedom) { setDegreesOfFreedomInternal(degreesOfFreedom); - invalidateParameterDependentMoments(); } /** * Modify the degrees of freedom. @@ -272,70 +271,54 @@ public class ChiSquaredDistributionImpl } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always 0 no matter the * degrees of freedom. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound for the support for the distribution. * * The upper bound of the support is always positive infinity no matter the * degrees of freedom. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the mean of the distribution. * * For k degrees of freedom, the mean is * k * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { return getDegreesOfFreedom(); } /** - * {@inheritDoc} + * Returns the variance of the distribution. * * For k degrees of freedom, the variance is * 2 * k * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { return 2*getDegreesOfFreedom(); } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/Distribution.java b/src/main/java/org/apache/commons/math/distribution/Distribution.java index 2b58d8588..9b0a9e876 100644 --- a/src/main/java/org/apache/commons/math/distribution/Distribution.java +++ b/src/main/java/org/apache/commons/math/distribution/Distribution.java @@ -53,58 +53,4 @@ public interface Distribution { */ double cumulativeProbability(double x0, double x1) throws MathException; - /** - * Use this method to get the numerical value of the mean of this - * distribution. - * - * @return the mean or Double.NaN if it's not defined - */ - double getNumericalMean(); - - /** - * Use this method to get the numerical value of the variance of this - * distribution. - * - * @return the variance (possibly Double.POSITIVE_INFINITY as - * for certain cases in {@link TDistributionImpl}) or - * Double.NaN if it's not defined - */ - double getNumericalVariance(); - - /** - * Use this method to get information about whether the lower bound - * of the support is inclusive or not. - * - * @return whether the lower bound of the support is inclusive or not - */ - boolean isSupportLowerBoundInclusive(); - - /** - * Use this method to get information about whether the upper bound - * of the support is inclusive or not. - * - * @return whether the upper bound of the support is inclusive or not - */ - boolean isSupportUpperBoundInclusive(); - - /** - * Use this method to get information about whether the support is connected, - * i.e. whether all values between the lower and upper bound of the support - * is included in the support. - * - * For {@link AbstractIntegerDistribution} the support is discrete, so - * if this is true, then the support is - * {lower bound, lower bound + 1, ..., upper bound}. - * - * For {@link AbstractContinuousDistribution} the support is continuous, so - * if this is true, then the support is the interval - * [lower bound, upper bound] - * where the limits are inclusive or not according to - * {@link #isSupportLowerBoundInclusive()} and {@link #isSupportUpperBoundInclusive()} - * (in the example both are true). If both are false, then the support is the interval - * (lower bound, upper bound) - * - * @return whether the support limits given by subclassed methods are connected or not - */ - boolean isSupportConnected(); } diff --git a/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java index 8cf198478..f7a3e2920 100644 --- a/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java @@ -76,7 +76,6 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution @Deprecated public void setMean(double mean) { setMeanInternal(mean); - invalidateParameterDependentMoments(); } /** * Modify the mean. @@ -204,7 +203,6 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution * @return domain value lower bound, i.e. * P(X < lower bound) < p */ - @Override protected double getDomainLowerBound(double p) { return 0; } @@ -217,7 +215,6 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution * @return domain value upper bound, i.e. * P(X < upper bound) > p */ - @Override protected double getDomainUpperBound(double p) { // NOTE: exponential is skewed to the left // NOTE: therefore, P(X < μ) > .5 @@ -266,70 +263,55 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * - * The lower bound of the support is always 0 no matter the mean parameter. + * The lower bound of the support is always 0, regardless of the mean. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * - * The upper bound of the support is always positive infinity - * no matter the mean parameter. + * The upper bound of the support is always positive infinity, + * regardless of the mean. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the mean of the distribution. * * For mean parameter k, the mean is * k * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { return getMean(); } /** - * {@inheritDoc} + * Returns the variance of the distribution. * * For mean parameter k, the variance is * k^2 * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double m = getMean(); return m * m; } - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java index eb4fa0e7f..fc6c4377d 100644 --- a/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java @@ -209,7 +209,6 @@ public class FDistributionImpl @Deprecated public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) { setNumeratorDegreesOfFreedomInternal(degreesOfFreedom); - invalidateParameterDependentMoments(); } /** @@ -244,7 +243,6 @@ public class FDistributionImpl @Deprecated public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) { setDenominatorDegreesOfFreedomInternal(degreesOfFreedom); - invalidateParameterDependentMoments(); } /** @@ -282,32 +280,32 @@ public class FDistributionImpl } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * - * The lower bound of the support is always 0 no matter the parameters. + * The lower bound of the support is always 0, regardless of the parameters. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * - * The upper bound of the support is always positive infinity - * no matter the parameters. + * The upper bound of the support is always positive infinity, + * regardless of the parameters. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the mean of the distribution. * * For denominator degrees of freedom parameter b, * the mean is @@ -316,10 +314,10 @@ public class FDistributionImpl *
  • else undefined * * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { final double denominatorDF = getDenominatorDegreesOfFreedom(); if (denominatorDF > 2) { @@ -330,7 +328,7 @@ public class FDistributionImpl } /** - * {@inheritDoc} + * Returns the variance of the distribution. * * For numerator degrees of freedom parameter a * and denominator degrees of freedom parameter b, @@ -343,10 +341,10 @@ public class FDistributionImpl *
  • else undefined * * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double denominatorDF = getDenominatorDegreesOfFreedom(); if (denominatorDF > 4) { @@ -359,20 +357,4 @@ public class FDistributionImpl return Double.NaN; } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java index b35758a9c..499cc6794 100644 --- a/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java @@ -137,7 +137,6 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution @Deprecated public void setAlpha(double alpha) { setAlphaInternal(alpha); - invalidateParameterDependentMoments(); } /** @@ -171,7 +170,6 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution @Deprecated public void setBeta(double newBeta) { setBetaInternal(newBeta); - invalidateParameterDependentMoments(); } /** @@ -302,72 +300,56 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * - * The lower bound of the support is always 0 no matter the parameters. + * The lower bound of the support is always 0, regardless of the parameters. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * - * The upper bound of the support is always positive infinity - * no matter the parameters. + * The upper bound of the support is always positive infinity, + * regardless of the parameters. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the mean. * * For shape parameter alpha and scale * parameter beta, the mean is * alpha * beta * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { return getAlpha() * getBeta(); } /** - * {@inheritDoc} + * Returns the variance. * * For shape parameter alpha and scale * parameter beta, the variance is * alpha * beta^2 * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double b = getBeta(); return getAlpha() * b * b; } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java index 4764085f9..6758ebbd9 100644 --- a/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/HypergeometricDistributionImpl.java @@ -241,7 +241,6 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setNumberOfSuccesses(int num) { setNumberOfSuccessesInternal(num); - invalidateParameterDependentMoments(); } /** @@ -268,7 +267,6 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setPopulationSize(int size) { setPopulationSizeInternal(size); - invalidateParameterDependentMoments(); } /** @@ -295,7 +293,6 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setSampleSize(int size) { setSampleSizeInternal(size); - invalidateParameterDependentMoments(); } /** * Modify the sample size. @@ -358,7 +355,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution } /** - * {@inheritDoc} + * Returns the lower bound for the support for the distribution. * * For population size N, * number of successes m, and @@ -367,15 +364,15 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution * max(0, n + m - N) * * @return lower bound of the support + * @since 2.2 */ - @Override public int getSupportLowerBound() { return FastMath.max(0, getSampleSize() + getNumberOfSuccesses() - getPopulationSize()); } /** - * {@inheritDoc} + * Returns the upper bound for the support of the distribution. * * For number of successes m and * sample size n, @@ -383,39 +380,39 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution * min(m, n) * * @return upper bound of the support + * @since 2.2 */ - @Override public int getSupportUpperBound() { return FastMath.min(getNumberOfSuccesses(), getSampleSize()); } /** - * {@inheritDoc} + * Returns the mean. * * For population size N, * number of successes m, and * sample size n, the mean is * n * m / N * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + protected double getNumericalMean() { return (double)(getSampleSize() * getNumberOfSuccesses()) / (double)getPopulationSize(); } /** - * {@inheritDoc} + * Returns the variance. * * For population size N, * number of successes m, and * sample size n, the variance is * [ n * m * (N - n) * (N - m) ] / [ N^2 * (N - 1) ] * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double N = getPopulationSize(); final double m = getNumberOfSuccesses(); final double n = getSampleSize(); diff --git a/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java index cd5ddeea9..781257b1c 100644 --- a/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java @@ -104,7 +104,6 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution @Deprecated public void setMean(double mean) { setMeanInternal(mean); - invalidateParameterDependentMoments(); } /** @@ -132,7 +131,6 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution @Deprecated public void setStandardDeviation(double sd) { setStandardDeviationInternal(sd); - invalidateParameterDependentMoments(); } /** @@ -310,70 +308,42 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always negative infinity * no matter the parameters. * * @return lower bound of the support (always Double.NEGATIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return Double.NEGATIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * * The upper bound of the support is always positive infinity * no matter the parameters. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} - * - * For mean parameter mu, the mean is mu - * - * @return {@inheritDoc} - */ - @Override - protected double calculateNumericalMean() { - return getMean(); - } - - /** - * {@inheritDoc} + * Returns the variance. * * For standard deviation parameter s, * the variance is s^2 * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double s = getStandardDeviation(); return s * s; } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java index d3fb19618..82b5e43c8 100644 --- a/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/PascalDistributionImpl.java @@ -80,7 +80,6 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setNumberOfSuccesses(int successes) { setNumberOfSuccessesInternal(successes); - invalidateParameterDependentMoments(); } /** @@ -108,7 +107,6 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setProbabilityOfSuccess(double p) { setProbabilityOfSuccessInternal(p); - invalidateParameterDependentMoments(); } /** @@ -217,70 +215,62 @@ public class PascalDistributionImpl extends AbstractIntegerDistribution } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always 0 no matter the parameters. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public int getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * * The upper bound of the support is always positive infinity - * no matter the parameters. Positive infinity is symbolised + * no matter the parameters. Positive infinity is represented * by Integer.MAX_VALUE together with * {@link #isSupportUpperBoundInclusive()} being false * * @return upper bound of the support (always Integer.MAX_VALUE for positive infinity) + * @since 2.2 */ - @Override public int getSupportUpperBound() { return Integer.MAX_VALUE; } /** - * {@inheritDoc} + * Returns the mean. * * For number of successes r and * probability of success p, the mean is * ( r * p ) / ( 1 - p ) * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { final double p = getProbabilityOfSuccess(); final double r = getNumberOfSuccesses(); return ( r * p ) / ( 1 - p ); } /** - * {@inheritDoc} + * Returns the variance. * * For number of successes r and * probability of success p, the mean is * ( r * p ) / ( 1 - p )^2 * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double p = getProbabilityOfSuccess(); final double r = getNumberOfSuccesses(); final double pInv = 1 - p; return ( r * p ) / (pInv * pInv); } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java index c92561c92..fece32a68 100644 --- a/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/PoissonDistributionImpl.java @@ -157,7 +157,6 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setMean(double p) { setNormalAndMeanInternal(normal, p); - invalidateParameterDependentMoments(); } /** * Set the Poisson mean for the distribution. The mean value must be @@ -303,19 +302,19 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always 0 no matter the mean parameter. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public int getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * * The upper bound of the support is positive infinity, * regardless of the parameter values. There is no integer infinity, @@ -323,41 +322,22 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution * {@link #isSupportUpperBoundInclusive()} returns true. * * @return upper bound of the support (always Integer.MAX_VALUE for positive infinity) + * @since 2.2 */ - @Override public int getSupportUpperBound() { return Integer.MAX_VALUE; } /** - * {@inheritDoc} - * - * For mean parameter p, the mean is p - * - * @return {@inheritDoc} - */ - @Override - protected double calculateNumericalMean() { - return getMean(); - } - - /** - * {@inheritDoc} + * Returns the variance of the distribution. * * For mean parameter p, the variance is p * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { return getMean(); } - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return true; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java index 840149fab..59d35fe96 100644 --- a/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java @@ -81,7 +81,6 @@ public class TDistributionImpl @Deprecated public void setDegreesOfFreedom(double degreesOfFreedom) { setDegreesOfFreedomInternal(degreesOfFreedom); - invalidateParameterDependentMoments(); } /** @@ -227,33 +226,33 @@ public class TDistributionImpl } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always negative infinity * no matter the parameters. * * @return lower bound of the support (always Double.NEGATIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return Double.NEGATIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * * The upper bound of the support is always positive infinity * no matter the parameters. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} + * Returns the mean. * * For degrees of freedom parameter df, the mean is * * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + public double getNumericalMean() { final double df = getDegreesOfFreedom(); if (df > 1) { @@ -275,7 +274,7 @@ public class TDistributionImpl } /** - * {@inheritDoc} + * Returns the variance. * * For degrees of freedom parameter df, the variance is * * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + public double getNumericalVariance() { final double df = getDegreesOfFreedom(); if (df > 2) { @@ -301,19 +300,4 @@ public class TDistributionImpl return Double.NaN; } - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportLowerBoundInclusive() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; - } } diff --git a/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java index 1de3ef723..d2a38076a 100644 --- a/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java @@ -52,6 +52,18 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution /** Inverse cumulative probability accuracy */ private final double solverAbsoluteAccuracy; + /** Cached numerical mean */ + private double numericalMean = Double.NaN; + + /** Whether or not the numerical mean has been calculated */ + private boolean numericalMeanIsCalculated = false; + + /** Cached numerical variance */ + private double numericalVariance = Double.NaN; + + /** Whether or not the numerical variance has been calculated */ + private boolean numericalVarianceIsCalculated = false; + /** * Creates weibull distribution with the given shape and scale and a * location equal to zero. @@ -81,7 +93,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution /** * For this distribution, X, this method returns P(X < x). * @param x the value at which the CDF is evaluated. - * @return CDF evaluted at x. + * @return CDF evaluated at x. */ public double cumulativeProbability(double x) { double ret; @@ -264,39 +276,39 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always 0 no matter the parameters. * * @return lower bound of the support (always 0) + * @since 2.2 */ - @Override public double getSupportLowerBound() { return 0; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * * The upper bound of the support is always positive infinity * no matter the parameters. * * @return upper bound of the support (always Double.POSITIVE_INFINITY) + * @since 2.2 */ - @Override public double getSupportUpperBound() { return Double.POSITIVE_INFINITY; } /** - * {@inheritDoc} + * Calculates the mean. * * The mean is scale * Gamma(1 + (1 / shape)) * where Gamma(...) is the Gamma-function * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override protected double calculateNumericalMean() { final double sh = getShape(); final double sc = getScale(); @@ -305,16 +317,16 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution } /** - * {@inheritDoc} + * Calculates the variance. * * The variance is * scale^2 * Gamma(1 + (2 / shape)) - mean^2 * where Gamma(...) is the Gamma-function * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + private double calculateNumericalVariance() { final double sh = getShape(); final double sc = getScale(); final double mn = getNumericalMean(); @@ -325,18 +337,42 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution } /** - * {@inheritDoc} + * Returns the mean of the distribution. + * + * @return the mean or Double.NaN if it's not defined + * @since 2.2 */ - @Override - public boolean isSupportLowerBoundInclusive() { - return true; + public double getNumericalMean() { + if (!numericalMeanIsCalculated) { + numericalMean = calculateNumericalMean(); + numericalMeanIsCalculated = true; + } + + return numericalMean; } /** - * {@inheritDoc} + * Returns the variance of the distribution. + * + * @return the variance (possibly Double.POSITIVE_INFINITY as + * for certain cases in {@link TDistributionImpl}) or + * Double.NaN if it's not defined + * @since 2.2 */ - @Override - public boolean isSupportUpperBoundInclusive() { - return false; + public double getNumericalVariance() { + if (!numericalVarianceIsCalculated) { + numericalVariance = calculateNumericalVariance(); + numericalVarianceIsCalculated = true; + } + + return numericalVariance; + } + + /** + * Invalidates the cached mean and variance. + */ + private void invalidateParameterDependentMoments() { + numericalMeanIsCalculated = false; + numericalVarianceIsCalculated = false; } } diff --git a/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java b/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java index 0e629f5de..456bf3860 100644 --- a/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java +++ b/src/main/java/org/apache/commons/math/distribution/ZipfDistributionImpl.java @@ -76,7 +76,6 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setNumberOfElements(final int n) { setNumberOfElementsInternal(n); - invalidateParameterDependentMoments(); } /** * Set the number of elements (e.g. corpus size) for the distribution. @@ -116,7 +115,6 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution @Deprecated public void setExponent(final double s) { setExponentInternal(s); - invalidateParameterDependentMoments(); } /** @@ -215,31 +213,31 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution } /** - * {@inheritDoc} + * Returns the lower bound of the support for the distribution. * * The lower bound of the support is always 1 no matter the parameters. * * @return lower bound of the support (always 1) + * @since 2.2 */ - @Override public int getSupportLowerBound() { return 1; } /** - * {@inheritDoc} + * Returns the upper bound of the support for the distribution. * * The upper bound of the support is the number of elements * * @return upper bound of the support + * @since 2.2 */ - @Override public int getSupportUpperBound() { return getNumberOfElements(); } /** - * {@inheritDoc} + * Returns the mean. * * For number of elements N and exponent s, the mean is * Hs1 / Hs where @@ -248,10 +246,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution *
  • Hs = generalizedHarmonic(N, s)
  • * * - * @return {@inheritDoc} + * @return the mean + * @since 2.2 */ - @Override - protected double calculateNumericalMean() { + protected double getNumericalMean() { final int N = getNumberOfElements(); final double s = getExponent(); @@ -262,7 +260,7 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution } /** - * {@inheritDoc} + * Returns the variance. * * For number of elements N and exponent s, the mean is * (Hs2 / Hs) - (Hs1^2 / Hs^2) where @@ -272,10 +270,10 @@ public class ZipfDistributionImpl extends AbstractIntegerDistribution *
  • Hs = generalizedHarmonic(N, s)
  • * * - * @return {@inheritDoc} + * @return the variance + * @since 2.2 */ - @Override - protected double calculateNumericalVariance() { + protected double getNumericalVariance() { final int N = getNumberOfElements(); final double s = getExponent(); diff --git a/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java index b5197c13d..890633653 100644 --- a/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/BetaDistributionTest.java @@ -290,7 +290,7 @@ public class BetaDistributionTest extends TestCase { public void testMomonts() { final double tol = 1e-9; - BetaDistribution dist; + BetaDistributionImpl dist; dist = new BetaDistributionImpl(1, 1); assertEquals(dist.getNumericalMean(), 0.5, tol); diff --git a/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java index d52cd0ef6..60938131b 100644 --- a/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/BinomialDistributionTest.java @@ -115,7 +115,7 @@ public class BinomialDistributionTest extends IntegerDistributionAbstractTest { public void testMomonts() { final double tol = 1e-9; - BinomialDistribution dist; + BinomialDistributionImpl dist; dist = new BinomialDistributionImpl(10, 0.5); assertEquals(dist.getNumericalMean(), 10d * 0.5d, tol); diff --git a/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java index b2ae24b44..313416cf5 100644 --- a/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/CauchyDistributionTest.java @@ -115,7 +115,7 @@ public class CauchyDistributionTest extends ContinuousDistributionAbstractTest } public void testMomonts() { - CauchyDistribution dist; + CauchyDistributionImpl dist; dist = new CauchyDistributionImpl(10.2, 0.15); assertTrue(Double.isNaN(dist.getNumericalMean())); diff --git a/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java index 4a5b9a0d2..e1e1744c3 100644 --- a/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/ChiSquareDistributionTest.java @@ -134,7 +134,7 @@ public class ChiSquareDistributionTest extends ContinuousDistributionAbstractTes public void testMomonts() { final double tol = 1e-9; - ChiSquaredDistribution dist; + ChiSquaredDistributionImpl dist; dist = new ChiSquaredDistributionImpl(1500); assertEquals(dist.getNumericalMean(), 1500, tol); diff --git a/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java index c99088d20..2ca2887d3 100644 --- a/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java @@ -124,7 +124,7 @@ public class ExponentialDistributionTest extends ContinuousDistributionAbstractT public void testMomonts() { final double tol = 1e-9; - ExponentialDistribution dist; + ExponentialDistributionImpl dist; dist = new ExponentialDistributionImpl(11d); assertEquals(dist.getNumericalMean(), 11d, tol); diff --git a/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java index 52427db99..2e4bd5740 100644 --- a/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java @@ -131,7 +131,7 @@ public class FDistributionTest extends ContinuousDistributionAbstractTest { public void testMomonts() { final double tol = 1e-9; - FDistribution dist; + FDistributionImpl dist; dist = new FDistributionImpl(1, 2); assertTrue(Double.isNaN(dist.getNumericalMean())); diff --git a/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java index 007985fa5..cc6e0b791 100644 --- a/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java @@ -155,7 +155,7 @@ public class GammaDistributionTest extends ContinuousDistributionAbstractTest { public void testMomonts() { final double tol = 1e-9; - GammaDistribution dist; + GammaDistributionImpl dist; dist = new GammaDistributionImpl(1, 2); assertEquals(dist.getNumericalMean(), 2, tol); diff --git a/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java index 94f5573e1..163304665 100644 --- a/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/HypergeometricDistributionTest.java @@ -214,7 +214,7 @@ public class HypergeometricDistributionTest extends IntegerDistributionAbstractT public void testMomonts() { final double tol = 1e-9; - HypergeometricDistribution dist; + HypergeometricDistributionImpl dist; dist = new HypergeometricDistributionImpl(1500, 40, 100); assertEquals(dist.getNumericalMean(), 40d * 100d / 1500d, tol); diff --git a/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java index a3752cf4a..6e0666b20 100644 --- a/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/NormalDistributionTest.java @@ -206,20 +206,17 @@ public class NormalDistributionTest extends ContinuousDistributionAbstractTest public void testMomonts() { final double tol = 1e-9; - NormalDistribution dist; + NormalDistributionImpl dist; dist = new NormalDistributionImpl(0, 1); - assertEquals(dist.getNumericalMean(), 0, tol); assertEquals(dist.getNumericalVariance(), 1, tol); dist.setMean(2.2); dist.setStandardDeviation(1.4); - assertEquals(dist.getNumericalMean(), 2.2, tol); assertEquals(dist.getNumericalVariance(), 1.4 * 1.4, tol); dist.setMean(-2000.9); dist.setStandardDeviation(10.4); - assertEquals(dist.getNumericalMean(), -2000.9, tol); assertEquals(dist.getNumericalVariance(), 10.4 * 10.4, tol); } } diff --git a/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java index f6f6a877b..cb2f5e8da 100644 --- a/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/PascalDistributionTest.java @@ -122,7 +122,7 @@ public class PascalDistributionTest extends IntegerDistributionAbstractTest { public void testMomonts() { final double tol = 1e-9; - PascalDistribution dist; + PascalDistributionImpl dist; dist = new PascalDistributionImpl(10, 0.5); assertEquals(dist.getNumericalMean(), ( 10d * 0.5d ) / 0.5d, tol); diff --git a/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java index f3475c2cf..afb477c7e 100644 --- a/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/PoissonDistributionTest.java @@ -220,14 +220,12 @@ public class PoissonDistributionTest extends IntegerDistributionAbstractTest { public void testMomonts() { final double tol = 1e-9; - PoissonDistribution dist; + PoissonDistributionImpl dist; dist = new PoissonDistributionImpl(1); - assertEquals(dist.getNumericalMean(), 1, tol); assertEquals(dist.getNumericalVariance(), 1, tol); dist.setMean(11.23); - assertEquals(dist.getNumericalMean(), 11.23, tol); assertEquals(dist.getNumericalVariance(), 11.23, tol); } } diff --git a/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java index ca6c8c98c..81a2d44aa 100644 --- a/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java @@ -118,7 +118,7 @@ public class TDistributionTest extends ContinuousDistributionAbstractTest { public void testMomonts() { final double tol = 1e-9; - TDistribution dist; + TDistributionImpl dist; dist = new TDistributionImpl(1); assertTrue(Double.isNaN(dist.getNumericalMean())); diff --git a/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java index 861428271..106248a9d 100644 --- a/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/WeibullDistributionTest.java @@ -125,7 +125,7 @@ public class WeibullDistributionTest extends ContinuousDistributionAbstractTest public void testMomonts() { final double tol = 1e-9; - WeibullDistribution dist; + WeibullDistributionImpl dist; dist = new WeibullDistributionImpl(2.5, 3.5); // In R: 3.5*gamma(1+(1/2.5)) (or emperically: mean(rweibull(10000, 2.5, 3.5))) diff --git a/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java b/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java index b4132cc74..5bbd3041c 100644 --- a/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java +++ b/src/test/java/org/apache/commons/math/distribution/ZipfDistributionTest.java @@ -80,7 +80,7 @@ public class ZipfDistributionTest extends IntegerDistributionAbstractTest { public void testMomonts() { final double tol = 1e-9; - ZipfDistribution dist; + ZipfDistributionImpl dist; dist = new ZipfDistributionImpl(2, 0.5); assertEquals(dist.getNumericalMean(), FastMath.sqrt(2), tol);