From e6fe53fdae66b16ed0f0d32d68b75e62925c4c71 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 23 Feb 2015 23:03:35 +0100 Subject: [PATCH] Remove deprecated classes and methods. --- .../integration/LegendreGaussIntegrator.java | 265 ------------------ .../math4/distribution/GammaDistribution.java | 24 -- .../math4/linear/EigenDecomposition.java | 35 --- .../apache/commons/math4/special/Beta.java | 28 -- .../commons/math4/util/ArithmeticUtils.java | 183 ------------ .../LegendreGaussIntegratorTest.java | 154 ---------- .../distribution/GammaDistributionTest.java | 4 +- 7 files changed, 2 insertions(+), 691 deletions(-) delete mode 100644 src/main/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegrator.java delete mode 100644 src/test/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegratorTest.java diff --git a/src/main/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegrator.java b/src/main/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegrator.java deleted file mode 100644 index 94d33253d..000000000 --- a/src/main/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegrator.java +++ /dev/null @@ -1,265 +0,0 @@ -/* - * 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.math4.analysis.integration; - -import org.apache.commons.math4.exception.MathIllegalArgumentException; -import org.apache.commons.math4.exception.MaxCountExceededException; -import org.apache.commons.math4.exception.NotStrictlyPositiveException; -import org.apache.commons.math4.exception.NumberIsTooSmallException; -import org.apache.commons.math4.exception.TooManyEvaluationsException; -import org.apache.commons.math4.exception.util.LocalizedFormats; -import org.apache.commons.math4.util.FastMath; - -/** - * Implements the - * Legendre-Gauss quadrature formula. - *

- * Legendre-Gauss integrators are efficient integrators that can - * accurately integrate functions with few function evaluations. A - * Legendre-Gauss integrator using an n-points quadrature formula can - * integrate 2n-1 degree polynomials exactly. - *

- *

- * These integrators evaluate the function on n carefully chosen - * abscissas in each step interval (mapped to the canonical [-1,1] interval). - * The evaluation abscissas are not evenly spaced and none of them are - * at the interval endpoints. This implies the function integrated can be - * undefined at integration interval endpoints. - *

- *

- * The evaluation abscissas xi are the roots of the degree n - * Legendre polynomial. The weights ai of the quadrature formula - * integrals from -1 to +1 ∫ Li2 where Li (x) = - * ∏ (x-xk)/(xi-xk) for k != i. - *

- *

- * @since 1.2 - * @deprecated As of 3.1 (to be removed in 4.0). Please use - * {@link IterativeLegendreGaussIntegrator} instead. - */ -@Deprecated -public class LegendreGaussIntegrator extends BaseAbstractUnivariateIntegrator { - - /** Abscissas for the 2 points method. */ - private static final double[] ABSCISSAS_2 = { - -1.0 / FastMath.sqrt(3.0), - 1.0 / FastMath.sqrt(3.0) - }; - - /** Weights for the 2 points method. */ - private static final double[] WEIGHTS_2 = { - 1.0, - 1.0 - }; - - /** Abscissas for the 3 points method. */ - private static final double[] ABSCISSAS_3 = { - -FastMath.sqrt(0.6), - 0.0, - FastMath.sqrt(0.6) - }; - - /** Weights for the 3 points method. */ - private static final double[] WEIGHTS_3 = { - 5.0 / 9.0, - 8.0 / 9.0, - 5.0 / 9.0 - }; - - /** Abscissas for the 4 points method. */ - private static final double[] ABSCISSAS_4 = { - -FastMath.sqrt((15.0 + 2.0 * FastMath.sqrt(30.0)) / 35.0), - -FastMath.sqrt((15.0 - 2.0 * FastMath.sqrt(30.0)) / 35.0), - FastMath.sqrt((15.0 - 2.0 * FastMath.sqrt(30.0)) / 35.0), - FastMath.sqrt((15.0 + 2.0 * FastMath.sqrt(30.0)) / 35.0) - }; - - /** Weights for the 4 points method. */ - private static final double[] WEIGHTS_4 = { - (90.0 - 5.0 * FastMath.sqrt(30.0)) / 180.0, - (90.0 + 5.0 * FastMath.sqrt(30.0)) / 180.0, - (90.0 + 5.0 * FastMath.sqrt(30.0)) / 180.0, - (90.0 - 5.0 * FastMath.sqrt(30.0)) / 180.0 - }; - - /** Abscissas for the 5 points method. */ - private static final double[] ABSCISSAS_5 = { - -FastMath.sqrt((35.0 + 2.0 * FastMath.sqrt(70.0)) / 63.0), - -FastMath.sqrt((35.0 - 2.0 * FastMath.sqrt(70.0)) / 63.0), - 0.0, - FastMath.sqrt((35.0 - 2.0 * FastMath.sqrt(70.0)) / 63.0), - FastMath.sqrt((35.0 + 2.0 * FastMath.sqrt(70.0)) / 63.0) - }; - - /** Weights for the 5 points method. */ - private static final double[] WEIGHTS_5 = { - (322.0 - 13.0 * FastMath.sqrt(70.0)) / 900.0, - (322.0 + 13.0 * FastMath.sqrt(70.0)) / 900.0, - 128.0 / 225.0, - (322.0 + 13.0 * FastMath.sqrt(70.0)) / 900.0, - (322.0 - 13.0 * FastMath.sqrt(70.0)) / 900.0 - }; - - /** Abscissas for the current method. */ - private final double[] abscissas; - - /** Weights for the current method. */ - private final double[] weights; - - /** - * Build a Legendre-Gauss integrator with given accuracies and iterations counts. - * @param n number of points desired (must be between 2 and 5 inclusive) - * @param relativeAccuracy relative accuracy of the result - * @param absoluteAccuracy absolute accuracy of the result - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * @exception MathIllegalArgumentException if number of points is out of [2; 5] - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - */ - public LegendreGaussIntegrator(final int n, - final double relativeAccuracy, - final double absoluteAccuracy, - final int minimalIterationCount, - final int maximalIterationCount) - throws MathIllegalArgumentException, NotStrictlyPositiveException, NumberIsTooSmallException { - super(relativeAccuracy, absoluteAccuracy, minimalIterationCount, maximalIterationCount); - switch(n) { - case 2 : - abscissas = ABSCISSAS_2; - weights = WEIGHTS_2; - break; - case 3 : - abscissas = ABSCISSAS_3; - weights = WEIGHTS_3; - break; - case 4 : - abscissas = ABSCISSAS_4; - weights = WEIGHTS_4; - break; - case 5 : - abscissas = ABSCISSAS_5; - weights = WEIGHTS_5; - break; - default : - throw new MathIllegalArgumentException( - LocalizedFormats.N_POINTS_GAUSS_LEGENDRE_INTEGRATOR_NOT_SUPPORTED, - n, 2, 5); - } - - } - - /** - * Build a Legendre-Gauss integrator with given accuracies. - * @param n number of points desired (must be between 2 and 5 inclusive) - * @param relativeAccuracy relative accuracy of the result - * @param absoluteAccuracy absolute accuracy of the result - * @exception MathIllegalArgumentException if number of points is out of [2; 5] - */ - public LegendreGaussIntegrator(final int n, - final double relativeAccuracy, - final double absoluteAccuracy) - throws MathIllegalArgumentException { - this(n, relativeAccuracy, absoluteAccuracy, - DEFAULT_MIN_ITERATIONS_COUNT, DEFAULT_MAX_ITERATIONS_COUNT); - } - - /** - * Build a Legendre-Gauss integrator with given iteration counts. - * @param n number of points desired (must be between 2 and 5 inclusive) - * @param minimalIterationCount minimum number of iterations - * @param maximalIterationCount maximum number of iterations - * @exception MathIllegalArgumentException if number of points is out of [2; 5] - * @exception NotStrictlyPositiveException if minimal number of iterations - * is not strictly positive - * @exception NumberIsTooSmallException if maximal number of iterations - * is lesser than or equal to the minimal number of iterations - */ - public LegendreGaussIntegrator(final int n, - final int minimalIterationCount, - final int maximalIterationCount) - throws MathIllegalArgumentException { - this(n, DEFAULT_RELATIVE_ACCURACY, DEFAULT_ABSOLUTE_ACCURACY, - minimalIterationCount, maximalIterationCount); - } - - /** {@inheritDoc} */ - @Override - protected double doIntegrate() - throws MathIllegalArgumentException, TooManyEvaluationsException, MaxCountExceededException { - - // compute first estimate with a single step - double oldt = stage(1); - - int n = 2; - while (true) { - - // improve integral with a larger number of steps - final double t = stage(n); - - // estimate error - final double delta = FastMath.abs(t - oldt); - final double limit = - FastMath.max(getAbsoluteAccuracy(), - getRelativeAccuracy() * (FastMath.abs(oldt) + FastMath.abs(t)) * 0.5); - - // check convergence - if ((iterations.getCount() + 1 >= getMinimalIterationCount()) && (delta <= limit)) { - return t; - } - - // prepare next iteration - double ratio = FastMath.min(4, FastMath.pow(delta / limit, 0.5 / abscissas.length)); - n = FastMath.max((int) (ratio * n), n + 1); - oldt = t; - iterations.incrementCount(); - - } - - } - - /** - * Compute the n-th stage integral. - * @param n number of steps - * @return the value of n-th stage integral - * @throws TooManyEvaluationsException if the maximum number of evaluations - * is exceeded. - */ - private double stage(final int n) - throws TooManyEvaluationsException { - - // set up the step for the current stage - final double step = (getMax() - getMin()) / n; - final double halfStep = step / 2.0; - - // integrate over all elementary steps - double midPoint = getMin() + halfStep; - double sum = 0.0; - for (int i = 0; i < n; ++i) { - for (int j = 0; j < abscissas.length; ++j) { - sum += weights[j] * computeObjectiveValue(midPoint + halfStep * abscissas[j]); - } - midPoint += step; - } - - return halfStep * sum; - - } - -} diff --git a/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java b/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java index 905c92266..daa9ef93d 100644 --- a/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java +++ b/src/main/java/org/apache/commons/math4/distribution/GammaDistribution.java @@ -202,18 +202,6 @@ public class GammaDistribution extends AbstractRealDistribution { this.maxLogY = FastMath.log(Double.MAX_VALUE) / (shape - 1.0); } - /** - * Returns the shape parameter of {@code this} distribution. - * - * @return the shape parameter - * @deprecated as of version 3.1, {@link #getShape()} should be preferred. - * This method will be removed in version 4.0. - */ - @Deprecated - public double getAlpha() { - return shape; - } - /** * Returns the shape parameter of {@code this} distribution. * @@ -224,18 +212,6 @@ public class GammaDistribution extends AbstractRealDistribution { return shape; } - /** - * Returns the scale parameter of {@code this} distribution. - * - * @return the scale parameter - * @deprecated as of version 3.1, {@link #getScale()} should be preferred. - * This method will be removed in version 4.0. - */ - @Deprecated - public double getBeta() { - return scale; - } - /** * Returns the scale parameter of {@code this} distribution. * diff --git a/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java b/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java index 1ae63bf4d..5118a611c 100644 --- a/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java +++ b/src/main/java/org/apache/commons/math4/linear/EigenDecomposition.java @@ -126,24 +126,6 @@ public class EigenDecomposition { } } - /** - * Calculates the eigen decomposition of the given real matrix. - * - * @param matrix Matrix to decompose. - * @param splitTolerance Dummy parameter (present for backward - * compatibility only). - * @throws MathArithmeticException if the decomposition of a general matrix - * results in a matrix with zero norm - * @throws MaxCountExceededException if the algorithm fails to converge. - * @deprecated in 3.1 (to be removed in 4.0) due to unused parameter - */ - @Deprecated - public EigenDecomposition(final RealMatrix matrix, - final double splitTolerance) - throws MathArithmeticException { - this(matrix); - } - /** * Calculates the eigen decomposition of the symmetric tridiagonal * matrix. The Householder matrix is assumed to be the identity matrix. @@ -166,23 +148,6 @@ public class EigenDecomposition { findEigenVectors(z); } - /** - * Calculates the eigen decomposition of the symmetric tridiagonal - * matrix. The Householder matrix is assumed to be the identity matrix. - * - * @param main Main diagonal of the symmetric tridiagonal form. - * @param secondary Secondary of the tridiagonal form. - * @param splitTolerance Dummy parameter (present for backward - * compatibility only). - * @throws MaxCountExceededException if the algorithm fails to converge. - * @deprecated in 3.1 (to be removed in 4.0) due to unused parameter - */ - @Deprecated - public EigenDecomposition(final double[] main, final double[] secondary, - final double splitTolerance) { - this(main, secondary); - } - /** * Gets the matrix V of the decomposition. * V is an orthogonal matrix, i.e. its transpose is also its inverse. diff --git a/src/main/java/org/apache/commons/math4/special/Beta.java b/src/main/java/org/apache/commons/math4/special/Beta.java index 08a0d4607..78612372d 100644 --- a/src/main/java/org/apache/commons/math4/special/Beta.java +++ b/src/main/java/org/apache/commons/math4/special/Beta.java @@ -226,34 +226,6 @@ public class Beta { return ret; } - /** - * Returns the natural logarithm of the beta function B(a, b). - * - * The implementation of this method is based on: - *

- * - * @param a Parameter {@code a}. - * @param b Parameter {@code b}. - * @param epsilon This parameter is ignored. - * @param maxIterations This parameter is ignored. - * @return log(B(a, b)). - * @deprecated as of version 3.1, this method is deprecated as the - * computation of the beta function is no longer iterative; it will be - * removed in version 4.0. Current implementation of this method - * internally calls {@link #logBeta(double, double)}. - */ - @Deprecated - public static double logBeta(double a, double b, - double epsilon, - int maxIterations) { - - return logBeta(a, b); - } - - /** * Returns the value of log Γ(a + b) for 1 ≤ a, b ≤ 2. Based on the * NSWC Library of Mathematics Subroutines double precision diff --git a/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java b/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java index d6262a565..ab799ed8f 100644 --- a/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java +++ b/src/main/java/org/apache/commons/math4/util/ArithmeticUtils.java @@ -20,7 +20,6 @@ import java.math.BigInteger; import org.apache.commons.math4.exception.MathArithmeticException; import org.apache.commons.math4.exception.NotPositiveException; -import org.apache.commons.math4.exception.NumberIsTooLargeException; import org.apache.commons.math4.exception.util.Localizable; import org.apache.commons.math4.exception.util.LocalizedFormats; @@ -68,161 +67,6 @@ public final class ArithmeticUtils { return addAndCheck(a, b, LocalizedFormats.OVERFLOW_IN_ADDITION); } - /** - * Returns an exact representation of the Binomial - * Coefficient, "{@code n choose k}", the number of - * {@code k}-element subsets that can be selected from an - * {@code n}-element set. - *

- * Preconditions: - *

- * - * @param n the size of the set - * @param k the size of the subsets to be counted - * @return {@code n choose k} - * @throws NotPositiveException if {@code n < 0}. - * @throws NumberIsTooLargeException if {@code k > n}. - * @throws MathArithmeticException if the result is too large to be - * represented by a long integer. - * @deprecated use {@link CombinatoricsUtils#binomialCoefficient(int, int)} - */ - @Deprecated - public static long binomialCoefficient(final int n, final int k) - throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { - return CombinatoricsUtils.binomialCoefficient(n, k); - } - - /** - * Returns a {@code double} representation of the Binomial - * Coefficient, "{@code n choose k}", the number of - * {@code k}-element subsets that can be selected from an - * {@code n}-element set. - *

- * Preconditions: - *

- * - * @param n the size of the set - * @param k the size of the subsets to be counted - * @return {@code n choose k} - * @throws NotPositiveException if {@code n < 0}. - * @throws NumberIsTooLargeException if {@code k > n}. - * @throws MathArithmeticException if the result is too large to be - * represented by a long integer. - * @deprecated use {@link CombinatoricsUtils#binomialCoefficientDouble(int, int)} - */ - @Deprecated - public static double binomialCoefficientDouble(final int n, final int k) - throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { - return CombinatoricsUtils.binomialCoefficientDouble(n, k); - } - - /** - * Returns the natural {@code log} of the Binomial - * Coefficient, "{@code n choose k}", the number of - * {@code k}-element subsets that can be selected from an - * {@code n}-element set. - *

- * Preconditions: - *

- * - * @param n the size of the set - * @param k the size of the subsets to be counted - * @return {@code n choose k} - * @throws NotPositiveException if {@code n < 0}. - * @throws NumberIsTooLargeException if {@code k > n}. - * @throws MathArithmeticException if the result is too large to be - * represented by a long integer. - * @deprecated use {@link CombinatoricsUtils#binomialCoefficientLog(int, int)} - */ - @Deprecated - public static double binomialCoefficientLog(final int n, final int k) - throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { - return CombinatoricsUtils.binomialCoefficientLog(n, k); - } - - /** - * Returns n!. Shorthand for {@code n} Factorial, the - * product of the numbers {@code 1,...,n}. - *

- * Preconditions: - *

- *

- * - * @param n argument - * @return {@code n!} - * @throws MathArithmeticException if the result is too large to be represented - * by a {@code long}. - * @throws NotPositiveException if {@code n < 0}. - * @throws MathArithmeticException if {@code n > 20}: The factorial value is too - * large to fit in a {@code long}. - * @deprecated use {@link CombinatoricsUtils#factorial(int)} - */ - @Deprecated - public static long factorial(final int n) throws NotPositiveException, MathArithmeticException { - return CombinatoricsUtils.factorial(n); - } - - /** - * Compute n!, the - * factorial of {@code n} (the product of the numbers 1 to n), as a - * {@code double}. - * The result should be small enough to fit into a {@code double}: The - * largest {@code n} for which {@code n! < Double.MAX_VALUE} is 170. - * If the computed value exceeds {@code Double.MAX_VALUE}, - * {@code Double.POSITIVE_INFINITY} is returned. - * - * @param n Argument. - * @return {@code n!} - * @throws NotPositiveException if {@code n < 0}. - * @deprecated use {@link CombinatoricsUtils#factorialDouble(int)} - */ - @Deprecated - public static double factorialDouble(final int n) throws NotPositiveException { - return CombinatoricsUtils.factorialDouble(n); - } - - /** - * Compute the natural logarithm of the factorial of {@code n}. - * - * @param n Argument. - * @return {@code n!} - * @throws NotPositiveException if {@code n < 0}. - * @deprecated use {@link CombinatoricsUtils#factorialLog(int)} - */ - @Deprecated - public static double factorialLog(final int n) throws NotPositiveException { - return CombinatoricsUtils.factorialLog(n); - } - /** * Computes the greatest common divisor of the absolute value of two * numbers, using a modified version of the "binary gcd" method. @@ -793,33 +637,6 @@ public final class ArithmeticUtils { return result; } - /** - * Returns the - * Stirling number of the second kind, "{@code S(n,k)}", the number of - * ways of partitioning an {@code n}-element set into {@code k} non-empty - * subsets. - *

- * The preconditions are {@code 0 <= k <= n } (otherwise - * {@code NotPositiveException} is thrown) - *

- * @param n the size of the set - * @param k the number of non-empty subsets - * @return {@code S(n,k)} - * @throws NotPositiveException if {@code k < 0}. - * @throws NumberIsTooLargeException if {@code k > n}. - * @throws MathArithmeticException if some overflow happens, typically for n exceeding 25 and - * k between 20 and n-2 (S(n,n-1) is handled specifically and does not overflow) - * @since 3.1 - * @deprecated use {@link CombinatoricsUtils#stirlingS2(int, int)} - */ - @Deprecated - public static long stirlingS2(final int n, final int k) - throws NotPositiveException, NumberIsTooLargeException, MathArithmeticException { - return CombinatoricsUtils.stirlingS2(n, k); - - } - /** * Add two long integers, checking for overflow. * diff --git a/src/test/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegratorTest.java b/src/test/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegratorTest.java deleted file mode 100644 index f0b8af00a..000000000 --- a/src/test/java/org/apache/commons/math4/analysis/integration/LegendreGaussIntegratorTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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.math4.analysis.integration; - -import java.util.Random; - -import org.apache.commons.math4.analysis.QuinticFunction; -import org.apache.commons.math4.analysis.UnivariateFunction; -import org.apache.commons.math4.analysis.function.Sin; -import org.apache.commons.math4.analysis.integration.BaseAbstractUnivariateIntegrator; -import org.apache.commons.math4.analysis.integration.LegendreGaussIntegrator; -import org.apache.commons.math4.analysis.integration.UnivariateIntegrator; -import org.apache.commons.math4.analysis.polynomials.PolynomialFunction; -import org.apache.commons.math4.exception.TooManyEvaluationsException; -import org.apache.commons.math4.util.FastMath; -import org.junit.Assert; -import org.junit.Test; - - -@Deprecated -public class LegendreGaussIntegratorTest { - - @Test - public void testSinFunction() { - UnivariateFunction f = new Sin(); - BaseAbstractUnivariateIntegrator integrator = new LegendreGaussIntegrator(5, 1.0e-14, 1.0e-10, 2, 15); - double min, max, expected, result, tolerance; - - min = 0; max = FastMath.PI; expected = 2; - tolerance = FastMath.max(integrator.getAbsoluteAccuracy(), - FastMath.abs(expected * integrator.getRelativeAccuracy())); - result = integrator.integrate(10000, f, min, max); - Assert.assertEquals(expected, result, tolerance); - - min = -FastMath.PI/3; max = 0; expected = -0.5; - tolerance = FastMath.max(integrator.getAbsoluteAccuracy(), - FastMath.abs(expected * integrator.getRelativeAccuracy())); - result = integrator.integrate(10000, f, min, max); - Assert.assertEquals(expected, result, tolerance); - } - - @Test - public void testQuinticFunction() { - UnivariateFunction f = new QuinticFunction(); - UnivariateIntegrator integrator = - new LegendreGaussIntegrator(3, - BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY, - BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY, - BaseAbstractUnivariateIntegrator.DEFAULT_MIN_ITERATIONS_COUNT, - 64); - double min, max, expected, result; - - min = 0; max = 1; expected = -1.0/48; - result = integrator.integrate(10000, f, min, max); - Assert.assertEquals(expected, result, 1.0e-16); - - min = 0; max = 0.5; expected = 11.0/768; - result = integrator.integrate(10000, f, min, max); - Assert.assertEquals(expected, result, 1.0e-16); - - min = -1; max = 4; expected = 2048/3.0 - 78 + 1.0/48; - result = integrator.integrate(10000, f, min, max); - Assert.assertEquals(expected, result, 1.0e-16); - } - - @Test - public void testExactIntegration() { - Random random = new Random(86343623467878363l); - for (int n = 2; n < 6; ++n) { - LegendreGaussIntegrator integrator = - new LegendreGaussIntegrator(n, - BaseAbstractUnivariateIntegrator.DEFAULT_RELATIVE_ACCURACY, - BaseAbstractUnivariateIntegrator.DEFAULT_ABSOLUTE_ACCURACY, - BaseAbstractUnivariateIntegrator.DEFAULT_MIN_ITERATIONS_COUNT, - 64); - - // an n points Gauss-Legendre integrator integrates 2n-1 degree polynoms exactly - for (int degree = 0; degree <= 2 * n - 1; ++degree) { - for (int i = 0; i < 10; ++i) { - double[] coeff = new double[degree + 1]; - for (int k = 0; k < coeff.length; ++k) { - coeff[k] = 2 * random.nextDouble() - 1; - } - PolynomialFunction p = new PolynomialFunction(coeff); - double result = integrator.integrate(10000, p, -5.0, 15.0); - double reference = exactIntegration(p, -5.0, 15.0); - Assert.assertEquals(n + " " + degree + " " + i, reference, result, 1.0e-12 * (1.0 + FastMath.abs(reference))); - } - } - - } - } - - @Test - public void testIssue464() { - final double value = 0.2; - UnivariateFunction f = new UnivariateFunction() { - public double value(double x) { - return (x >= 0 && x <= 5) ? value : 0.0; - } - }; - LegendreGaussIntegrator gauss = new LegendreGaussIntegrator(5, 3, 100); - - // due to the discontinuity, integration implies *many* calls - double maxX = 0.32462367623786328; - Assert.assertEquals(maxX * value, gauss.integrate(Integer.MAX_VALUE, f, -10, maxX), 1.0e-7); - Assert.assertTrue(gauss.getEvaluations() > 37000000); - Assert.assertTrue(gauss.getIterations() < 30); - - // setting up limits prevents such large number of calls - try { - gauss.integrate(1000, f, -10, maxX); - Assert.fail("expected TooManyEvaluationsException"); - } catch (TooManyEvaluationsException tmee) { - // expected - Assert.assertEquals(1000, tmee.getMax()); - } - - // integrating on the two sides should be simpler - double sum1 = gauss.integrate(1000, f, -10, 0); - int eval1 = gauss.getEvaluations(); - double sum2 = gauss.integrate(1000, f, 0, maxX); - int eval2 = gauss.getEvaluations(); - Assert.assertEquals(maxX * value, sum1 + sum2, 1.0e-7); - Assert.assertTrue(eval1 + eval2 < 200); - - } - - private double exactIntegration(PolynomialFunction p, double a, double b) { - final double[] coeffs = p.getCoefficients(); - double yb = coeffs[coeffs.length - 1] / coeffs.length; - double ya = yb; - for (int i = coeffs.length - 2; i >= 0; --i) { - yb = yb * b + coeffs[i] / (i + 1); - ya = ya * a + coeffs[i] / (i + 1); - } - return yb * b - ya * a; - } - -} diff --git a/src/test/java/org/apache/commons/math4/distribution/GammaDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/GammaDistributionTest.java index c217b9c0c..6945e3f63 100644 --- a/src/test/java/org/apache/commons/math4/distribution/GammaDistributionTest.java +++ b/src/test/java/org/apache/commons/math4/distribution/GammaDistributionTest.java @@ -78,8 +78,8 @@ public class GammaDistributionTest extends RealDistributionAbstractTest { @Test public void testParameterAccessors() { GammaDistribution distribution = (GammaDistribution) getDistribution(); - Assert.assertEquals(4d, distribution.getAlpha(), 0); - Assert.assertEquals(2d, distribution.getBeta(), 0); + Assert.assertEquals(4d, distribution.getShape(), 0); + Assert.assertEquals(2d, distribution.getScale(), 0); } @Test