You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ce...@apache.org on 2011/11/26 07:17:52 UTC
svn commit: r1206399 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math/distribution/
main/java/org/apache/commons/math/random/
main/java/org/apache/commons/math/stat/inference/
test/java/org/apache/commons/math/distribution/ test/j...
Author: celestin
Date: Sat Nov 26 06:17:49 2011
New Revision: 1206399
URL: http://svn.apache.org/viewvc?rev=1206399&view=rev
Log:
- Merged ExponentialDistribution and ExponentialDistributionImpl (MATH-711).
- Merged FDistribution and FDistributionImpl (MATH-711).
- Merged GammaDistribution and GammaDistributionImpl (MATH-711).
Added:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java
- copied, changed from r1206052, 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/FDistribution.java
- copied, changed from r1206052, 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/GammaDistribution.java
- copied, changed from r1206052, commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/GammaDistributionImpl.java
Removed:
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
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/random/RandomDataImpl.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java?rev=1206399&r1=1206398&r2=1206399&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java Sat Nov 26 06:17:49 2011
@@ -1,214 +1,214 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math.distribution;
-
-import java.io.Serializable;
-
-
-/**
- * Implementation of the chi-squared distribution.
- *
- * @see <a href="http://en.wikipedia.org/wiki/Chi-squared_distribution">Chi-squared distribution (Wikipedia)</a>
- * @see <a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">Chi-squared Distribution (MathWorld)</a>
- * @version $Id$
- */
-public class ChiSquaredDistribution
- extends AbstractContinuousDistribution
- implements Serializable {
- /**
- * Default inverse cumulative probability accuracy
- * @since 2.1
- */
- public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
- /** Serializable version identifier */
- private static final long serialVersionUID = -8352658048349159782L;
- /** Internal Gamma distribution. */
- private final GammaDistribution gamma;
- /** Inverse cumulative probability accuracy */
- private final double solverAbsoluteAccuracy;
-
- /**
- * Create a Chi-Squared distribution with the given degrees of freedom.
- *
- * @param degreesOfFreedom Degrees of freedom.
- */
- public ChiSquaredDistribution(double degreesOfFreedom) {
- this(degreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
- }
-
- /**
- * Create a Chi-Squared distribution with the given degrees of freedom and
- * inverse cumulative probability accuracy.
- *
- * @param degreesOfFreedom Degrees of freedom.
- * @param inverseCumAccuracy the maximum absolute error in inverse
- * cumulative probability estimates (defaults to
- * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
- * @since 2.1
- */
- public ChiSquaredDistribution(double degreesOfFreedom,
- double inverseCumAccuracy) {
- gamma = new GammaDistributionImpl(degreesOfFreedom / 2, 2);
- solverAbsoluteAccuracy = inverseCumAccuracy;
- }
-
- /**
- * Access the number of degrees of freedom.
- *
- * @return the degrees of freedom.
- */
- public double getDegreesOfFreedom() {
- return gamma.getAlpha() * 2.0;
- }
-
- /** {@inheritDoc} */
- public double density(double x) {
- return gamma.density(x);
- }
-
- /** {@inheritDoc} */
- public double cumulativeProbability(double x) {
- return gamma.cumulativeProbability(x);
- }
-
- /**
- * {@inheritDoc}
- *
- * Returns {@code 0} when {@code p == 0} and
- * {@code Double.POSITIVE_INFINITY} when {@code p == 1}.
- */
- @Override
- public double inverseCumulativeProbability(final double p) {
- if (p == 0) {
- return 0d;
- }
- if (p == 1) {
- return Double.POSITIVE_INFINITY;
- }
- return super.inverseCumulativeProbability(p);
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainLowerBound(double p) {
- return Double.MIN_VALUE * gamma.getBeta();
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getDomainUpperBound(double p) {
- // NOTE: chi squared is skewed to the left
- // NOTE: therefore, P(X < μ) > .5
-
- double ret;
-
- if (p < .5) {
- // use mean
- ret = getDegreesOfFreedom();
- } else {
- // use max
- ret = Double.MAX_VALUE;
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getInitialDomain(double p) {
- // NOTE: chi squared is skewed to the left
- // NOTE: therefore, P(X < μ) > 0.5
-
- double ret;
-
- if (p < 0.5) {
- // use 1/2 mean
- ret = getDegreesOfFreedom() * 0.5;
- } else {
- // use mean
- ret = getDegreesOfFreedom();
- }
-
- return ret;
- }
-
- /** {@inheritDoc} */
- @Override
- protected double getSolverAbsoluteAccuracy() {
- return solverAbsoluteAccuracy;
- }
-
- /**
- * {@inheritDoc}
- *
- * The lower bound of the support is always 0 no matter the
- * degrees of freedom.
- *
- * @return lower bound of the support (always 0)
- */
- @Override
- public double getSupportLowerBound() {
- return 0;
- }
-
- /**
- * {@inheritDoc}
- *
- * 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)
- */
- @Override
- public double getSupportUpperBound() {
- return Double.POSITIVE_INFINITY;
- }
-
- /**
- * {@inheritDoc}
- *
- * For {@code k} degrees of freedom, the mean is {@code k}.
- */
- @Override
- protected double calculateNumericalMean() {
- return getDegreesOfFreedom();
- }
-
- /**
- * {@inheritDoc}
- *
- * For {@code k} degrees of freedom, the variance is {@code 2 * k}.
- *
- * @return {@inheritDoc}
- */
- @Override
- protected double calculateNumericalVariance() {
- return 2*getDegreesOfFreedom();
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isSupportLowerBoundInclusive() {
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isSupportUpperBoundInclusive() {
- return false;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.math.distribution;
+
+import java.io.Serializable;
+
+
+/**
+ * Implementation of the chi-squared distribution.
+ *
+ * @see <a href="http://en.wikipedia.org/wiki/Chi-squared_distribution">Chi-squared distribution (Wikipedia)</a>
+ * @see <a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">Chi-squared Distribution (MathWorld)</a>
+ * @version $Id: ChiSquaredDistribution.java 1206060 2011-11-25 05:16:56Z celestin $
+ */
+public class ChiSquaredDistribution
+ extends AbstractContinuousDistribution
+ implements Serializable {
+ /**
+ * Default inverse cumulative probability accuracy
+ * @since 2.1
+ */
+ public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY = 1e-9;
+ /** Serializable version identifier */
+ private static final long serialVersionUID = -8352658048349159782L;
+ /** Internal Gamma distribution. */
+ private final GammaDistribution gamma;
+ /** Inverse cumulative probability accuracy */
+ private final double solverAbsoluteAccuracy;
+
+ /**
+ * Create a Chi-Squared distribution with the given degrees of freedom.
+ *
+ * @param degreesOfFreedom Degrees of freedom.
+ */
+ public ChiSquaredDistribution(double degreesOfFreedom) {
+ this(degreesOfFreedom, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
+ }
+
+ /**
+ * Create a Chi-Squared distribution with the given degrees of freedom and
+ * inverse cumulative probability accuracy.
+ *
+ * @param degreesOfFreedom Degrees of freedom.
+ * @param inverseCumAccuracy the maximum absolute error in inverse
+ * cumulative probability estimates (defaults to
+ * {@link #DEFAULT_INVERSE_ABSOLUTE_ACCURACY}).
+ * @since 2.1
+ */
+ public ChiSquaredDistribution(double degreesOfFreedom,
+ double inverseCumAccuracy) {
+ gamma = new GammaDistribution(degreesOfFreedom / 2, 2);
+ solverAbsoluteAccuracy = inverseCumAccuracy;
+ }
+
+ /**
+ * Access the number of degrees of freedom.
+ *
+ * @return the degrees of freedom.
+ */
+ public double getDegreesOfFreedom() {
+ return gamma.getAlpha() * 2.0;
+ }
+
+ /** {@inheritDoc} */
+ public double density(double x) {
+ return gamma.density(x);
+ }
+
+ /** {@inheritDoc} */
+ public double cumulativeProbability(double x) {
+ return gamma.cumulativeProbability(x);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Returns {@code 0} when {@code p == 0} and
+ * {@code Double.POSITIVE_INFINITY} when {@code p == 1}.
+ */
+ @Override
+ public double inverseCumulativeProbability(final double p) {
+ if (p == 0) {
+ return 0d;
+ }
+ if (p == 1) {
+ return Double.POSITIVE_INFINITY;
+ }
+ return super.inverseCumulativeProbability(p);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getDomainLowerBound(double p) {
+ return Double.MIN_VALUE * gamma.getBeta();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getDomainUpperBound(double p) {
+ // NOTE: chi squared is skewed to the left
+ // NOTE: therefore, P(X < μ) > .5
+
+ double ret;
+
+ if (p < .5) {
+ // use mean
+ ret = getDegreesOfFreedom();
+ } else {
+ // use max
+ ret = Double.MAX_VALUE;
+ }
+
+ return ret;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getInitialDomain(double p) {
+ // NOTE: chi squared is skewed to the left
+ // NOTE: therefore, P(X < μ) > 0.5
+
+ double ret;
+
+ if (p < 0.5) {
+ // use 1/2 mean
+ ret = getDegreesOfFreedom() * 0.5;
+ } else {
+ // use mean
+ ret = getDegreesOfFreedom();
+ }
+
+ return ret;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ protected double getSolverAbsoluteAccuracy() {
+ return solverAbsoluteAccuracy;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * The lower bound of the support is always 0 no matter the
+ * degrees of freedom.
+ *
+ * @return lower bound of the support (always 0)
+ */
+ @Override
+ public double getSupportLowerBound() {
+ return 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * 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)
+ */
+ @Override
+ public double getSupportUpperBound() {
+ return Double.POSITIVE_INFINITY;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * For {@code k} degrees of freedom, the mean is {@code k}.
+ */
+ @Override
+ protected double calculateNumericalMean() {
+ return getDegreesOfFreedom();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * For {@code k} degrees of freedom, the variance is {@code 2 * k}.
+ *
+ * @return {@inheritDoc}
+ */
+ @Override
+ protected double calculateNumericalVariance() {
+ return 2*getDegreesOfFreedom();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isSupportLowerBoundInclusive() {
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isSupportUpperBoundInclusive() {
+ return false;
+ }
+}
Copied: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java (from r1206052, 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/ExponentialDistribution.java?p2=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistribution.java&p1=commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/ExponentialDistributionImpl.java&r1=1206052&r2=1206399&rev=1206399&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/ExponentialDistribution.java Sat Nov 26 06:17:49 2011
@@ -24,12 +24,14 @@ import org.apache.commons.math.exception
import org.apache.commons.math.util.FastMath;
/**
- * The default implementation of {@link ExponentialDistribution}.
+ * Implementation of the exponential distribution.
*
+ * @see <a href="http://en.wikipedia.org/wiki/Exponential_distribution">Exponential distribution (Wikipedia)</a>
+ * @see <a href="http://mathworld.wolfram.com/ExponentialDistribution.html">Exponential distribution (MathWorld)</a>
* @version $Id$
*/
-public class ExponentialDistributionImpl extends AbstractContinuousDistribution
- implements ExponentialDistribution, Serializable {
+public class ExponentialDistribution extends AbstractContinuousDistribution
+ implements Serializable {
/**
* Default inverse cumulative probability accuracy.
* @since 2.1
@@ -46,7 +48,7 @@ public class ExponentialDistributionImpl
* Create a exponential distribution with the given mean.
* @param mean mean of this distribution.
*/
- public ExponentialDistributionImpl(double mean) {
+ public ExponentialDistribution(double mean) {
this(mean, DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
}
@@ -60,7 +62,8 @@ public class ExponentialDistributionImpl
* @throws NotStrictlyPositiveException if {@code mean <= 0}.
* @since 2.1
*/
- public ExponentialDistributionImpl(double mean, double inverseCumAccuracy) {
+ public ExponentialDistribution(double mean, double inverseCumAccuracy)
+ throws NotStrictlyPositiveException{
if (mean <= 0) {
throw new NotStrictlyPositiveException(LocalizedFormats.MEAN, mean);
}
@@ -69,15 +72,15 @@ public class ExponentialDistributionImpl
}
/**
- * {@inheritDoc}
+ * Access the mean.
+ *
+ * @return the mean.
*/
public double getMean() {
return mean;
}
- /**
- * {@inheritDoc}
- */
+ /** {@inheritDoc} */
public double density(double x) {
if (x < 0) {
return 0;
@@ -108,8 +111,8 @@ public class ExponentialDistributionImpl
/**
* {@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(double p) throws OutOfRangeException {
@@ -127,12 +130,12 @@ public class ExponentialDistributionImpl
}
/**
- * Generates a random value sampled from this distribution.
+ * {@inheritDoc}
*
- * <p><strong>Algorithm Description</strong>: Uses the <a
- * href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html"> Inversion
- * Method</a> to generate exponentially distributed random values from
- * uniform deviates.</p>
+ * <p><strong>Algorithm Description</strong>: this implementation uses the
+ * <a href="http://www.jesus.ox.ac.uk/~clifford/a5/chap1/node5.html">
+ * Inversion Method</a> to generate exponentially distributed random values
+ * from uniform deviates.</p>
*
* @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 <code>k</code>, the mean is
- * <code>k</code>
- *
- * @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 <code>k</code>, the variance is
- * <code>k^2</code>
- *
- * @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 <a href="http://en.wikipedia.org/wiki/F-distribution">F-distribution (Wikipedia)</a>
+ * @see <a href="http://mathworld.wolfram.com/F-Distribution.html">F-distribution (MathWorld)</a>
* @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 <code>b</code>,
- * the mean is
+ * For denominator degrees of freedom parameter {@code b}, the mean is
* <ul>
- * <li>if <code>b > 2</code> then <code>b / (b - 2)</code></li>
- * <li>else <code>undefined</code>
+ * <li>if {@code b > 2} then {@code b / (b - 2)},</li>
+ * <li>else undefined ({@code Double.NaN}).
* </ul>
- *
- * @return {@inheritDoc}
*/
@Override
protected double calculateNumericalMean() {
@@ -272,18 +251,15 @@ public class FDistributionImpl
/**
* {@inheritDoc}
*
- * For numerator degrees of freedom parameter <code>a</code>
- * and denominator degrees of freedom parameter <code>b</code>,
- * the variance is
+ * For numerator degrees of freedom parameter {@code a} and denominator
+ * degrees of freedom parameter {@code b}, the variance is
* <ul>
* <li>
- * if <code>b > 4</code> then
- * <code>[ 2 * b^2 * (a + b - 2) ] / [ a * (b - 2)^2 * (b - 4) ]</code>
+ * if {@code b > 4} then
+ * {@code [2 * b^2 * (a + b - 2)] / [a * (b - 2)^2 * (b - 4)]},
* </li>
- * <li>else <code>undefined</code>
+ * <li>else undefined ({@code Double.NaN}).
* </ul>
- *
- * @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 <a href="http://en.wikipedia.org/wiki/Gamma_distribution">Gamma distribution (Wikipedia)</a>
+ * @see <a href="http://mathworld.wolfram.com/GammaDistribution.html">Gamma distribution (MathWorld)</a>
* @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 <code>alpha</code> and scale
- * parameter <code>beta</code>, the mean is
- * <code>alpha * beta</code>
- *
- * @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 <code>alpha</code> and scale
- * parameter <code>beta</code>, the variance is
- * <code>alpha * beta^2</code>
+ * 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));
}
/**
* <p>Generates a random value from the
- * {@link org.apache.commons.math.distribution.GammaDistributionImpl Gamma Distribution}.</p>
+ * {@link org.apache.commons.math.distribution.GammaDistribution Gamma Distribution}.</p>
*
* <p>This implementation uses the following algorithms: </p>
*
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java?rev=1206399&r1=1206398&r2=1206399&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/inference/OneWayAnovaImpl.java Sat Nov 26 06:17:49 2011
@@ -21,7 +21,6 @@ import java.util.Collection;
import org.apache.commons.math.MathException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.distribution.FDistribution;
-import org.apache.commons.math.distribution.FDistributionImpl;
import org.apache.commons.math.exception.util.LocalizedFormats;
import org.apache.commons.math.stat.descriptive.summary.Sum;
import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
@@ -84,7 +83,7 @@ public class OneWayAnovaImpl implements
public double anovaPValue(Collection<double[]> categoryData)
throws IllegalArgumentException, MathException {
AnovaStats a = anovaStats(categoryData);
- FDistribution fdist = new FDistributionImpl(a.dfbg, a.dfwg);
+ FDistribution fdist = new FDistribution(a.dfbg, a.dfwg);
return 1.0 - fdist.cumulativeProbability(a.F);
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java?rev=1206399&r1=1206398&r2=1206399&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/ExponentialDistributionTest.java Sat Nov 26 06:17:49 2011
@@ -43,7 +43,7 @@ public class ExponentialDistributionTest
/** Creates the default continuous distribution instance to use in tests. */
@Override
public ExponentialDistribution makeDistribution() {
- return new ExponentialDistributionImpl(5.0);
+ return new ExponentialDistribution(5.0);
}
/** Creates the default cumulative probability distribution test input values */
@@ -92,14 +92,14 @@ public class ExponentialDistributionTest
@Test
public void testDensity() {
- ExponentialDistribution d1 = new ExponentialDistributionImpl(1);
+ ExponentialDistribution d1 = new ExponentialDistribution(1);
Assert.assertTrue(Precision.equals(0.0, d1.density(-1e-9), 1));
Assert.assertTrue(Precision.equals(1.0, d1.density(0.0), 1));
Assert.assertTrue(Precision.equals(0.0, d1.density(1000.0), 1));
Assert.assertTrue(Precision.equals(FastMath.exp(-1), d1.density(1.0), 1));
Assert.assertTrue(Precision.equals(FastMath.exp(-2), d1.density(2.0), 1));
- ExponentialDistribution d2 = new ExponentialDistributionImpl(3);
+ ExponentialDistribution d2 = new ExponentialDistribution(3);
Assert.assertTrue(Precision.equals(1/3.0, d2.density(0.0), 1));
// computed using print(dexp(1, rate=1/3), digits=10) in R 2.5
Assert.assertEquals(0.2388437702, d2.density(1.0), 1e-8);
@@ -116,19 +116,19 @@ public class ExponentialDistributionTest
@Test(expected=NotStrictlyPositiveException.class)
public void testPreconditions() {
- new ExponentialDistributionImpl(0);
+ new ExponentialDistribution(0);
}
@Test
public void testMoments() {
final double tol = 1e-9;
ExponentialDistribution dist;
-
- dist = new ExponentialDistributionImpl(11d);
+
+ dist = new ExponentialDistribution(11d);
Assert.assertEquals(dist.getNumericalMean(), 11d, tol);
Assert.assertEquals(dist.getNumericalVariance(), 11d * 11d, tol);
-
- dist = new ExponentialDistributionImpl(10.5d);
+
+ dist = new ExponentialDistribution(10.5d);
Assert.assertEquals(dist.getNumericalMean(), 10.5d, tol);
Assert.assertEquals(dist.getNumericalVariance(), 10.5d * 10.5d, tol);
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java?rev=1206399&r1=1206398&r2=1206399&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/FDistributionTest.java Sat Nov 26 06:17:49 2011
@@ -34,7 +34,7 @@ public class FDistributionTest extends C
/** Creates the default continuous distribution instance to use in tests. */
@Override
public FDistribution makeDistribution() {
- return new FDistributionImpl(5.0, 6.0);
+ return new FDistribution(5.0, 6.0);
}
/** Creates the default cumulative probability distribution test input values */
@@ -91,13 +91,13 @@ public class FDistributionTest extends C
@Test
public void testPreconditions() {
try {
- new FDistributionImpl(0, 1);
+ new FDistribution(0, 1);
Assert.fail("Expecting NotStrictlyPositiveException for df = 0");
} catch (NotStrictlyPositiveException ex) {
// Expected.
}
try {
- new FDistributionImpl(1, 0);
+ new FDistribution(1, 0);
Assert.fail("Expecting NotStrictlyPositiveException for df = 0");
} catch (NotStrictlyPositiveException ex) {
// Expected.
@@ -106,7 +106,7 @@ public class FDistributionTest extends C
@Test
public void testLargeDegreesOfFreedom() throws Exception {
- FDistributionImpl fd = new FDistributionImpl(100000, 100000);
+ FDistribution fd = new FDistribution(100000, 100000);
double p = fd.cumulativeProbability(.999);
double x = fd.inverseCumulativeProbability(p);
Assert.assertEquals(.999, x, 1.0e-5);
@@ -114,12 +114,12 @@ public class FDistributionTest extends C
@Test
public void testSmallDegreesOfFreedom() throws Exception {
- FDistributionImpl fd = new FDistributionImpl(1, 1);
+ FDistribution fd = new FDistribution(1, 1);
double p = fd.cumulativeProbability(0.975);
double x = fd.inverseCumulativeProbability(p);
Assert.assertEquals(0.975, x, 1.0e-5);
- fd = new FDistributionImpl(1, 2);
+ fd = new FDistribution(1, 2);
p = fd.cumulativeProbability(0.975);
x = fd.inverseCumulativeProbability(p);
Assert.assertEquals(0.975, x, 1.0e-5);
@@ -129,17 +129,17 @@ public class FDistributionTest extends C
public void testMoments() {
final double tol = 1e-9;
FDistribution dist;
-
- dist = new FDistributionImpl(1, 2);
+
+ dist = new FDistribution(1, 2);
Assert.assertTrue(Double.isNaN(dist.getNumericalMean()));
Assert.assertTrue(Double.isNaN(dist.getNumericalVariance()));
-
- dist = new FDistributionImpl(1, 3);
+
+ dist = new FDistribution(1, 3);
Assert.assertEquals(dist.getNumericalMean(), 3d / (3d - 2d), tol);
Assert.assertTrue(Double.isNaN(dist.getNumericalVariance()));
-
- dist = new FDistributionImpl(1, 5);
+
+ dist = new FDistribution(1, 5);
Assert.assertEquals(dist.getNumericalMean(), 5d / (5d - 2d), tol);
- Assert.assertEquals(dist.getNumericalVariance(), (2d * 5d * 5d * 4d) / 9d, tol);
+ Assert.assertEquals(dist.getNumericalVariance(), (2d * 5d * 5d * 4d) / 9d, tol);
}
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java?rev=1206399&r1=1206398&r2=1206399&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/distribution/GammaDistributionTest.java Sat Nov 26 06:17:49 2011
@@ -35,7 +35,7 @@ public class GammaDistributionTest exten
/** Creates the default continuous distribution instance to use in tests. */
@Override
public GammaDistribution makeDistribution() {
- return new GammaDistributionImpl(4d, 2d);
+ return new GammaDistribution(4d, 2d);
}
/** Creates the default cumulative probability distribution test input values */
@@ -77,13 +77,13 @@ public class GammaDistributionTest exten
@Test
public void testPreconditions() {
try {
- new GammaDistributionImpl(0, 1);
+ new GammaDistribution(0, 1);
Assert.fail("Expecting NotStrictlyPositiveException for alpha = 0");
} catch (NotStrictlyPositiveException ex) {
// Expected.
}
try {
- new GammaDistributionImpl(1, 0);
+ new GammaDistribution(1, 0);
Assert.fail("Expecting NotStrictlyPositiveException for alpha = 0");
} catch (NotStrictlyPositiveException ex) {
// Expected.
@@ -108,13 +108,13 @@ public class GammaDistributionTest exten
}
private void testProbability(double x, double a, double b, double expected) throws Exception {
- GammaDistribution distribution = new GammaDistributionImpl( a, b );
+ GammaDistribution distribution = new GammaDistribution( a, b );
double actual = distribution.cumulativeProbability(x);
Assert.assertEquals("probability for " + x, expected, actual, 10e-4);
}
private void testValue(double expected, double a, double b, double p) throws Exception {
- GammaDistribution distribution = new GammaDistributionImpl( a, b );
+ GammaDistribution distribution = new GammaDistribution( a, b );
double actual = distribution.inverseCumulativeProbability(p);
Assert.assertEquals("critical value for " + p, expected, actual, 10e-4);
}
@@ -141,7 +141,7 @@ public class GammaDistributionTest exten
}
private void checkDensity(double alpha, double rate, double[] x, double[] expected) {
- GammaDistribution d = new GammaDistributionImpl(alpha, 1 / rate);
+ GammaDistribution d = new GammaDistribution(alpha, 1 / rate);
for (int i = 0; i < x.length; i++) {
Assert.assertEquals(expected[i], d.density(x[i]), 1e-5);
}
@@ -158,12 +158,12 @@ public class GammaDistributionTest exten
public void testMoments() {
final double tol = 1e-9;
GammaDistribution dist;
-
- dist = new GammaDistributionImpl(1, 2);
+
+ dist = new GammaDistribution(1, 2);
Assert.assertEquals(dist.getNumericalMean(), 2, tol);
- Assert.assertEquals(dist.getNumericalVariance(), 4, tol);
-
- dist = new GammaDistributionImpl(1.1, 4.2);
+ Assert.assertEquals(dist.getNumericalVariance(), 4, tol);
+
+ dist = new GammaDistribution(1.1, 4.2);
Assert.assertEquals(dist.getNumericalMean(), 1.1d * 4.2d, tol);
Assert.assertEquals(dist.getNumericalVariance(), 1.1d * 4.2d * 4.2d, tol);
}
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java?rev=1206399&r1=1206398&r2=1206399&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/random/RandomDataTest.java Sat Nov 26 06:17:49 2011
@@ -30,9 +30,9 @@ import org.apache.commons.math.distribut
import org.apache.commons.math.distribution.BinomialDistributionTest;
import org.apache.commons.math.distribution.CauchyDistribution;
import org.apache.commons.math.distribution.ChiSquaredDistribution;
-import org.apache.commons.math.distribution.ExponentialDistributionImpl;
-import org.apache.commons.math.distribution.FDistributionImpl;
-import org.apache.commons.math.distribution.GammaDistributionImpl;
+import org.apache.commons.math.distribution.ExponentialDistribution;
+import org.apache.commons.math.distribution.FDistribution;
+import org.apache.commons.math.distribution.GammaDistribution;
import org.apache.commons.math.distribution.HypergeometricDistributionImpl;
import org.apache.commons.math.distribution.HypergeometricDistributionTest;
import org.apache.commons.math.distribution.PascalDistributionImpl;
@@ -616,7 +616,7 @@ public class RandomDataTest {
long[] counts;
// Mean 1
- quartiles = TestUtils.getDistributionQuartiles(new ExponentialDistributionImpl(1));
+ quartiles = TestUtils.getDistributionQuartiles(new ExponentialDistribution(1));
counts = new long[4];
randomData.reSeed(1000);
for (int i = 0; i < 1000; i++) {
@@ -626,7 +626,7 @@ public class RandomDataTest {
TestUtils.assertChiSquareAccept(expected, counts, 0.001);
// Mean 5
- quartiles = TestUtils.getDistributionQuartiles(new ExponentialDistributionImpl(5));
+ quartiles = TestUtils.getDistributionQuartiles(new ExponentialDistribution(5));
counts = new long[4];
randomData.reSeed(1000);
for (int i = 0; i < 1000; i++) {
@@ -896,7 +896,7 @@ public class RandomDataTest {
@Test
public void testNextF() throws Exception {
- double[] quartiles = TestUtils.getDistributionQuartiles(new FDistributionImpl(12, 5));
+ double[] quartiles = TestUtils.getDistributionQuartiles(new FDistribution(12, 5));
long[] counts = new long[4];
randomData.reSeed(1000);
for (int i = 0; i < 1000; i++) {
@@ -912,7 +912,7 @@ public class RandomDataTest {
long[] counts;
// Tests shape > 1, one case in the rejection sampling
- quartiles = TestUtils.getDistributionQuartiles(new GammaDistributionImpl(4, 2));
+ quartiles = TestUtils.getDistributionQuartiles(new GammaDistribution(4, 2));
counts = new long[4];
randomData.reSeed(1000);
for (int i = 0; i < 1000; i++) {
@@ -922,7 +922,7 @@ public class RandomDataTest {
TestUtils.assertChiSquareAccept(expected, counts, 0.001);
// Tests shape <= 1, another case in the rejection sampling
- quartiles = TestUtils.getDistributionQuartiles(new GammaDistributionImpl(0.3, 3));
+ quartiles = TestUtils.getDistributionQuartiles(new GammaDistribution(0.3, 3));
counts = new long[4];
randomData.reSeed(1000);
for (int i = 0; i < 1000; i++) {