This is a multifile commit, it covers checkstyle errors in javadoc etc.

PR: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20936
Submitted by:	brent@worden.org


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140936 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark R. Diggory 2003-06-21 02:21:49 +00:00
parent d3f4480aff
commit b84e9460b5
14 changed files with 157 additions and 151 deletions

View File

@ -54,16 +54,14 @@
package org.apache.commons.math;
/**
* <p>
* Provides a generic means to evaluate continued fractions. Subclasses simply
* provided the a and b coefficients to evaluate the continued fraction.
* </p>
*
* <p>
* Reference:<br/>
* <a href="http://mathworld.wolfram.com/ContinuedFraction.html">
* Continued Fraction</a>
* </p>
* References:
* <ul>
* <li><a href="http://mathworld.wolfram.com/ContinuedFraction.html">
* Continued Fraction</a></li>
* </ul>
*
* @author Brent Worden
*/
@ -126,11 +124,8 @@ public abstract class ContinuedFraction {
}
/**
* <p>
* Evaluates the continued fraction at the value x.
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li>O. E-gecio-glu, C . K. Koc, J. Rifa i Coma,
@ -138,7 +133,6 @@ public abstract class ContinuedFraction {
* Fast Computation of Continued Fractions</a>, Computers Math. Applic.,
* 21(2--3), 1991, 167--169.</li>
* </ul>
* </p>
*
* @param x the evaluation point.
* @param epsilon maximum error allowed.
@ -188,11 +182,11 @@ public abstract class ContinuedFraction {
f[1][1] = (a[1][0] * an[0][1]) + (a[1][1] * an[1][1]);
// determine if we're close enough
if(Math.abs((f[0][0] * f[1][1]) - (f[1][0] * f[0][1])) <
Math.abs(epsilon * f[1][0] * f[1][1])){
if (Math.abs((f[0][0] * f[1][1]) - (f[1][0] * f[0][1])) <
Math.abs(epsilon * f[1][0] * f[1][1])) {
ret = f[0][0] / f[1][0];
} else {
if(n >= maxIterations){
if (n >= maxIterations) {
throw new ConvergenceException(
"Continued fraction convergents failed to converge.");
}

View File

@ -94,7 +94,7 @@ public abstract class AbstractContinuousDistribution
* @return x, such that P(X &lt; x) = <code>p</code>
*/
public double inverseCummulativeProbability(final double p) {
if (p < 0.0 || p > 1.0){
if (p < 0.0 || p > 1.0) {
throw new IllegalArgumentException(
"p must be between 0.0 and 1.0, inclusive.");
}

View File

@ -54,21 +54,16 @@
package org.apache.commons.math.stat.distribution;
/**
* <p>
* The Chi-Squared Distribution
* </p>
* The Chi-Squared Distribution.
*
* <p>
* Instances of ChiSquaredDistribution objects should be created using
* {@link DistributionFactory#createChiSquareDistribution(double)}
* </p>
* {@link DistributionFactory#createChiSquareDistribution(double)}.
*
* <p>
* References:
* <ul>
* <li><a href="http://mathworld.wolfram.com/Chi-SquaredDistribution.html">
* Chi-Squared Distribution</a></li>
* </p>
* </ul>
*
* @author Brent Worden
*/

View File

@ -54,7 +54,6 @@
package org.apache.commons.math.stat.distribution;
/**
* <p>
* This factory provids the means to create common statistical distributions.
* The following distributions are supported:
* <ul>
@ -63,16 +62,13 @@ package org.apache.commons.math.stat.distribution;
* <li>Gamma</li>
* <li>Student's t</li>
* </ul>
* </p>
*
* <p>
* Common usage:<pre>
* DistributionFactory factory = DistributionFactory.newInstance();
*
* // create a Chi-Square distribution with 5 degrees of freedom.
* ChiSquaredDistribution chi = factory.createChiSquareDistribution(5.0);
* </pre>
* </p>
*
* @author Brent Worden
*/

View File

@ -54,21 +54,15 @@
package org.apache.commons.math.stat.distribution;
/**
* <p>
* The Exponential Distribution
* </p>
* The Exponential Distribution.
*
* <p>
* Instances of ExponentialDistribution objects should be created using
* {@link DistributionFactory#createExponentialDistribution(double)}
* </p>
* {@link DistributionFactory#createExponentialDistribution(double)}.
*
* <p>
* References:
* <ul>
* <li><a href="http://mathworld.wolfram.com/ExponentialDistribution.html">
* Exponential Distribution</a></li>
* </p>
*
* @author Brent Worden
*/

View File

@ -1,3 +1,56 @@
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.math.stat.distribution;
/**
@ -6,65 +59,61 @@ package org.apache.commons.math.stat.distribution;
* @author Brent Worden
*/
public class ExponentialDistributionImpl
implements ExponentialDistribution {
implements ExponentialDistribution {
/** The mean of this distribution. */
private double mean;
/**
* Create a exponential distribution with the given mean.
* @param degreesOfFreedom degrees of freedom.
* @param mean mean of this distribution.
*/
public ExponentialDistributionImpl(double mean) {
super();
public ExponentialDistributionImpl(double mean) {
super();
setMean(mean);
}
}
/**
* Modify the mean.
* @param mean the new mean.
*/
public void setMean(double mean) {
if(mean <= 0.0){
public void setMean(double mean) {
if (mean <= 0.0) {
throw new IllegalArgumentException("mean must be positive.");
}
this.mean = mean;
}
}
/**
* Access the mean.
* @return the mean.
*/
public double getMean() {
return mean;
}
public double getMean() {
return mean;
}
/**
* <p>
* For this disbution, X, this method returns P(X &lt; x).
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li>
* <a href="http://mathworld.wolfram.com/ExponentialDistribution.html">
* Exponential Distribution</a>, equation (1).</li>
* </ul>
* </p>
*
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
*/
public double cummulativeProbability(double x) {
public double cummulativeProbability(double x) {
double ret;
if(x <= 0.0){
if (x <= 0.0) {
ret = 0.0;
} else {
} else {
ret = 1.0 - Math.exp(-x / getMean());
}
}
return ret;
}
}
/**
* For this distribution, X, this method returns the critical point x, such
@ -73,12 +122,12 @@ public class ExponentialDistributionImpl
* @param p the desired probability
* @return x, such that P(X &lt; x) = <code>p</code>
*/
public double inverseCummulativeProbability(double p){
public double inverseCummulativeProbability(double p) {
double ret;
if(p < 0.0 || p > 1.0){
if (p < 0.0 || p > 1.0) {
ret = Double.NaN;
} else if(p == 1.0){
} else if (p == 1.0) {
ret = Double.POSITIVE_INFINITY;
} else {
ret = -getMean() * Math.log(1.0 - p);

View File

@ -54,20 +54,16 @@
package org.apache.commons.math.stat.distribution;
/**
* <p>
* F-Distribution.
* </p>
*
* <p>
* Instances of FDistribution objects should be created using
* {@link DistributionFactory#createFDistribution(double,double)}
* </p>
* {@link DistributionFactory#createFDistribution(double,double)}.
*
* <p>
* Reference:<br/>
* <a href="http://mathworld.wolfram.com/F-Distribution.html">
* F-Distribution</a>
* </p>
* References:
* <ul>
* <li><a href="http://mathworld.wolfram.com/F-Distribution.html">
* F-Distribution</a></li>
* </ul>
*
* @author Brent Worden
*/

View File

@ -57,7 +57,7 @@ import org.apache.commons.math.special.Beta;
/**
* Default implementation of
* {@link org.apache.commons.math.stat.distribution.TDistribution}.
* {@link org.apache.commons.math.stat.distribution.FDistribution}.
*
* @author Brent Worden
*/
@ -73,35 +73,32 @@ public class FDistributionImpl
/**
* Create a F distribution using the given degrees of freedom.
* @param numeratorDegreesOfFreedom the degrees of freedom.
* @param denominatorDegreesOfFreedom
* @param numeratorDegreesOfFreedom the numerator degrees of freedom.
* @param denominatorDegreesOfFreedom the denominator degrees of freedom.
*/
public FDistributionImpl(double numeratorDegreesOfFreedom,
double denominatorDegreesOfFreedom){
double denominatorDegreesOfFreedom) {
super();
setNumeratorDegreesOfFreedom(numeratorDegreesOfFreedom);
setDenominatorDegreesOfFreedom(denominatorDegreesOfFreedom);
}
/**
* <p>
* For this disbution, X, this method returns P(X &lt; x).
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li>
* <a href="http://mathworld.wolfram.com/F-Distribution.html">
* F-Distribution</a>, equation (4).</li>
* </p>
* </ul>
*
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
*/
public double cummulativeProbability(double x) {
double ret;
if(x <= 0.0){
if (x <= 0.0) {
ret = 0.0;
} else {
double n = getNumeratorDegreesOfFreedom();
@ -123,7 +120,7 @@ public class FDistributionImpl
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
protected double getDomainLowerBound(double p){
protected double getDomainLowerBound(double p) {
return 0.0;
}
@ -136,7 +133,7 @@ public class FDistributionImpl
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
protected double getDomainUpperBound(double p){
protected double getDomainUpperBound(double p) {
return Double.MAX_VALUE;
}
@ -148,16 +145,17 @@ public class FDistributionImpl
* @param p the desired probability for the critical value
* @return initial domain value
*/
protected double getInitialDomain(double p){
return getDenominatorDegreesOfFreedom() / (getDenominatorDegreesOfFreedom() - 2.0);
protected double getInitialDomain(double p) {
return getDenominatorDegreesOfFreedom() /
(getDenominatorDegreesOfFreedom() - 2.0);
}
/**
* Modify the numerator degrees of freedom.
* @param degreesOfFreedom the new numerator degrees of freedom.
*/
public void setNumeratorDegreesOfFreedom(double degreesOfFreedom){
if(degreesOfFreedom <= 0.0){
public void setNumeratorDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
throw new IllegalArgumentException(
"degrees of freedom must be positive.");
}
@ -168,7 +166,7 @@ public class FDistributionImpl
* Access the numerator degrees of freedom.
* @return the numerator degrees of freedom.
*/
public double getNumeratorDegreesOfFreedom(){
public double getNumeratorDegreesOfFreedom() {
return numeratorDegreesOfFreedom;
}
@ -176,8 +174,8 @@ public class FDistributionImpl
* Modify the denominator degrees of freedom.
* @param degreesOfFreedom the new denominator degrees of freedom.
*/
public void setDenominatorDegreesOfFreedom(double degreesOfFreedom){
if(degreesOfFreedom <= 0.0){
public void setDenominatorDegreesOfFreedom(double degreesOfFreedom) {
if (degreesOfFreedom <= 0.0) {
throw new IllegalArgumentException(
"degrees of freedom must be positive.");
}
@ -188,7 +186,7 @@ public class FDistributionImpl
* Access the denominator degrees of freedom.
* @return the denominator degrees of freedom.
*/
public double getDenominatorDegreesOfFreedom(){
public double getDenominatorDegreesOfFreedom() {
return denominatorDegreesOfFreedom;
}
}

View File

@ -54,21 +54,16 @@
package org.apache.commons.math.stat.distribution;
/**
* <p>
* The Gamma Distribution
* </p>
* The Gamma Distribution.
*
* <p>
* Instances of GammaDistribution objects should be created using
* {@link DistributionFactory#createGammaDistribution(double,double)}
* </p>
* {@link DistributionFactory#createGammaDistribution(double,double)}.
*
* <p>
* References:
* <ul>
* <li><a href="http://mathworld.wolfram.com/GammaDistribution.html">
* Gamma Distribution</a></li>
* </p>
* </ul>
*
* @author Brent Worden
*/

View File

@ -81,11 +81,8 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
}
/**
* <p>
* For this disbution, X, this method returns P(X &lt; x).
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li>
@ -94,7 +91,6 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
* <li>Casella, G., & Berger, R. (1990). <i>Statistical Inference</i>.
* Belmont, CA: Duxbury Press.</li>
* </ul>
* </p>
*
* @param x the value at which the CDF is evaluated.
* @return CDF for this distribution.
@ -179,7 +175,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
double ret;
if(p < .5){
if (p < .5) {
// use mean
ret = getAlpha() * getBeta();
} else {
@ -205,7 +201,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
double ret;
if(p < .5){
if (p < .5) {
// use 1/2 mean
ret = getAlpha() * getBeta() * .5;
} else {

View File

@ -54,20 +54,16 @@
package org.apache.commons.math.stat.distribution;
/**
* <p>
* Student's t-Distribution.
* </p>
*
* <p>
* Instances of TDistribution objects should be created using
* {@link DistributionFactory#createTDistribution(double)}
* </p>
*
* <p>
* Reference:<br/>
* <a href="http://mathworld.wolfram.com/Studentst-Distribution.html">
* Student's t-Distribution</a>
* </p>
* References:
* <ul>
* <li><a href="http://mathworld.wolfram.com/Studentst-Distribution.html">
* Student's t-Distribution</a></li>
* </ul>
*
* @author Brent Worden
*/

View File

@ -72,7 +72,7 @@ public class TDistributionImpl
* Create a t distribution using the given degrees of freedom.
* @param degreesOfFreedom the degrees of freedom.
*/
public TDistributionImpl(double degreesOfFreedom){
public TDistributionImpl(double degreesOfFreedom) {
super();
setDegreesOfFreedom(degreesOfFreedom);
}
@ -82,7 +82,7 @@ public class TDistributionImpl
* @param degreesOfFreedom the new degrees of freedom.
*/
public void setDegreesOfFreedom(double degreesOfFreedom) {
if(degreesOfFreedom <= 0.0){
if (degreesOfFreedom <= 0.0) {
throw new IllegalArgumentException(
"degrees of freedom must be positive.");
}
@ -104,14 +104,14 @@ public class TDistributionImpl
*/
public double cummulativeProbability(double x) {
double ret;
if(x == 0.0){
if (x == 0.0) {
ret = 0.5;
} else {
double t = Beta.regularizedBeta(
getDegreesOfFreedom() / (getDegreesOfFreedom() + (x * x)),
0.5 * getDegreesOfFreedom(), 0.5);
if(x < 0.0){
if (x < 0.0) {
ret = 0.5 * t;
} else {
ret = 1.0 - 0.5 * t;
@ -130,7 +130,7 @@ public class TDistributionImpl
* @return domain value lower bound, i.e.
* P(X &lt; <i>lower bound</i>) &lt; <code>p</code>
*/
protected double getDomainLowerBound(double p){
protected double getDomainLowerBound(double p) {
return -Double.MAX_VALUE;
}
@ -143,7 +143,7 @@ public class TDistributionImpl
* @return domain value upper bound, i.e.
* P(X &lt; <i>upper bound</i>) &gt; <code>p</code>
*/
protected double getDomainUpperBound(double p){
protected double getDomainUpperBound(double p) {
return Double.MAX_VALUE;
}
@ -155,7 +155,7 @@ public class TDistributionImpl
* @param p the desired probability for the critical value
* @return initial domain value
*/
protected double getInitialDomain(double p){
protected double getInitialDomain(double p) {
return 0.0;
}
}

View File

@ -73,9 +73,7 @@ public class Beta {
}
/**
* <p>
* Returns the regularized beta function I(x, a, b).
* </p>
*
* @param x ???
* @param a ???
@ -87,39 +85,40 @@ public class Beta {
}
/**
* <p>
* Returns the regularized beta function I(x, a, b).
* </p>
*
* @param x ???
* @param a ???
* @param b ???
* @param epsilon When the absolute value of the nth item in the
* series is less than epsilon the approximation ceases
* to calculate further elements in the series.
* @return the regularized beta function I(x, a, b)
*/
public static double regularizedBeta(double x, double a, double b, double epsilon) {
public static double regularizedBeta(double x, double a, double b,
double epsilon) {
return regularizedBeta(x, a, b, epsilon, Integer.MAX_VALUE);
}
/**
* <p>
* Returns the regularized beta function I(x, a, b).
* </p>
*
* @param x ???
* @param a ???
* @param b ???
* @param maxIterations Maximum number of "iterations" to complete.
* @return the regularized beta function I(x, a, b)
*/
public static double regularizedBeta(double x, double a, double b, int maxIterations) {
public static double regularizedBeta(double x, double a, double b,
int maxIterations) {
return regularizedBeta(x, a, b, DEFAULT_EPSILON, maxIterations);
}
/**
* <p>
* Returns the regularized beta function I(x, a, b).
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li>
@ -129,14 +128,19 @@ public class Beta {
* <a href="http://functions.wolfram.com/06.21.10.0001.01">
* Regularized Beta Function</a>.</li>
* </ul>
* </p>
*
* @param x ???
* @param a ???
* @param b ???
* @param epsilon When the absolute value of the nth item in the
* series is less than epsilon the approximation ceases
* to calculate further elements in the series.
* @param maxIterations Maximum number of "iterations" to complete.
* @return the regularized beta function I(x, a, b)
*/
public static double regularizedBeta(double x, final double a, final double b, double epsilon, int maxIterations) {
public static double regularizedBeta(double x, final double a,
final double b, double epsilon, int maxIterations) {
double ret;
if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b) || (x < 0)
@ -155,8 +159,9 @@ public class Beta {
if (n % 2 == 0) { // even
m = (n - 2.0) / 2.0;
ret =
- ((a + m) * (a + b + m) * x)
/ ((a + (2 * m)) * (a + (2 * m) + 1.0));
-((a + m) * (a + b + m) * x)
/ ((a + (2 * m))
* (a + (2 * m) + 1.0));
} else {
m = (n - 1.0) / 2.0;
ret =
@ -180,17 +185,17 @@ public class Beta {
}
return ret;
}
};
ret = Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x)) - Math.log(a) - logBeta(a, b, epsilon, maxIterations)) * fraction.evaluate(x, epsilon, maxIterations);
};
ret = Math.exp((a * Math.log(x)) + (b * Math.log(1.0 - x))
- Math.log(a) - logBeta(a, b, epsilon, maxIterations))
* fraction.evaluate(x, epsilon, maxIterations);
}
return ret;
}
/**
* <p>
* Returns the natural logarithm of the beta function B(a, b).
* </p>
*
* @param a ???
* @param b ???
@ -201,23 +206,25 @@ public class Beta {
}
/**
* <p>
* Returns the natural logarithm of the beta function B(a, b).
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li><a href="http://mathworld.wolfram.com/BetaFunction.html">
* Beta Function</a>, equation (1).</li>
* </ul>
* </p>
*
* @param a ???
* @param b ???
* @param epsilon When the absolute value of the nth item in the
* series is less than epsilon the approximation ceases
* to calculate further elements in the series.
* @param maxIterations Maximum number of "iterations" to complete.
* @return log(B(a, b))
*/
public static double logBeta(double a, double b, double epsilon, int maxIterations) {
public static double logBeta(double a, double b, double epsilon,
int maxIterations) {
double ret;
if (Double.isNaN(a) || Double.isNaN(b) || (a <= 0.0) || (b <= 0.0)) {

View File

@ -94,9 +94,7 @@ public class Gamma {
}
/**
* <p>
* Returns the regularized gamma function P(a, x).
* </p>
*
* @param a ???
* @param x ???
@ -107,11 +105,8 @@ public class Gamma {
}
/**
* <p>
* Returns the regularized gamma function P(a, x).
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li>
@ -125,7 +120,6 @@ public class Gamma {
* Confluent Hypergeometric Function of the First Kind</a>, equation (1).
* </li>
* </ul>
* </p>
*
* @param a ???
* @param x ???
@ -173,11 +167,8 @@ public class Gamma {
}
/**
* <p>
* Returns the natural logarithm of the gamma function &#915;(x).
* </p>
*
* <p>
* The implementation of this method is based on:
* <ul>
* <li><a href="http://mathworld.wolfram.com/GammaFunction.html">
@ -188,7 +179,6 @@ public class Gamma {
* the computation of the convergent Lanczos complex Gamma approximation
* </a></li>
* </ul>
* </p>
*
* @param x ???
* @return log(&#915;(x))