From d23bf18b40bc7f731498acd042f6d0c0800a9290 Mon Sep 17 00:00:00 2001 From: Tim O'Brien Date: Mon, 2 Jun 2003 03:44:13 +0000 Subject: [PATCH] Licensing issues have prompted the removal of all source reliant on Gamma.java. Gamma.java explicitly stated that it was "based on" an implementation from Numerical Recipes in C. Please see http://www.nr.com/infotop.html - these implementations (and derivatives of these works) are covered under restrictive licensing terms. This code will be removed from the repository until these issues can be addressed. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@140875 13f79535-47bb-0310-9956-ffa450edef68 --- .../distribution/ChiSquaredDistribution.java | 77 -------- .../ChiSquaredDistributionImpl.java | 100 ---------- .../distribution/DistributionFactory.java | 108 ----------- .../distribution/DistributionFactoryImpl.java | 93 --------- .../math/distribution/GammaDistribution.java | 89 --------- .../distribution/GammaDistributionImpl.java | 166 ---------------- .../apache/commons/math/special/Gamma.java | 180 ----------------- .../ChiSquareDistributionTest.java | 129 ------------ .../DistributionFactoryImplTest.java | 183 ------------------ .../distribution/GammaDistributionTest.java | 81 -------- 10 files changed, 1206 deletions(-) delete mode 100644 src/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java delete mode 100644 src/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java delete mode 100644 src/java/org/apache/commons/math/distribution/DistributionFactory.java delete mode 100644 src/java/org/apache/commons/math/distribution/DistributionFactoryImpl.java delete mode 100644 src/java/org/apache/commons/math/distribution/GammaDistribution.java delete mode 100644 src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java delete mode 100644 src/java/org/apache/commons/math/special/Gamma.java delete mode 100644 src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java delete mode 100644 src/test/org/apache/commons/math/distribution/DistributionFactoryImplTest.java delete mode 100644 src/test/org/apache/commons/math/distribution/GammaDistributionTest.java diff --git a/src/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java b/src/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java deleted file mode 100644 index e8c1aa0a5..000000000 --- a/src/java/org/apache/commons/math/distribution/ChiSquaredDistribution.java +++ /dev/null @@ -1,77 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -/** - * The Chi-Squared Distribution defined by - * http://mathworld.wolfram.com/Chi-SquaredDistribution.html. - * - * Instances of ChiSquaredDistribution objects should be created using - * {@link DistributionFactory#createChiSquareDistribution(double)} - * - * @author Brent Worden - */ -public interface ChiSquaredDistribution extends ContinuousDistribution { - /** - * Modify the degrees of freedom. - * @param degreesOfFreedom the new degrees of freedom. - */ - void setDegreesOfFreedom(double degreesOfFreedom); - - /** - * Access the degrees of freedom. - * @return the degrees of freedom. - */ - double getDegreesOfFreedom(); -} \ No newline at end of file diff --git a/src/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java b/src/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java deleted file mode 100644 index 6c62d5a76..000000000 --- a/src/java/org/apache/commons/math/distribution/ChiSquaredDistributionImpl.java +++ /dev/null @@ -1,100 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -/** - * @author Brent Worden - */ -public class ChiSquaredDistributionImpl - extends AbstractContinuousDistribution - implements ChiSquaredDistribution { - - private GammaDistribution gamma; - - public ChiSquaredDistributionImpl(double degreesOfFreedom){ - super(); - setGamma(DistributionFactory.newInstance().createGammaDistribution(degreesOfFreedom / 2.0, 2.0)); - } - public void setDegreesOfFreedom(double degreesOfFreedom) { - getGamma().setAlpha(degreesOfFreedom / 2.0); - } - - public double getDegreesOfFreedom() { - return getGamma().getAlpha() * 2.0; - } - - public double cummulativeProbability(double x) { - return getGamma().cummulativeProbability(x); - } - - public double getDomainLowerBound() { - return Double.MIN_VALUE * getGamma().getBeta(); - } - - public double getDomainUpperBound() { - return Double.MAX_VALUE; - } - - public double getMean() { - return getDegreesOfFreedom(); - } - - private void setGamma(GammaDistribution gamma) { - this.gamma = gamma; - } - - private GammaDistribution getGamma() { - return gamma; - } -} diff --git a/src/java/org/apache/commons/math/distribution/DistributionFactory.java b/src/java/org/apache/commons/math/distribution/DistributionFactory.java deleted file mode 100644 index 8d40b16db..000000000 --- a/src/java/org/apache/commons/math/distribution/DistributionFactory.java +++ /dev/null @@ -1,108 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -/** - * This factory provids the means to create common statistical distributions. - * The following distributions are supported:
    - *
  • Chi-Square
  • - *
  • Gamma
  • - *
