Author: celestin Date: Thu Nov 10 06:21:56 2011 New Revision: 1200179 URL: http://svn.apache.org/viewvc?rev=1200179&view=rev Log: Modifications to the hierarchy of distributions, according to MATH-692. Patch contributed by Christian Winter.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ContinuousDistributionAbstractTest.java commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java Thu Nov 10 06:21:56 2011 @@ -60,18 +60,21 @@ public abstract class AbstractContinuous /** * {@inheritDoc} + * + * For continuous distributions {@code P(X = x)} always evaluates to 0. + * + * @return 0 */ - public abstract double density(double x); + @Override + public final double probability(double x) { + return 0.0; + } /** - * For this distribution, {@code X}, this method returns the critical - * point {@code x}, such that {@code P(X < x) = p}. - * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws OutOfRangeException if {@code p} is not a valid probability. + * {@inheritDoc} */ - public double inverseCumulativeProbability(final double p) { + @Override + public double inverseCumulativeProbability(final double p) throws OutOfRangeException { if (p < 0.0 || p > 1.0) { throw new OutOfRangeException(p, 0, 1); @@ -81,6 +84,7 @@ public abstract class AbstractContinuous // subclasses can override if there is a better method. UnivariateRealFunction rootFindingFunction = new UnivariateRealFunction() { + @Override public double value(double x) { return cumulativeProbability(x) - p; } @@ -124,6 +128,7 @@ public abstract class AbstractContinuous * @param seed New seed. * @since 2.2 */ + @Override public void reseedRandomGenerator(long seed) { randomData.reSeed(seed); } @@ -138,6 +143,7 @@ public abstract class AbstractContinuous * @return a random value. * @since 2.2 */ + @Override public double sample() { return randomData.nextInversionDeviate(this); } @@ -151,6 +157,7 @@ public abstract class AbstractContinuous * @throws NotStrictlyPositiveException if {@code sampleSize} is not positive. * @since 2.2 */ + @Override public double[] sample(int sampleSize) { if (sampleSize <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractDistribution.java Thu Nov 10 06:21:56 2011 @@ -52,21 +52,13 @@ public abstract class AbstractDistributi } /** - * For a random variable X whose values are distributed according - * to this distribution, this method returns P(x0 ≤ X ≤ x1). - * <p> - * The default implementation uses the identity</p> - * <p> - * P(x0 ≤ X ≤ x1) = P(X ≤ x1) - P(X ≤ x0) </p> - * - * @param x0 the (inclusive) lower bound - * @param x1 the (inclusive) upper bound - * @return the probability that a random variable with this distribution - * will take a value between {@code x0} and {@code x1}, - * including the endpoints. - * @throws NumberIsTooLargeException if {@code x0 > x1} + * {@inheritDoc} + * + * The default implementation uses the identity + * <p>{@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}</p> */ - public double cumulativeProbability(double x0, double x1) { + @Override + public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); @@ -89,6 +81,7 @@ public abstract class AbstractDistributi * * @return the mean or Double.NaN if it's not defined */ + @Override public double getNumericalMean() { if (!numericalMeanIsCalculated) { numericalMean = calculateNumericalMean(); @@ -115,6 +108,7 @@ public abstract class AbstractDistributi * for certain cases in {@link TDistributionImpl}) or * Double.NaN if it's not defined */ + @Override public double getNumericalVariance() { if (!numericalVarianceIsCalculated) { numericalVariance = calculateNumericalVariance(); @@ -130,6 +124,7 @@ public abstract class AbstractDistributi * * @return whether the lower bound of the support is inclusive or not */ + @Override public abstract boolean isSupportLowerBoundInclusive(); /** @@ -138,6 +133,7 @@ public abstract class AbstractDistributi * * @return whether the upper bound of the support is inclusive or not */ + @Override public abstract boolean isSupportUpperBoundInclusive(); /** @@ -159,6 +155,7 @@ public abstract class AbstractDistributi * * @return whether the support limits given by subclassed methods are connected or not */ + @Override public boolean isSupportConnected() { return true; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/BetaDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -166,12 +166,6 @@ public class BetaDistributionImpl } } - /** {@inheritDoc} */ - @Override - public double cumulativeProbability(double x0, double x1) { - return cumulativeProbability(x1) - cumulativeProbability(x0); - } - /** * Return the absolute accuracy setting of the solver used to estimate * inverse cumulative probabilities. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/CauchyDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -87,11 +87,9 @@ public class CauchyDistributionImpl exte } /** - * For this distribution, {@code X}, this method returns {@code P(X < x)}. - * - * @param x Value at which the CDF is evaluated. - * @return CDF evaluated at {@code x}. + * {@inheritDoc} */ + @Override public double cumulativeProbability(double x) { return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI); } @@ -99,6 +97,7 @@ public class CauchyDistributionImpl exte /** * {@inheritDoc} */ + @Override public double getMedian() { return median; } @@ -106,6 +105,7 @@ public class CauchyDistributionImpl exte /** * {@inheritDoc} */ + @Override public double getScale() { return scale; } @@ -120,17 +120,13 @@ public class CauchyDistributionImpl exte } /** - * For this distribution, {@code X}, this method returns the critical - * point {@code x}, such that {@code P(X < x) = p}. - * It will return {@code Double.NEGATIVE_INFINITY} when p = 0 and - * {@code Double.POSITIVE_INFINITY} when p = 1. + * {@inheritDoc} * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws OutOfRangeException if {@code p} is not a valid probability. + * It will return {@code Double.NEGATIVE_INFINITY} when {@code p = 0} + * and {@code Double.POSITIVE_INFINITY} when {@code p = 1}. */ @Override - public double inverseCumulativeProbability(double p) { + public double inverseCumulativeProbability(double p) throws OutOfRangeException { double ret; if (p < 0 || p > 1) { throw new OutOfRangeException(p, 0, 1); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -67,6 +67,7 @@ public class ChiSquaredDistributionImpl /** * {@inheritDoc} */ + @Override public double getDegreesOfFreedom() { return gamma.getAlpha() * 2.0; } @@ -80,25 +81,18 @@ public class ChiSquaredDistributionImpl } /** - * For this distribution, {@code X}, this method returns {@code P(X < x)}. - * - * @param x the value at which the CDF is evaluated. - * @return CDF for this distribution. + * {@inheritDoc} */ + @Override public double cumulativeProbability(double x) { return gamma.cumulativeProbability(x); } /** - * For this distribution, X, this method returns the critical point - * {@code x}, such that {@code P(X < x) = p}. - * It will return 0 when p = 0 and {@code Double.POSITIVE_INFINITY} - * when p = 1. - * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws org.apache.commons.math.exception.OutOfRangeException if - * {@code p} is not a valid probability. + * {@inheritDoc} + * + * It will return {@code 0} when {@code p = 0} and + * {@code Double.POSITIVE_INFINITY} when {@code p = 1}. */ @Override public double inverseCumulativeProbability(final double p) { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ContinuousDistribution.java Thu Nov 10 06:21:56 2011 @@ -16,6 +16,8 @@ */ package org.apache.commons.math.distribution; +import org.apache.commons.math.exception.OutOfRangeException; + /** * Base interface for continuous distributions. * @@ -23,19 +25,27 @@ package org.apache.commons.math.distribu */ public interface ContinuousDistribution extends Distribution { /** - * For a distribution, {@code X}, compute {@code x} such that - * {@code P(X < x) = p}. + * Computes the quantile function of this distribution. For a random + * variable {@code X} distributed according to this distribution, the + * returned value is + * <ul> + * <li><code>inf{x in R | P(X<=x) >= p}</code> for {@code 0 < p <= 1},</li> + * <li><code>inf{x in R | P(X<=x) > 0}</code> for {@code p = 0}.</li> + * </ul> * - * @param p Cumulative probability. - * @return {@code x} such that {@code P(X < x) = p}. + * @param p the cumulative probability + * @return the smallest {@code p}-quantile of this distribution + * (largest 0-quantile for {@code p = 0}) + * @throws OutOfRangeException if {@code p < 0} or {@code p > 1} */ - double inverseCumulativeProbability(double p); + double inverseCumulativeProbability(double p) throws OutOfRangeException; /** - * Probability density for a particular point. + * Returns the probability density function (PDF) of this distribution + * evaluated at the specified point. * - * @param x Point at which the density should be computed. - * @return the pdf at point {@code x}. + * @param x the point at which the PDF should be evaluated + * @return the PDF at point {@code x} */ double density(double x); Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/Distribution.java Thu Nov 10 06:21:56 2011 @@ -16,6 +16,8 @@ */ package org.apache.commons.math.distribution; +import org.apache.commons.math.exception.NumberIsTooLargeException; + /** * Base interface for probability distributions. * @@ -23,29 +25,40 @@ package org.apache.commons.math.distribu */ public interface Distribution { /** - * For a random variable X whose values are distributed according - * to this distribution, this method returns P(X ≤ x). In other words, - * this method represents the (cumulative) distribution function, or - * CDF, for this distribution. + * For a random variable {@code X} whose values are distributed according + * to this distribution, this method returns {@code P(X = x)}. In other + * words, this method represents the probability mass function (PMF) + * for the distribution. + * + * @param x the value at which the PMF is evaluated + * @return the value of the probability mass function at {@code x} + */ + double probability(double x); + + /** + * For a random variable {@code X} whose values are distributed according + * to this distribution, this method returns {@code P(X <= x)}. In other + * words, this method represents the (cumulative) distribution function + * (CDF) for this distribution. * - * @param x the value at which the distribution function is evaluated. + * @param x the value at which the CDF is evaluated * @return the probability that a random variable with this - * distribution takes a value less than or equal to <code>x</code> + * distribution takes a value less than or equal to {@code x} */ double cumulativeProbability(double x); /** - * For a random variable X whose values are distributed according - * to this distribution, this method returns P(x0 ≤ X ≤ x1). + * For a random variable {@code X} whose values are distributed according + * to this distribution, this method returns {@code P(x0 < X <= x1)}. * - * @param x0 the (inclusive) lower bound - * @param x1 the (inclusive) upper bound + * @param x0 the exclusive lower bound + * @param x1 the inclusive upper bound * @return the probability that a random variable with this distribution - * will take a value between <code>x0</code> and <code>x1</code>, - * including the endpoints - * @throws IllegalArgumentException if <code>x0 > x1</code> + * takes a value between {@code x0} and {@code x1}, + * excluding the lower and including the upper endpoint + * @throws NumberIsTooLargeException if {@code x0 > x1} */ - double cumulativeProbability(double x0, double x1); + double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException; /** * Use this method to get the numerical value of the mean of this Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -71,6 +71,7 @@ public class ExponentialDistributionImpl /** * {@inheritDoc} */ + @Override public double getMean() { return mean; } @@ -87,7 +88,7 @@ public class ExponentialDistributionImpl } /** - * For this distribution, X, this method returns P(X < x). + * {@inheritDoc} * * The implementation of this method is based on: * <ul> @@ -95,10 +96,8 @@ public class ExponentialDistributionImpl * <a href="http://mathworld.wolfram.com/ExponentialDistribution.html"> * Exponential Distribution</a>, equation (1).</li> * </ul> - * - * @param x Value at which the CDF is evaluated. - * @return the CDF for this distribution. */ + @Override public double cumulativeProbability(double x) { double ret; if (x <= 0.0) { @@ -110,17 +109,13 @@ public class ExponentialDistributionImpl } /** - * For this distribution, X, this method returns the critical point x, such - * that {@code P(X < x) = p}. - * It will return 0 when p = 0 and {@code Double.POSITIVE_INFINITY} - * when p = 1. + * {@inheritDoc} * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws OutOfRangeException if {@code p < 0} or {@code p > 1}. + * It will return {@code 0} when {@code p = 0} and + * {@code Double.POSITIVE_INFINITY} when {@code p = 1}. */ @Override - public double inverseCumulativeProbability(double p) { + public double inverseCumulativeProbability(double p) throws OutOfRangeException { double ret; if (p < 0.0 || p > 1.0) { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -20,6 +20,7 @@ package org.apache.commons.math.distribu import java.io.Serializable; import org.apache.commons.math.exception.NotStrictlyPositiveException; +import org.apache.commons.math.exception.OutOfRangeException; import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.special.Beta; import org.apache.commons.math.util.FastMath; @@ -89,10 +90,8 @@ public class FDistributionImpl } /** - * Returns the probability density for a particular point. + * {@inheritDoc} * - * @param x The point at which the density should be computed. - * @return The pdf at point x. * @since 2.1 */ @Override @@ -110,7 +109,7 @@ public class FDistributionImpl } /** - * For this distribution, {@code X}, this method returns {@code P(X < x)}. + * {@inheritDoc} * * The implementation of this method is based on * <ul> @@ -119,10 +118,8 @@ public class FDistributionImpl * F-Distribution</a>, equation (4). * </li> * </ul> - * - * @param x Value at which the CDF is evaluated. - * @return CDF for this distribution. */ + @Override public double cumulativeProbability(double x) { double ret; if (x <= 0) { @@ -139,17 +136,13 @@ public class FDistributionImpl } /** - * For this distribution, {@code X}, this method returns the critical - * point {@code x}, such that {@code P(X < x) = p}. - * Returns 0 when p = 0 and {@code Double.POSITIVE_INFINITY} when p = 1. + * {@inheritDoc} * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws IllegalArgumentException if {@code p} is not a valid - * probability. + * It will return {@code 0} when {@code p = 0} and + * {@code Double.POSITIVE_INFINITY} when {@code p = 1}. */ @Override - public double inverseCumulativeProbability(final double p) { + public double inverseCumulativeProbability(final double p) throws OutOfRangeException { if (p == 0) { return 0; } @@ -207,6 +200,7 @@ public class FDistributionImpl /** * {@inheritDoc} */ + @Override public double getNumeratorDegreesOfFreedom() { return numeratorDegreesOfFreedom; } @@ -214,6 +208,7 @@ public class FDistributionImpl /** * {@inheritDoc} */ + @Override public double getDenominatorDegreesOfFreedom() { return denominatorDegreesOfFreedom; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -79,7 +79,7 @@ public class GammaDistributionImpl exten } /** - * For this distribution, {@code X}, this method returns {@code P(X < x)}. + * {@inheritDoc} * * The implementation of this method is based on: * <ul> @@ -91,10 +91,8 @@ public class GammaDistributionImpl exten * Belmont, CA: Duxbury Press. * </li> * </ul> - * - * @param x Value at which the CDF is evaluated. - * @return CDF for this distribution. */ + @Override public double cumulativeProbability(double x) { double ret; @@ -108,15 +106,10 @@ public class GammaDistributionImpl exten } /** - * For this distribution, {@code X}, this method returns the critical - * point {@code x}, such that {@code P(X < x) = p}. - * It will return 0 when p = 0 and {@code Double.POSITIVE_INFINITY} - * when p = 1. - * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws org.apache.commons.math.exception.OutOfRangeException if - * {@code p} is not a valid probability. + * {@inheritDoc} + * + * It will return {@code 0} when {@cod p = 0} and + * {@code Double.POSITIVE_INFINITY} when {@code p = 1}. */ @Override public double inverseCumulativeProbability(final double p) { @@ -132,6 +125,7 @@ public class GammaDistributionImpl exten /** * {@inheritDoc} */ + @Override public double getAlpha() { return alpha; } @@ -139,6 +133,7 @@ public class GammaDistributionImpl exten /** * {@inheritDoc} */ + @Override public double getBeta() { return beta; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/NormalDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -92,6 +92,7 @@ public class NormalDistributionImpl exte /** * {@inheritDoc} */ + @Override public double getMean() { return mean; } @@ -99,6 +100,7 @@ public class NormalDistributionImpl exte /** * {@inheritDoc} */ + @Override public double getStandardDeviation() { return standardDeviation; } @@ -114,13 +116,12 @@ public class NormalDistributionImpl exte } /** - * For this distribution, {@code X}, this method returns {@code P(X < x)}. - * If {@code x}is more than 40 standard deviations from the mean, 0 or 1 is returned, - * as in these cases the actual value is within {@code Double.MIN_VALUE} of 0 or 1. + * {@inheritDoc} * - * @param x Value at which the CDF is evaluated. - * @return CDF evaluated at {@code x}. + * If {@code x} is more than 40 standard deviations from the mean, 0 or 1 is returned, + * as in these cases the actual value is within {@code Double.MIN_VALUE} of 0 or 1. */ + @Override public double cumulativeProbability(double x) { final double dev = x - mean; if (FastMath.abs(dev) > 40 * standardDeviation) { @@ -133,7 +134,7 @@ public class NormalDistributionImpl exte * {@inheritDoc} */ @Override - public double cumulativeProbability(double x0, double x1) { + public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException { if (x0 > x1) { throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, x0, x1, true); @@ -157,19 +158,13 @@ public class NormalDistributionImpl exte } /** - * For this distribution, X, this method returns the critical point - * {@code x}, such that {@code P(X < x) = p}. - * It will return {@code Double.NEGATIVE_INFINITY} when p = 0 and - * {@code Double.POSITIVE_INFINITY} for p = 1. - * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws org.apache.commons.math.exception.OutOfRangeException if - * {@code p} is not a valid probability. + * {@inheritDoc} + * + * It will return {@code Double.NEGATIVE_INFINITY} when {@code p = 0} + * and {@code Double.POSITIVE_INFINITY} for {@code p = 1}. */ @Override - public double inverseCumulativeProbability(final double p) - { + public double inverseCumulativeProbability(final double p) { if (p == 0) { return Double.NEGATIVE_INFINITY; } Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/TDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -79,6 +79,7 @@ public class TDistributionImpl * * @return the degrees of freedom. */ + @Override public double getDegreesOfFreedom() { return degreesOfFreedom; } @@ -96,11 +97,9 @@ public class TDistributionImpl } /** - * For this distribution, X, this method returns {@code P(X < x}). - * - * @param x Value at which the CDF is evaluated. - * @return CDF evaluated at {@code x}. + * {@inheritDoc} */ + @Override public double cumulativeProbability(double x) { double ret; if (x == 0) { @@ -122,15 +121,10 @@ public class TDistributionImpl } /** - * For this distribution, {@code X}, this method returns the critical - * point {@code x}, such that {@code P(X < x) = p}. - * Returns {@code Double.NEGATIVE_INFINITY} when p = 0 and - * {@code Double.POSITIVE_INFINITY} when p = 1. - * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws org.apache.commons.math.exception.OutOfRangeException if - * {@code p} is not a valid probability. + * {@inheritDoc} + * + * It will return {@code Double.NEGATIVE_INFINITY} when {@cod p = 0} + * and {@code Double.POSITIVE_INFINITY} when {@code p = 1}. */ @Override public double inverseCumulativeProbability(final double p) { Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/WeibullDistributionImpl.java Thu Nov 10 06:21:56 2011 @@ -88,11 +88,9 @@ public class WeibullDistributionImpl ext } /** - * For this distribution, {@code X}, this method returns {@code P(X < x)}. - * - * @param x Value at which the CDF is evaluated. - * @return the CDF evaluated at {@code x}. + * {@inheritDoc} */ + @Override public double cumulativeProbability(double x) { double ret; if (x <= 0.0) { @@ -106,6 +104,7 @@ public class WeibullDistributionImpl ext /** * {@inheritDoc} */ + @Override public double getShape() { return shape; } @@ -113,6 +112,7 @@ public class WeibullDistributionImpl ext /** * {@inheritDoc} */ + @Override public double getScale() { return scale; } @@ -140,14 +140,10 @@ public class WeibullDistributionImpl ext } /** - * For this distribution, {@code X}, this method returns the critical - * point {@code x}, such that {@code P(X < x) = p}. - * It will return {@code Double.NEGATIVE_INFINITY} when p = 0 and - * {@code Double.POSITIVE_INFINITY} when p = 1. - * - * @param p Desired probability. - * @return {@code x}, such that {@code P(X < x) = p}. - * @throws OutOfRangeException if {@code p} is not a valid probability. + * {@inheritDoc} + * + * It will return {@code 0} when {@code p = 0} and + * {@code Double.POSITIVE_INFINITY} when {@code p = 1}. */ @Override public double inverseCumulativeProbability(double p) { Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ContinuousDistributionAbstractTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ContinuousDistributionAbstractTest.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ContinuousDistributionAbstractTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ContinuousDistributionAbstractTest.java Thu Nov 10 06:21:56 2011 @@ -238,7 +238,7 @@ public abstract class ContinuousDistribu distribution.cumulativeProbability (cumulativeTestPoints[i], cumulativeTestPoints[i]), tolerance); - // check that P(a < X < b) = P(X < b) - P(X < a) + // check that P(a < X <= b) = P(X <= b) - P(X <= a) double upper = FastMath.max(cumulativeTestPoints[i], cumulativeTestPoints[i -1]); double lower = FastMath.min(cumulativeTestPoints[i], cumulativeTestPoints[i -1]); double diff = distribution.cumulativeProbability(upper) - Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java?rev=1200179&r1=1200178&r2=1200179&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java (original) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/TDistributionTest.java Thu Nov 10 06:21:56 2011 @@ -72,7 +72,7 @@ public class TDistributionTest extends C * Bug report that prompted this unit test.</a> */ @Test - public void testCumulativeProbabilityAgaintStackOverflow() throws Exception { + public void testCumulativeProbabilityAgainstStackOverflow() throws Exception { TDistributionImpl td = new TDistributionImpl(5.); td.cumulativeProbability(.1); td.cumulativeProbability(.01);