Modifications to the hierarchy of distributions, according to MATH-692. Patch contributed by Christian Winter.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1200179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2011-11-10 06:21:56 +00:00
parent 70667484eb
commit 87f0f14381
15 changed files with 134 additions and 153 deletions

View File

@ -60,18 +60,21 @@ public abstract class AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@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 * {@inheritDoc}
* 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.
*/ */
public double inverseCumulativeProbability(final double p) { @Override
public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
if (p < 0.0 || p > 1.0) { if (p < 0.0 || p > 1.0) {
throw new OutOfRangeException(p, 0, 1); throw new OutOfRangeException(p, 0, 1);
@ -81,6 +84,7 @@ public abstract class AbstractContinuousDistribution
// subclasses can override if there is a better method. // subclasses can override if there is a better method.
UnivariateRealFunction rootFindingFunction = UnivariateRealFunction rootFindingFunction =
new UnivariateRealFunction() { new UnivariateRealFunction() {
@Override
public double value(double x) { public double value(double x) {
return cumulativeProbability(x) - p; return cumulativeProbability(x) - p;
} }
@ -124,6 +128,7 @@ public abstract class AbstractContinuousDistribution
* @param seed New seed. * @param seed New seed.
* @since 2.2 * @since 2.2
*/ */
@Override
public void reseedRandomGenerator(long seed) { public void reseedRandomGenerator(long seed) {
randomData.reSeed(seed); randomData.reSeed(seed);
} }
@ -138,6 +143,7 @@ public abstract class AbstractContinuousDistribution
* @return a random value. * @return a random value.
* @since 2.2 * @since 2.2
*/ */
@Override
public double sample() { public double sample() {
return randomData.nextInversionDeviate(this); return randomData.nextInversionDeviate(this);
} }
@ -151,6 +157,7 @@ public abstract class AbstractContinuousDistribution
* @throws NotStrictlyPositiveException if {@code sampleSize} is not positive. * @throws NotStrictlyPositiveException if {@code sampleSize} is not positive.
* @since 2.2 * @since 2.2
*/ */
@Override
public double[] sample(int sampleSize) { public double[] sample(int sampleSize) {
if (sampleSize <= 0) { if (sampleSize <= 0) {
throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES, throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_SAMPLES,

View File

@ -52,21 +52,13 @@ public abstract class AbstractDistribution
} }
/** /**
* For a random variable X whose values are distributed according * {@inheritDoc}
* to this distribution, this method returns P(x0 &le; X &le; x1).
* <p>
* The default implementation uses the identity</p>
* <p>
* P(x0 &le; X &le; x1) = P(X &le; x1) - P(X &le; x0) </p>
* *
* @param x0 the (inclusive) lower bound * The default implementation uses the identity
* @param x1 the (inclusive) upper bound * <p>{@code P(x0 < X <= x1) = P(X <= x1) - P(X <= x0)}</p>
* @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}
*/ */
public double cumulativeProbability(double x0, double x1) { @Override
public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException {
if (x0 > x1) { if (x0 > x1) {
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
x0, x1, true); x0, x1, true);
@ -89,6 +81,7 @@ public abstract class AbstractDistribution
* *
* @return the mean or Double.NaN if it's not defined * @return the mean or Double.NaN if it's not defined
*/ */
@Override
public double getNumericalMean() { public double getNumericalMean() {
if (!numericalMeanIsCalculated) { if (!numericalMeanIsCalculated) {
numericalMean = calculateNumericalMean(); numericalMean = calculateNumericalMean();
@ -115,6 +108,7 @@ public abstract class AbstractDistribution
* for certain cases in {@link TDistributionImpl}) or * for certain cases in {@link TDistributionImpl}) or
* Double.NaN if it's not defined * Double.NaN if it's not defined
*/ */
@Override
public double getNumericalVariance() { public double getNumericalVariance() {
if (!numericalVarianceIsCalculated) { if (!numericalVarianceIsCalculated) {
numericalVariance = calculateNumericalVariance(); numericalVariance = calculateNumericalVariance();
@ -130,6 +124,7 @@ public abstract class AbstractDistribution
* *
* @return whether the lower bound of the support is inclusive or not * @return whether the lower bound of the support is inclusive or not
*/ */
@Override
public abstract boolean isSupportLowerBoundInclusive(); public abstract boolean isSupportLowerBoundInclusive();
/** /**
@ -138,6 +133,7 @@ public abstract class AbstractDistribution
* *
* @return whether the upper bound of the support is inclusive or not * @return whether the upper bound of the support is inclusive or not
*/ */
@Override
public abstract boolean isSupportUpperBoundInclusive(); public abstract boolean isSupportUpperBoundInclusive();
/** /**
@ -159,6 +155,7 @@ public abstract class AbstractDistribution
* *
* @return whether the support limits given by subclassed methods are connected or not * @return whether the support limits given by subclassed methods are connected or not
*/ */
@Override
public boolean isSupportConnected() { public boolean isSupportConnected() {
return true; return true;
} }

View File

@ -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 * Return the absolute accuracy setting of the solver used to estimate
* inverse cumulative probabilities. * inverse cumulative probabilities.

View File

@ -87,11 +87,9 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, {@code X}, this method returns {@code P(X < x)}. * {@inheritDoc}
*
* @param x Value at which the CDF is evaluated.
* @return CDF evaluated at {@code x}.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI); return 0.5 + (FastMath.atan((x - median) / scale) / FastMath.PI);
} }
@ -99,6 +97,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getMedian() { public double getMedian() {
return median; return median;
} }
@ -106,6 +105,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getScale() { public double getScale() {
return scale; return scale;
} }
@ -120,17 +120,13 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, {@code X}, this method returns the critical * {@inheritDoc}
* 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. * It will return {@code Double.NEGATIVE_INFINITY} when {@code p = 0}
* @return {@code x}, such that {@code P(X < x) = p}. * and {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
* @throws OutOfRangeException if {@code p} is not a valid probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(double p) { public double inverseCumulativeProbability(double p) throws OutOfRangeException {
double ret; double ret;
if (p < 0 || p > 1) { if (p < 0 || p > 1) {
throw new OutOfRangeException(p, 0, 1); throw new OutOfRangeException(p, 0, 1);

View File

@ -67,6 +67,7 @@ public class ChiSquaredDistributionImpl
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getDegreesOfFreedom() { public double getDegreesOfFreedom() {
return gamma.getAlpha() * 2.0; return gamma.getAlpha() * 2.0;
} }
@ -80,25 +81,18 @@ public class ChiSquaredDistributionImpl
} }
/** /**
* For this distribution, {@code X}, this method returns {@code P(X < x)}. * {@inheritDoc}
*
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
return gamma.cumulativeProbability(x); return gamma.cumulativeProbability(x);
} }
/** /**
* For this distribution, X, this method returns the critical point * {@inheritDoc}
* {@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. * It will return {@code 0} when {@code p = 0} and
* @return {@code x}, such that {@code P(X < x) = p}. * {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
* @throws org.apache.commons.math.exception.OutOfRangeException if
* {@code p} is not a valid probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(final double p) { public double inverseCumulativeProbability(final double p) {

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.math.distribution; package org.apache.commons.math.distribution;
import org.apache.commons.math.exception.OutOfRangeException;
/** /**
* Base interface for continuous distributions. * Base interface for continuous distributions.
* *
@ -23,19 +25,27 @@ package org.apache.commons.math.distribution;
*/ */
public interface ContinuousDistribution extends Distribution { public interface ContinuousDistribution extends Distribution {
/** /**
* For a distribution, {@code X}, compute {@code x} such that * Computes the quantile function of this distribution. For a random
* {@code P(X < x) = p}. * 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. * @param p the cumulative probability
* @return {@code x} such that {@code P(X < x) = p}. * @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. * @param x the point at which the PDF should be evaluated
* @return the pdf at point {@code x}. * @return the PDF at point {@code x}
*/ */
double density(double x); double density(double x);

View File

@ -16,6 +16,8 @@
*/ */
package org.apache.commons.math.distribution; package org.apache.commons.math.distribution;
import org.apache.commons.math.exception.NumberIsTooLargeException;
/** /**
* Base interface for probability distributions. * Base interface for probability distributions.
* *
@ -23,29 +25,40 @@ package org.apache.commons.math.distribution;
*/ */
public interface Distribution { public interface Distribution {
/** /**
* For a random variable X whose values are distributed according * For a random variable {@code X} whose values are distributed according
* to this distribution, this method returns P(X &le; x). In other words, * to this distribution, this method returns {@code P(X = x)}. In other
* this method represents the (cumulative) distribution function, or * words, this method represents the probability mass function (PMF)
* CDF, for this distribution. * for the distribution.
* *
* @param x the value at which the distribution function is evaluated. * @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 CDF is evaluated
* @return the probability that a random variable with this * @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); double cumulativeProbability(double x);
/** /**
* For a random variable X whose values are distributed according * For a random variable {@code X} whose values are distributed according
* to this distribution, this method returns P(x0 &le; X &le; x1). * to this distribution, this method returns {@code P(x0 < X <= x1)}.
* *
* @param x0 the (inclusive) lower bound * @param x0 the exclusive lower bound
* @param x1 the (inclusive) upper bound * @param x1 the inclusive upper bound
* @return the probability that a random variable with this distribution * @return the probability that a random variable with this distribution
* will take a value between <code>x0</code> and <code>x1</code>, * takes a value between {@code x0} and {@code x1},
* including the endpoints * excluding the lower and including the upper endpoint
* @throws IllegalArgumentException if <code>x0 > x1</code> * @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 * Use this method to get the numerical value of the mean of this

View File

@ -71,6 +71,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getMean() { public double getMean() {
return mean; return mean;
} }
@ -87,7 +88,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, X, this method returns P(X &lt; x). * {@inheritDoc}
* *
* The implementation of this method is based on: * The implementation of this method is based on:
* <ul> * <ul>
@ -95,10 +96,8 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
* <a href="http://mathworld.wolfram.com/ExponentialDistribution.html"> * <a href="http://mathworld.wolfram.com/ExponentialDistribution.html">
* Exponential Distribution</a>, equation (1).</li> * Exponential Distribution</a>, equation (1).</li>
* </ul> * </ul>
*
* @param x Value at which the CDF is evaluated.
* @return the CDF for this distribution.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
double ret; double ret;
if (x <= 0.0) { if (x <= 0.0) {
@ -110,17 +109,13 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, X, this method returns the critical point x, such * {@inheritDoc}
* 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. * It will return {@code 0} when {@code p = 0} and
* @return {@code x}, such that {@code P(X < x) = p}. * {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
* @throws OutOfRangeException if {@code p < 0} or {@code p > 1}.
*/ */
@Override @Override
public double inverseCumulativeProbability(double p) { public double inverseCumulativeProbability(double p) throws OutOfRangeException {
double ret; double ret;
if (p < 0.0 || p > 1.0) { if (p < 0.0 || p > 1.0) {

View File

@ -20,6 +20,7 @@ package org.apache.commons.math.distribution;
import java.io.Serializable; import java.io.Serializable;
import org.apache.commons.math.exception.NotStrictlyPositiveException; 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.exception.util.LocalizedFormats;
import org.apache.commons.math.special.Beta; import org.apache.commons.math.special.Beta;
import org.apache.commons.math.util.FastMath; 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 * @since 2.1
*/ */
@Override @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 * The implementation of this method is based on
* <ul> * <ul>
@ -119,10 +118,8 @@ public class FDistributionImpl
* F-Distribution</a>, equation (4). * F-Distribution</a>, equation (4).
* </li> * </li>
* </ul> * </ul>
*
* @param x Value at which the CDF is evaluated.
* @return CDF for this distribution.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
double ret; double ret;
if (x <= 0) { if (x <= 0) {
@ -139,17 +136,13 @@ public class FDistributionImpl
} }
/** /**
* For this distribution, {@code X}, this method returns the critical * {@inheritDoc}
* point {@code x}, such that {@code P(X < x) = p}.
* Returns 0 when p = 0 and {@code Double.POSITIVE_INFINITY} when p = 1.
* *
* @param p Desired probability. * It will return {@code 0} when {@code p = 0} and
* @return {@code x}, such that {@code P(X < x) = p}. * {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
* @throws IllegalArgumentException if {@code p} is not a valid
* probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(final double p) { public double inverseCumulativeProbability(final double p) throws OutOfRangeException {
if (p == 0) { if (p == 0) {
return 0; return 0;
} }
@ -207,6 +200,7 @@ public class FDistributionImpl
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getNumeratorDegreesOfFreedom() { public double getNumeratorDegreesOfFreedom() {
return numeratorDegreesOfFreedom; return numeratorDegreesOfFreedom;
} }
@ -214,6 +208,7 @@ public class FDistributionImpl
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getDenominatorDegreesOfFreedom() { public double getDenominatorDegreesOfFreedom() {
return denominatorDegreesOfFreedom; return denominatorDegreesOfFreedom;
} }

View File

@ -79,7 +79,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, {@code X}, this method returns {@code P(X < x)}. * {@inheritDoc}
* *
* The implementation of this method is based on: * The implementation of this method is based on:
* <ul> * <ul>
@ -91,10 +91,8 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
* Belmont, CA: Duxbury Press. * Belmont, CA: Duxbury Press.
* </li> * </li>
* </ul> * </ul>
*
* @param x Value at which the CDF is evaluated.
* @return CDF for this distribution.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
double ret; double ret;
@ -108,15 +106,10 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, {@code X}, this method returns the critical * {@inheritDoc}
* 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. * It will return {@code 0} when {@cod p = 0} and
* @return {@code x}, such that {@code P(X < x) = p}. * {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
* @throws org.apache.commons.math.exception.OutOfRangeException if
* {@code p} is not a valid probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(final double p) { public double inverseCumulativeProbability(final double p) {
@ -132,6 +125,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getAlpha() { public double getAlpha() {
return alpha; return alpha;
} }
@ -139,6 +133,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getBeta() { public double getBeta() {
return beta; return beta;
} }

View File

@ -92,6 +92,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getMean() { public double getMean() {
return mean; return mean;
} }
@ -99,6 +100,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getStandardDeviation() { public double getStandardDeviation() {
return standardDeviation; return standardDeviation;
} }
@ -114,13 +116,12 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, {@code X}, this method returns {@code P(X < x)}. * {@inheritDoc}
* 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.
* *
* @param x Value at which the CDF is evaluated. * If {@code x} is more than 40 standard deviations from the mean, 0 or 1 is returned,
* @return CDF evaluated at {@code x}. * as in these cases the actual value is within {@code Double.MIN_VALUE} of 0 or 1.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
final double dev = x - mean; final double dev = x - mean;
if (FastMath.abs(dev) > 40 * standardDeviation) { if (FastMath.abs(dev) > 40 * standardDeviation) {
@ -133,7 +134,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public double cumulativeProbability(double x0, double x1) { public double cumulativeProbability(double x0, double x1) throws NumberIsTooLargeException {
if (x0 > x1) { if (x0 > x1) {
throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT, throw new NumberIsTooLargeException(LocalizedFormats.LOWER_ENDPOINT_ABOVE_UPPER_ENDPOINT,
x0, x1, true); x0, x1, true);
@ -157,19 +158,13 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, X, this method returns the critical point * {@inheritDoc}
* {@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. * It will return {@code Double.NEGATIVE_INFINITY} when {@code p = 0}
* @return {@code x}, such that {@code P(X < x) = p}. * and {@code Double.POSITIVE_INFINITY} for {@code p = 1}.
* @throws org.apache.commons.math.exception.OutOfRangeException if
* {@code p} is not a valid probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(final double p) public double inverseCumulativeProbability(final double p) {
{
if (p == 0) { if (p == 0) {
return Double.NEGATIVE_INFINITY; return Double.NEGATIVE_INFINITY;
} }

View File

@ -79,6 +79,7 @@ public class TDistributionImpl
* *
* @return the degrees of freedom. * @return the degrees of freedom.
*/ */
@Override
public double getDegreesOfFreedom() { public double getDegreesOfFreedom() {
return degreesOfFreedom; return degreesOfFreedom;
} }
@ -96,11 +97,9 @@ public class TDistributionImpl
} }
/** /**
* For this distribution, X, this method returns {@code P(X < x}). * {@inheritDoc}
*
* @param x Value at which the CDF is evaluated.
* @return CDF evaluated at {@code x}.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
double ret; double ret;
if (x == 0) { if (x == 0) {
@ -122,15 +121,10 @@ public class TDistributionImpl
} }
/** /**
* For this distribution, {@code X}, this method returns the critical * {@inheritDoc}
* 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. * It will return {@code Double.NEGATIVE_INFINITY} when {@cod p = 0}
* @return {@code x}, such that {@code P(X < x) = p}. * and {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
* @throws org.apache.commons.math.exception.OutOfRangeException if
* {@code p} is not a valid probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(final double p) { public double inverseCumulativeProbability(final double p) {

View File

@ -88,11 +88,9 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, {@code X}, this method returns {@code P(X < x)}. * {@inheritDoc}
*
* @param x Value at which the CDF is evaluated.
* @return the CDF evaluated at {@code x}.
*/ */
@Override
public double cumulativeProbability(double x) { public double cumulativeProbability(double x) {
double ret; double ret;
if (x <= 0.0) { if (x <= 0.0) {
@ -106,6 +104,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getShape() { public double getShape() {
return shape; return shape;
} }
@ -113,6 +112,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override
public double getScale() { public double getScale() {
return scale; return scale;
} }
@ -140,14 +140,10 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
} }
/** /**
* For this distribution, {@code X}, this method returns the critical * {@inheritDoc}
* 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. * It will return {@code 0} when {@code p = 0} and
* @return {@code x}, such that {@code P(X < x) = p}. * {@code Double.POSITIVE_INFINITY} when {@code p = 1}.
* @throws OutOfRangeException if {@code p} is not a valid probability.
*/ */
@Override @Override
public double inverseCumulativeProbability(double p) { public double inverseCumulativeProbability(double p) {

View File

@ -238,7 +238,7 @@ public abstract class ContinuousDistributionAbstractTest {
distribution.cumulativeProbability distribution.cumulativeProbability
(cumulativeTestPoints[i], cumulativeTestPoints[i]), tolerance); (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 upper = FastMath.max(cumulativeTestPoints[i], cumulativeTestPoints[i -1]);
double lower = FastMath.min(cumulativeTestPoints[i], cumulativeTestPoints[i -1]); double lower = FastMath.min(cumulativeTestPoints[i], cumulativeTestPoints[i -1]);
double diff = distribution.cumulativeProbability(upper) - double diff = distribution.cumulativeProbability(upper) -

View File

@ -72,7 +72,7 @@ public class TDistributionTest extends ContinuousDistributionAbstractTest {
* Bug report that prompted this unit test.</a> * Bug report that prompted this unit test.</a>
*/ */
@Test @Test
public void testCumulativeProbabilityAgaintStackOverflow() throws Exception { public void testCumulativeProbabilityAgainstStackOverflow() throws Exception {
TDistributionImpl td = new TDistributionImpl(5.); TDistributionImpl td = new TDistributionImpl(5.);
td.cumulativeProbability(.1); td.cumulativeProbability(.1);
td.cumulativeProbability(.01); td.cumulativeProbability(.01);