- * - * Common usage:
- * DistributionFactory factory = DistributionFactory.newInstance();
- * 
- * // create a Chi-Square distribution with 5 degrees of freedom.
- * ChiSquaredDistribution chi = factory.createChiSquareDistribution(5.0);
- * 
- * - * @author Brent Worden - */ -public abstract class DistributionFactory { - /** - * Default constructor. - */ - protected DistributionFactory() { - super(); - } - - /** - * Create an instance of a DistributionFactory - * @return a new factory. - */ - public static DistributionFactory newInstance() { - // for now, return the only concrete factory. - // later, allow for a plugable implementation, possible using SPI and - // commons-discovery. - return new DistributionFactoryImpl(); - } - - /** - * Create a new chi-square distribution with the given degrees of freedom. - * @param degreesOfFreedom degrees of freedom. - * @return a new chi-square distribution. - */ - public abstract ChiSquaredDistribution createChiSquareDistribution( - double degreesOfFreedom - ); - - /** - * Create a new gamma distribution with the given alpha and beta values. - * @param alpha the shape parameter. - * @param beta the scale parameter. - * @return a new gamma distribution. - */ - public abstract GammaDistribution createGammaDistribution( - double alpha, double beta); -} diff --git a/src/java/org/apache/commons/math/distribution/DistributionFactoryImpl.java b/src/java/org/apache/commons/math/distribution/DistributionFactoryImpl.java deleted file mode 100644 index c265205ee..000000000 --- a/src/java/org/apache/commons/math/distribution/DistributionFactoryImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - - -/** - * A concrete distribution factory. This is the default factory used by - * Commons-Math. - * - * @author Brent Worden - */ -public class DistributionFactoryImpl extends DistributionFactory { - /** - * Default constructor. Package scope to prevent unwanted instantiation. - */ - DistributionFactoryImpl() { - super(); - } - - /** - * Create a new chi-square distribution with the given degrees of freedom. - * @param degreesOfFreedom degrees of freedom. - * @return a new chi-square distribution. - */ - public ChiSquaredDistribution createChiSquareDistribution( - final double degreesOfFreedom) { - - return new ChiSquaredDistributionImpl(degreesOfFreedom); - } - - /** - * Create a new gamma distribution the given alpha and beta values. - * @param alpha the shape parameter. - * @param beta the scale parameter. - * @return a new gamma distribution. - */ - public GammaDistribution createGammaDistribution( - double alpha, double beta) { - - return new GammaDistributionImpl(alpha, beta); - } -} diff --git a/src/java/org/apache/commons/math/distribution/GammaDistribution.java b/src/java/org/apache/commons/math/distribution/GammaDistribution.java deleted file mode 100644 index 20fa02f67..000000000 --- a/src/java/org/apache/commons/math/distribution/GammaDistribution.java +++ /dev/null @@ -1,89 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -/** - * The Gamma Distribution defined by - * http://mathworld.wolfram.com/GammaDistribution.html. - * - * Instances of GammaDistribution objects should be created using - * {@link DistributionFactory#createGammaDistribution(double, double)} - * - * @author Brent Worden - */ -public interface GammaDistribution extends ContinuousDistribution { - /** - * Modify the shape parameter, alpha. - * @param alpha the new shape parameter. - */ - void setAlpha(double alpha); - - /** - * Access the shape parameter, alpha - * @return alpha. - */ - double getAlpha(); - - /** - * Modify the scale parameter, beta. - * @param beta the new scale parameter. - */ - void setBeta(double beta); - - /** - * Access the scale parameter, beta - * @return beta. - */ - double getBeta(); -} diff --git a/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java b/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java deleted file mode 100644 index b93a5239e..000000000 --- a/src/java/org/apache/commons/math/distribution/GammaDistributionImpl.java +++ /dev/null @@ -1,166 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -import org.apache.commons.math.special.Gamma; - -/** - * The Gamma Distribution defined by - * http://mathworld.wolfram.com/GammaDistribution.html. - *
- * Along with the Gamma Distribution, this class can be used as a Chi-Squared - * Distribution defined by - * http://mathworld.wolfram.com/Chi-SquaredDistribution.html - * - * @author Brent Worden - */ -public class GammaDistributionImpl extends AbstractContinuousDistribution - implements GammaDistribution { - - /** The shape parameter. */ - private double alpha; - - /** The scale parameter. */ - private double beta; - - /** - * Create a new gamma distribution with the given alpha and beta values. - * @param alpha the shape parameter. - * @param beta the scale parameter. - */ - public GammaDistributionImpl(double alpha, double beta) { - super(); - setAlpha(alpha); - setBeta(beta); - } - - /** - * For this disbution, X, this method returns P(X < x). This - * implementation is based on the formulas found in Abramowitz and Stegun, - * "Handbook of Mathematical Functions." - * @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) { - ret = 0.0; - } else { - ret = Gamma.regularizedGammaP(getAlpha(), x / getBeta()); - } - - return ret; - } - - /** - * Modify the shape parameter, alpha. - * @param alpha the new shape parameter. - */ - public void setAlpha(double alpha) { - if (alpha <= 0.0) { - throw new IllegalArgumentException("alpha must be positive"); - } - this.alpha = alpha; - } - - /** - * Access the shape parameter, alpha - * @return alpha. - */ - public double getAlpha() { - return alpha; - } - - /** - * Modify the scale parameter, beta. - * @param beta the new scale parameter. - */ - public void setBeta(double beta) { - if (beta <= 0.0) { - throw new IllegalArgumentException("beta must be positive"); - } - this.beta = beta; - } - - /** - * Access the scale parameter, beta - * @return beta. - */ - public double getBeta() { - return beta; - } - - /** - * @return - */ - public double getDomainLowerBound() { - return Double.MIN_VALUE; - } - - /** - * @return - */ - public double getDomainUpperBound() { - return Double.MAX_VALUE; - } - - /** - * @return - */ - public double getMean() { - return getAlpha() * getBeta(); - } - -} diff --git a/src/java/org/apache/commons/math/special/Gamma.java b/src/java/org/apache/commons/math/special/Gamma.java deleted file mode 100644 index df60af0f5..000000000 --- a/src/java/org/apache/commons/math/special/Gamma.java +++ /dev/null @@ -1,180 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.special; - -import org.apache.commons.math.ConvergenceException; - -/** - * This is a utility class that provides computation methods related to the - * Gamma family of functions. - * - * @author Brent Worden - */ -public class Gamma { - /** Maximum number of iteration allowed for iterative methods. */ - private static final int MAXIMUM_ITERATIONS = 100; - - /** Maximum allowed numerical error. */ - private static final double EPSILON = 10e-9; - - /** - * Default constructor. Prohibit instantiation. - */ - private Gamma() { - super(); - } - - /** - * Returns the regularized gamma function P(a, x) defined by - * http://mathworld.wolfram.com/RegularizedGammaFunction.html. - * - * This implementation is based on the formulas and descriptions presented - * in Press, et. al. "Numerical Recipes in C." This implementation uses - * the series representation of the regularized gamma function for all - * values a and x. Later on, this method can be improved upon for certain - * values of a and x using continuous fractions as the series converges - * slowly for x >> a. - * - * @param a ??? - * @param x ??? - * @return the regularized gamma function P(a, x) - */ - public static double regularizedGammaP(double a, double x) { - double ret; - - if (a <= 0.0) { - throw new IllegalArgumentException("a must be positive"); - } else if (x <= 0.0) { - throw new IllegalArgumentException("x must be non-negative"); - } else { - // calculate series - double n = 0.0; // current element index - double an = 1.0 / a; // n-th element in the series - double sum = an; // partial sum - while (Math.abs(an) > EPSILON && n < MAXIMUM_ITERATIONS) { - // compute next element in the series - n = n + 1.0; - an = an * (x / (a + n)); - - // update partial sum - sum = sum + an; - } - if (n >= MAXIMUM_ITERATIONS) { - throw new ConvergenceException( - "maximum number of iterations reached"); - } else { - ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * sum; - } - } - - return ret; - } - - /** - * Returns the natural logarithm of the gamma function Γ(x) defined - * by http://mathworld.wolfram.com/GammaFunction.html - * - * This implementation is based on the formulas and descriptions presented - * in Press, et. al. "Numerical Recipes in C" and the Lanczos coefficient - * research conducted by Paul Godfrey. - * - * @param x ??? - * @return log(Γ(x)) - */ - public static double logGamma(double x) { - double ret; - - if (x <= 0.0) { - throw new IllegalArgumentException( - "x must be non-negative"); - } else { - double g = 607.0 / 128.0; - - // Lanczos coefficients - double[] c = - { - 0.99999999999999709182, - 57.156235665862923517, - -59.597960355475491248, - 14.136097974741747174, - -0.49191381609762019978, - .33994649984811888699e-4, - .46523628927048575665e-4, - -.98374475304879564677e-4, - .15808870322491248884e-3, - -.21026444172410488319e-3, - .21743961811521264320e-3, - -.16431810653676389022e-3, - .84418223983852743293e-4, - -.26190838401581408670e-4, - .36899182659531622704e-5, - }; - - double sum = 0.0; - for (int i = 1; i < c.length; ++i) { - sum = sum + (c[i] / (x + i)); - } - sum = sum + c[0]; - - double tmp = x + g + .5; - ret = - (x + .5) * Math.log(tmp) - - tmp - + (.5 * Math.log(2.0 * Math.PI)) - + Math.log(sum / x); - } - - return ret; - } -} diff --git a/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java b/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java deleted file mode 100644 index 40b553b88..000000000 --- a/src/test/org/apache/commons/math/distribution/ChiSquareDistributionTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -import junit.framework.TestCase; - -/** - * @author Brent Worden - */ -public class ChiSquareDistributionTest extends TestCase { - private ChiSquaredDistribution chiSquare; - - /** - * Constructor for ChiSquareDistributionTest. - * @param name - */ - public ChiSquareDistributionTest(String name) { - super(name); - } - - /* - * @see TestCase#setUp() - */ - protected void setUp() throws Exception { - super.setUp(); - chiSquare = DistributionFactory.newInstance().createChiSquareDistribution(5.0); - } - - /* - * @see TestCase#tearDown() - */ - protected void tearDown() throws Exception { - chiSquare = null; - super.tearDown(); - } - - public void testLowerTailProbability(){ - testProbability( .210, .001); - testProbability( .554, .010); - testProbability( .831, .025); - testProbability(1.145, .050); - testProbability(1.610, .100); - } - - public void testUpperTailProbability(){ - testProbability(20.515, .999); - testProbability(15.086, .990); - testProbability(12.833, .975); - testProbability(11.070, .950); - testProbability( 9.236, .900); - } - - public void testLowerTailValues(){ - testValue(.001, .210); - testValue(.010, .554); - testValue(.025, .831); - testValue(.050, 1.145); - testValue(.100, 1.610); - } - - public void testUpperTailValues(){ - testValue(.999, 20.515); - testValue(.990, 15.086); - testValue(.975, 12.833); - testValue(.950, 11.070); - testValue(.900, 9.236); - } - - private void testProbability(double x, double expected){ - double actual = chiSquare.cummulativeProbability(x); - assertEquals("probability for " + x, expected, actual, 10e-4); - } - - private void testValue(double p, double expected){ - double actual = chiSquare.inverseCummulativeProbability(p); - assertEquals("value for " + p, expected, actual, 10e-4); - } -} diff --git a/src/test/org/apache/commons/math/distribution/DistributionFactoryImplTest.java b/src/test/org/apache/commons/math/distribution/DistributionFactoryImplTest.java deleted file mode 100644 index 5b09492d7..000000000 --- a/src/test/org/apache/commons/math/distribution/DistributionFactoryImplTest.java +++ /dev/null @@ -1,183 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -import junit.framework.TestCase; - -/** - * @author Brent Worden - */ -public class DistributionFactoryImplTest extends TestCase { - /** */ - private DistributionFactory factory; - - /** - * Constructor for DistributionFactoryImplTest. - * @param name - */ - public DistributionFactoryImplTest(String name) { - super(name); - } - /** - * @throws java.lang.Exception - */ - protected void setUp() throws Exception { - super.setUp(); - factory = new DistributionFactoryImpl(); - } - - /** - * @throws java.lang.Exception - */ - protected void tearDown() throws Exception { - factory = null; - super.tearDown(); - } - - public void testCreateChiSquareDistributionNegative(){ - try { - factory.createChiSquareDistribution(-1.0); - fail("negative degrees of freedom. IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - ; - } - } - - public void testCreateChiSquareDistributionZero(){ - try { - factory.createChiSquareDistribution(0.0); - fail("zero degrees of freedom. IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - ; - } - } - - public void testCreateChiSquareDistributionPositive(){ - try { - factory.createChiSquareDistribution(1.0); - } catch (IllegalArgumentException ex) { - fail("positive degrees of freedom. IllegalArgumentException is not expected"); - } - } - - public void testCreateGammaDistributionNegativePositive(){ - try { - factory.createGammaDistribution(-1.0, 1.0); - fail("negative alpha. IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - ; - } - } - - public void testCreateGammaDistributionZeroPositive(){ - try { - factory.createGammaDistribution(0.0, 1.0); - fail("zero alpha. IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - ; - } - } - - public void testCreateGammaDistributionPositiveNegative(){ - try { - factory.createGammaDistribution(1.0, -1.0); - fail("negative beta. IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - ; - } - } - - public void testCreateGammaDistributionPositiveZero(){ - try { - factory.createGammaDistribution(1.0, 0.0); - fail("zero beta. IllegalArgumentException expected"); - } catch (IllegalArgumentException ex) { - ; - } - } - - public void testCreateGammaDistributionPositivePositive(){ - try { - factory.createGammaDistribution(1.0, 1.0); - } catch (IllegalArgumentException ex) { - fail("positive alpah and beta. IllegalArgumentException is not expected"); - } - } -// -// public void testCreateTDistributionNegative(){ -// try { -// factory.createTDistribution(-1.0); -// fail("negative degrees of freedom. IllegalArgumentException expected"); -// } catch (IllegalArgumentException ex) { -// ; -// } -// } -// -// public void testCreateTDistributionZero(){ -// try { -// factory.createTDistribution(0.0); -// fail("zero degrees of freedom. IllegalArgumentException expected"); -// } catch (IllegalArgumentException ex) { -// ; -// } -// } -// -// public void testCreateTDistributionPositive(){ -// try { -// factory.createTDistribution(1.0); -// } catch (IllegalArgumentException ex) { -// fail("positive degrees of freedom. IllegalArgumentException is not expected"); -// } -// } -} diff --git a/src/test/org/apache/commons/math/distribution/GammaDistributionTest.java b/src/test/org/apache/commons/math/distribution/GammaDistributionTest.java deleted file mode 100644 index 860a5d307..000000000 --- a/src/test/org/apache/commons/math/distribution/GammaDistributionTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* ==================================================================== - * 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 - * . - */ -package org.apache.commons.math.stat.distribution; - -import junit.framework.TestCase; - -/** - * @author Brent Worden - */ -public class GammaDistributionTest extends TestCase { - /** - * Constructor for ChiSquareDistributionTest. - * @param name - */ - public GammaDistributionTest(String name) { - super(name); - } - - public void testProbabilities(){ - testProbability(15.5, 4.0, 2.0, .9499); - testProbability( 0.5, 4.0, 1.0, .0018); - testProbability(10.0, 1.0, 2.0, .9933); - testProbability( 5.0, 2.0, 2.0, .7127); - } - - private void testProbability(double x, double a, double b, double expected){ - double actual = DistributionFactory.newInstance().createGammaDistribution(a, b).cummulativeProbability(x); - assertEquals("probability for " + x, expected, actual, 10e-4); - } -}