Algorithm Description: Uses the Inversion - * Method to generate exponentially distributed random values from - * uniform deviates.

+ *

Algorithm Description: this implementation uses the + * + * Inversion Method to generate exponentially distributed random values + * from uniform deviates.

* * @return a random value. * @since 2.2 @@ -142,25 +145,13 @@ public class ExponentialDistributionImpl return randomData.nextExponential(mean); } - /** - * Access the domain value lower bound, based on {@code p}, used to - * bracket a CDF root. - * - * @param p Desired probability for the critical value. - * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}. - */ + /** {@inheritDoc} */ @Override protected double getDomainLowerBound(double p) { return 0; } - /** - * Access the domain value upper bound, based on {@code p}, used to - * bracket a CDF root. - * - * @param p Desired probability for the critical value. - * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}. - */ + /** {@inheritDoc} */ @Override protected double getDomainUpperBound(double p) { // NOTE: exponential is skewed to the left @@ -175,17 +166,12 @@ public class ExponentialDistributionImpl } } - /** - * Access the initial domain value, based on {@code p}, used to - * bracket a CDF root. - * - * @param p Desired probability for the critical value. - * @return the initial domain value. - */ + /** {@inheritDoc} */ @Override protected double getInitialDomain(double p) { // TODO: try to improve on this estimate - // TODO: what should really happen here is not derive from AbstractContinuousDistribution + // TODO: what should really happen here is not derive from + // AbstractContinuousDistribution // TODO: because the inverse cumulative distribution is simple. // Exponential is skewed to the left, therefore, P(X < μ) > .5 if (p < 0.5) { @@ -197,13 +183,7 @@ public class ExponentialDistributionImpl } } - /** - * Return the absolute accuracy setting of the solver used to estimate - * inverse cumulative probabilities. - * - * @return the solver absolute accuracy. - * @since 2.1 - */ + /** {@inheritDoc} */ @Override protected double getSolverAbsoluteAccuracy() { return solverAbsoluteAccuracy; @@ -237,10 +217,7 @@ public class ExponentialDistributionImpl /** * {@inheritDoc} * - * For mean parameter `k`, the mean is - * `k` - * - * @return {@inheritDoc} + * For mean parameter {@code k}, the mean is {@code k}. */ @Override protected double calculateNumericalMean() { @@ -250,10 +227,7 @@ public class ExponentialDistributionImpl /** * {@inheritDoc} * - * For mean parameter `k`, the variance is - * `k^2` - * - * @return {@inheritDoc} + * For mean parameter {@code k}, the variance is {@code k^2}. */ @Override protected double calculateNumericalVariance() { @@ -261,17 +235,13 @@ public class ExponentialDistributionImpl return m * m; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean isSupportLowerBoundInclusive() { return true; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean isSupportUpperBoundInclusive() { return false; Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistribution.java (from r1206052, 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/FDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/FDistributionImpl.java&r1=1206052&r2=1206399&rev=1206399&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/FDistribution.java Sat Nov 26 06:17:49 2011 @@ -26,14 +26,15 @@ import org.apache.commons.math.special.B import org.apache.commons.math.util.FastMath; /** - * Default implementation of - * {@link org.apache.commons.math.distribution.FDistribution}. + * Implementation of the F-distribution. * + * @see F-distribution (Wikipedia) + * @see F-distribution (MathWorld) * @version \$Id\$ */ -public class FDistributionImpl +public class FDistribution extends AbstractContinuousDistribution - implements FDistribution, Serializable { + implements Serializable { /** * Default inverse cumulative probability accuracy. * @since 2.1 @@ -52,11 +53,13 @@ public class FDistributionImpl * Create a F distribution using the given degrees of freedom. * @param numeratorDegreesOfFreedom Numerator degrees of freedom. * @param denominatorDegreesOfFreedom Denominator degrees of freedom. - * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} - * or {@code denominatorDegreesOfFreedom <= 0}. - */ - public FDistributionImpl(double numeratorDegreesOfFreedom, - double denominatorDegreesOfFreedom) { + * @throws NotStrictlyPositiveException if + * {@code numeratorDegreesOfFreedom <= 0} or + * {@code denominatorDegreesOfFreedom <= 0}. + */ + public FDistribution(double numeratorDegreesOfFreedom, + double denominatorDegreesOfFreedom) + throws NotStrictlyPositiveException { this(numeratorDegreesOfFreedom, denominatorDegreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); } @@ -69,13 +72,15 @@ public class FDistributionImpl * @param inverseCumAccuracy the maximum absolute error in inverse * cumulative probability estimates. * (defaults to {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}) - * @throws NotStrictlyPositiveException if {@code numeratorDegreesOfFreedom <= 0} - * or {@code denominatorDegreesOfFreedom <= 0}. + * @throws NotStrictlyPositiveException if + * {@code numeratorDegreesOfFreedom <= 0} or + * {@code denominatorDegreesOfFreedom <= 0}. * @since 2.1 */ - public FDistributionImpl(double numeratorDegreesOfFreedom, + public FDistribution(double numeratorDegreesOfFreedom, double denominatorDegreesOfFreedom, - double inverseCumAccuracy) { + double inverseCumAccuracy) + throws NotStrictlyPositiveException { if (numeratorDegreesOfFreedom <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.DEGREES_OF_FREEDOM, numeratorDegreesOfFreedom); @@ -136,8 +141,8 @@ public class FDistributionImpl /** * {@inheritDoc} * - * It will return {@code 0} when {@code p = 0} and - * {@code Double.POSITIVE_INFINITY} when {@code p = 1}. + * Returns {@code 0} when {@code p == 0} and + * {@code Double.POSITIVE_INFINITY} when {@code p == 1}. */ @Override public double inverseCumulativeProbability(final double p) throws OutOfRangeException { @@ -150,40 +155,19 @@ public class FDistributionImpl return super.inverseCumulativeProbability(p); } - /** - * Access the domain value lower bound, based on {@code p}, used to - * bracket a CDF root. This method is used by - * {@link #inverseCumulativeProbability(double)} to find critical values. - * - * @param p Desired probability for the critical value. - * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}. - */ + /** {@inheritDoc} */ @Override protected double getDomainLowerBound(double p) { return 0; } - /** - * Access the domain value upper bound, based on {@code p}, used to - * bracket a CDF root. This method is used by - * {@link #inverseCumulativeProbability(double)} to find critical values. - * - * @param p Desired probability for the critical value. - * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}. - */ + /** {@inheritDoc} */ @Override protected double getDomainUpperBound(double p) { return Double.MAX_VALUE; } - /** - * Access the initial domain value, based on {@code p}, used to - * bracket a CDF root. This method is used by - * {@link #inverseCumulativeProbability(double)} to find critical values. - * - * @param p Desired probability for the critical value. - * @return the initial domain value. - */ + /** {@inheritDoc} */ @Override protected double getInitialDomain(double p) { double ret = 1; @@ -196,26 +180,24 @@ public class FDistributionImpl } /** - * {@inheritDoc} + * Access the numerator degrees of freedom. + * + * @return the numerator degrees of freedom. */ public double getNumeratorDegreesOfFreedom() { return numeratorDegreesOfFreedom; } /** - * {@inheritDoc} + * Access the denominator degrees of freedom. + * + * @return the denominator degrees of freedom. */ public double getDenominatorDegreesOfFreedom() { return denominatorDegreesOfFreedom; } - /** - * Return the absolute accuracy setting of the solver used to estimate - * inverse cumulative probabilities. - * - * @return the solver absolute accuracy - * @since 2.1 - */ + /** {@inheritDoc} */ @Override protected double getSolverAbsoluteAccuracy() { return solverAbsoluteAccuracy; @@ -249,14 +231,11 @@ public class FDistributionImpl /** * {@inheritDoc} * - * For denominator degrees of freedom parameter `b`, - * the mean is + * For denominator degrees of freedom parameter {@code b}, the mean is *
- *
• if `b > 2` then `b / (b - 2)`
• - *
• else `undefined` + *
• if {@code b > 2} then {@code b / (b - 2)},
• + *
• else undefined ({@code Double.NaN}). *
- * - * @return {@inheritDoc} */ @Override protected double calculateNumericalMean() { @@ -272,18 +251,15 @@ public class FDistributionImpl /** * {@inheritDoc} * - * For numerator degrees of freedom parameter `a` - * and denominator degrees of freedom parameter `b`, - * the variance is + * For numerator degrees of freedom parameter {@code a} and denominator + * degrees of freedom parameter {@code b}, the variance is *
*
• - * if `b > 4` then - * `[ 2 * b^2 * (a + b - 2) ] / [ a * (b - 2)^2 * (b - 4) ]` + * if {@code b > 4} then + * {@code [2 * b^2 * (a + b - 2)] / [a * (b - 2)^2 * (b - 4)]}, *
• - *
• else `undefined` + *
• else undefined ({@code Double.NaN}). *
- * - * @return {@inheritDoc} */ @Override protected double calculateNumericalVariance() { @@ -300,17 +276,13 @@ public class FDistributionImpl return Double.NaN; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean isSupportLowerBoundInclusive() { return true; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean isSupportUpperBoundInclusive() { return false; Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistribution.java (from r1206052, 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/GammaDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java&r1=1206052&r2=1206399&rev=1206399&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/GammaDistribution.java Sat Nov 26 06:17:49 2011 @@ -24,12 +24,14 @@ import org.apache.commons.math.special.G import org.apache.commons.math.util.FastMath; /** - * The default implementation of {@link GammaDistribution}. + * Implementation of the Gamma distribution. * + * @see Gamma distribution (Wikipedia) + * @see Gamma distribution (MathWorld) * @version \$Id\$ */ -public class GammaDistributionImpl extends AbstractContinuousDistribution - implements GammaDistribution, Serializable { +public class GammaDistribution extends AbstractContinuousDistribution + implements Serializable { /** * Default inverse cumulative probability accuracy. * @since 2.1 @@ -45,16 +47,18 @@ public class GammaDistributionImpl exten private final double solverAbsoluteAccuracy; /** - * Create a new gamma distribution with the given alpha and beta values. + * Create a new gamma distribution with the given {@code alpha} and + * {@code beta} values. * @param alpha the shape parameter. * @param beta the scale parameter. */ - public GammaDistributionImpl(double alpha, double beta) { + public GammaDistribution(double alpha, double beta) { this(alpha, beta, DEFAULT_INVERSE_ABSOLUTE_ACCURACY); } /** - * Create a new gamma distribution with the given alpha and beta values. + * Create a new gamma distribution with the given {@code alpha} and + * {@code beta} values. * * @param alpha Shape parameter. * @param beta Scale parameter. @@ -65,7 +69,8 @@ public class GammaDistributionImpl exten * {@code beta <= 0}. * @since 2.1 */ - public GammaDistributionImpl(double alpha, double beta, double inverseCumAccuracy) { + public GammaDistribution(double alpha, double beta, double inverseCumAccuracy) + throws NotStrictlyPositiveException { if (alpha <= 0) { throw new NotStrictlyPositiveException(LocalizedFormats.ALPHA, alpha); } @@ -107,8 +112,8 @@ public class GammaDistributionImpl exten /** * {@inheritDoc} * - * It will return {@code 0} when {@cod p = 0} and - * {@code Double.POSITIVE_INFINITY} when {@code p = 1}. + * Returns {@code 0} when {@code p == 0} and + * {@code Double.POSITIVE_INFINITY} when {@code p == 1}. */ @Override public double inverseCumulativeProbability(final double p) { @@ -122,22 +127,24 @@ public class GammaDistributionImpl exten } /** - * {@inheritDoc} + * Access the {@code alpha} shape parameter. + * + * @return {@code alpha}. */ public double getAlpha() { return alpha; } /** - * {@inheritDoc} + * Access the {@code beta} scale parameter. + * + * @return {@code beta}. */ public double getBeta() { return beta; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public double density(double x) { if (x < 0) { return 0; @@ -146,28 +153,14 @@ public class GammaDistributionImpl exten FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha)); } - /** - * Access the domain value lower bound, based on {@code p}, used to - * bracket a CDF root. This method is used by - * {@link #inverseCumulativeProbability(double)} to find critical values. - * - * @param p Desired probability for the critical value. - * @return the domain value lower bound, i.e. {@code P(X < 'lower bound') < p}. - */ + /** {@inheritDoc} */ @Override protected double getDomainLowerBound(double p) { // TODO: try to improve on this estimate return Double.MIN_VALUE; } - /** - * Access the domain value upper bound, based on {@code p}, used to - * bracket a CDF root. This method is used by - * {@link #inverseCumulativeProbability(double)} to find critical values. - * - * @param p Desired probability for the critical value. - * @return the domain value upper bound, i.e. {@code P(X < 'upper bound') > p}. - */ + /** {@inheritDoc} */ @Override protected double getDomainUpperBound(double p) { // TODO: try to improve on this estimate @@ -187,14 +180,7 @@ public class GammaDistributionImpl exten return ret; } - /** - * Access the initial domain value, based on {@code p}, used to - * bracket a CDF root. This method is used by - * {@link #inverseCumulativeProbability(double)} to find critical values. - * - * @param p Desired probability for the critical value. - * @return the initial domain value. - */ + /** {@inheritDoc} */ @Override protected double getInitialDomain(double p) { // TODO: try to improve on this estimate @@ -213,13 +199,7 @@ public class GammaDistributionImpl exten return ret; } - /** - * Return the absolute accuracy setting of the solver used to estimate - * inverse cumulative probabilities. - * - * @return the solver absolute accuracy. - * @since 2.1 - */ + /** {@inheritDoc} */ @Override protected double getSolverAbsoluteAccuracy() { return solverAbsoluteAccuracy; @@ -253,11 +233,8 @@ public class GammaDistributionImpl exten /** * {@inheritDoc} * - * For shape parameter `alpha` and scale - * parameter `beta`, the mean is - * `alpha * beta` - * - * @return {@inheritDoc} + * For shape parameter {@code alpha} and scale parameter {@code beta}, the + * mean is {@code alpha * beta}. */ @Override protected double calculateNumericalMean() { @@ -267,9 +244,8 @@ public class GammaDistributionImpl exten /** * {@inheritDoc} * - * For shape parameter `alpha` and scale - * parameter `beta`, the variance is - * `alpha * beta^2` + * For shape parameter {@code alpha} and scale parameter {@code beta}, the + * variance is {@code alpha * beta^2}. * * @return {@inheritDoc} */ @@ -279,17 +255,13 @@ public class GammaDistributionImpl exten return getAlpha() * b * b; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean isSupportLowerBoundInclusive() { return true; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ @Override public boolean isSupportUpperBoundInclusive() { return false; Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java?rev=1206399&r1=1206398&r2=1206399&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java Sat Nov 26 06:17:49 2011 @@ -29,7 +29,7 @@ import org.apache.commons.math.distribut import org.apache.commons.math.distribution.CauchyDistribution; import org.apache.commons.math.distribution.ChiSquaredDistribution; import org.apache.commons.math.distribution.ContinuousDistribution; -import org.apache.commons.math.distribution.FDistributionImpl; +import org.apache.commons.math.distribution.FDistribution; import org.apache.commons.math.distribution.HypergeometricDistributionImpl; import org.apache.commons.math.distribution.IntegerDistribution; import org.apache.commons.math.distribution.PascalDistributionImpl; @@ -654,7 +654,7 @@ public class RandomDataImpl implements R } /** - * Generates a random value from the {@link FDistributionImpl F Distribution}. + * Generates a random value from the {@link FDistribution F Distribution}. * This implementation uses {@link #nextInversionDeviate(ContinuousDistribution) inversion} * to generate random values. * @@ -664,12 +664,12 @@ public class RandomDataImpl implements R * @since 2.2 */ public double nextF(double numeratorDf, double denominatorDf) { - return nextInversionDeviate(new FDistributionImpl(numeratorDf, denominatorDf)); + return nextInversionDeviate(new FDistribution(numeratorDf, denominatorDf)); } /** *

Generates a random value from the - * {@link org.apache.commons.math.distribution.GammaDistributionImpl Gamma Distribution}.