tobrien 2003/07/30 14:58:11 Modified: math project.xml math/src/java/org/apache/commons/math MathConfigurationException.java math/src/java/org/apache/commons/math/analysis SplineInterpolator.java UnivariateRealFunction.java UnivariateRealSolverFactory.java math/src/java/org/apache/commons/math/linear RealMatrixImpl.java math/src/java/org/apache/commons/math/special Beta.java Gamma.java math/src/java/org/apache/commons/math/stat/distribution AbstractContinuousDistribution.java DistributionFactory.java math/src/java/org/apache/commons/math/stat/univariate AbstractStorelessUnivariateStatistic.java math/src/test/org/apache/commons/math/analysis RealSolverTest.java math/src/test/org/apache/commons/math/stat BeanListUnivariateImplTest.java Log: Bugzilla #22002: applied Brent W's patch which dealt with URSFactory and URSFImpl as well as numerous improvements to javadoc Revision Changes Path 1.23 +1 -1 jakarta-commons-sandbox/math/project.xml Index: project.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/project.xml,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- project.xml 9 Jul 2003 20:08:00 -0000 1.22 +++ project.xml 30 Jul 2003 21:58:10 -0000 1.23 @@ -118,7 +118,7 @@ <report>maven-license-plugin</report> <!-- <report>maven-linkcheck-plugin</report> --> <report>maven-statcvs-plugin</report> -<!-- <report>maven-tasklist-plugin</report> --> + <report>maven-tasklist-plugin</report> </reports> </project> 1.5 +5 -3 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/MathConfigurationException.java Index: MathConfigurationException.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/MathConfigurationException.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MathConfigurationException.java 9 Jul 2003 20:02:44 -0000 1.4 +++ MathConfigurationException.java 30 Jul 2003 21:58:10 -0000 1.5 @@ -61,13 +61,14 @@ public class MathConfigurationException extends MathException { /** - * + * Default constructor. */ public MathConfigurationException() { super(); } /** + * Construct an exception with the given message. * @param message message describing the problem */ public MathConfigurationException(String message) { @@ -75,6 +76,7 @@ } /** + * Construct an exception with the given message and root cause. * @param message message describing the problem * @param throwable caught exception causing this problem */ @@ -83,10 +85,10 @@ } /** + * Construct an exception with the given root cause. * @param throwable caught exception causing this problem */ public MathConfigurationException(Throwable throwable) { super(throwable); } - } 1.3 +25 -25 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/SplineInterpolator.java Index: SplineInterpolator.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/SplineInterpolator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SplineInterpolator.java 9 Jul 2003 20:02:43 -0000 1.2 +++ SplineInterpolator.java 30 Jul 2003 21:58:10 -0000 1.3 @@ -60,25 +60,31 @@ * */ public class SplineInterpolator implements UnivariateRealInterpolator { - private double[][] c = null ; + private double[][] c = null; - /* (non-Javadoc) - * @see org.apache.commons.math.UnivariateRealInterpolator#interpolate(double[], double[]) + /** + * Computes an interpolating function for the data set. + * @param xval the arguments for the interpolation points + * @param yval the values for the interpolation points + * @return a function which interpolates the data set + * @throws MathException if arguments violate assumptions made by the + * interpolationg algorithm */ public UnivariateRealFunction interpolate(double[] xval, double[] yval) { if (xval.length != yval.length) { - throw new IllegalArgumentException("Dataset arrays must have same length."); + throw new IllegalArgumentException( + "Dataset arrays must have same length."); } - if ( c == null ) - { + if (c == null) { // Number of intervals. The number of data points is N+1. int n = xval.length - 1; // Check whether the xval vector has ascending values. // Separation should be checked too (not implemented: which criteria?). for (int i = 0; i < n; i++) { - if (xval[i]>=xval[i+1]) { - throw new IllegalArgumentException("Dataset must specify sorted, ascending x values."); + if (xval[i] >= xval[i + 1]) { + throw new IllegalArgumentException( + "Dataset must specify sorted, ascending x values."); } } // Vectors for the equation system. There are n-1 equations for the unknowns s[i] (1<=i<=N-1), @@ -104,10 +110,9 @@ // (yval[i + 2] - yval[i + 1]) / (xval[i + 2] - xval[i + 1]) // take it from the previous loop pass. Note: the interesting part of performance // loss is the range check in the array access, not the computation itself. - b[i] = - 6.0 - * ((yval[i + 2] - yval[i + 1]) / (xval[i + 2] - xval[i + 1]) - - (yval[i + 1] - yval[i]) / (xval[i + 1] - xval[i])); + b[i] = 6.0 * ((yval[i + 2] - yval[i + 1]) / (xval[i + 2] - + xval[i + 1]) - (yval[i + 1] - yval[i]) / (xval[i + 1] - + xval[i])); d[i] = 2.0 * (xval[i + 2] - xval[i]); } // Set up upper and lower diagonal. Keep the offsets in mind. @@ -132,26 +137,21 @@ c = new double[n][4]; c[0][3] = d[0] / (xval[1] - xval[0]) / 6.0; c[0][2] = 0.0; - c[0][1] = - (yval[1] - yval[0]) / (xval[1] - xval[0]) - - d[0] * (xval[1] - xval[0]) / 6.0; + c[0][1] = (yval[1] - yval[0]) / (xval[1] - xval[0]) - d[0] * + (xval[1] - xval[0]) / 6.0; for (int i = 1; i < n - 2; i++) { // TODO: This relies on compiler for CSE of xval[i + 1] - xval[i]. Is this a reasonable assumption? c[i][3] = (d[i] - d[i - 1]) / (xval[i + 1] - xval[i]) / 6.0; c[i][2] = d[i - 1] / 2.0; - c[i][1] = - (yval[i + 1] - yval[i]) / (xval[i + 1] - xval[i]) - - d[i] * (xval[i + 1] - xval[i]) / 6.0 - - d[i - - 1] * (xval[i + 1] - xval[i]) / 3.0; + c[i][1] = (yval[i + 1] - yval[i]) / (xval[i + 1] - xval[i]) - + d[i] * (xval[i + 1] - xval[i]) / 6.0 - d[i - 1] * + (xval[i + 1] - xval[i]) / 3.0; } // TODO: again, CSE aspects. c[n - 1][3] = -d[n - 2] / (xval[n] - xval[n - 1]) / 6.0; c[n - 1][2] = d[n - 2] / 2.0; - c[n - 1][1] = - (yval[n] - yval[n - 1]) / (xval[n] - xval[n - 1]) - - d[n - - 2] * (xval[n] - xval[n - 1]) / 3.0; + c[n - 1][1] = (yval[n] - yval[n - 1]) / (xval[n] - xval[n - 1]) - + d[n - 2] * (xval[n] - xval[n - 1]) / 3.0; for (int i = 0; i < n; i++) { c[i][0] = yval[i]; } 1.4 +1 -7 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealFunction.java Index: UnivariateRealFunction.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealFunction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- UnivariateRealFunction.java 11 Jul 2003 15:59:14 -0000 1.3 +++ UnivariateRealFunction.java 30 Jul 2003 21:58:10 -0000 1.4 @@ -71,8 +71,6 @@ * @return the value * @throws MathException if the function couldn't be computed due to * missing additional data or other environmental problems. - * @throws RuntimeException if the operation isn't supported, the argument - * was outside the supported domain or any other problem. */ public double value(double x) throws MathException; @@ -85,8 +83,6 @@ * @param x the point for which the first derivative should be computed * @return the value * @throws MathException if the derivative couldn't be computed. - * @throws RuntimeException if the operation isn't supported, the argument - * was outside the supported domain or any other problem. */ public double firstDerivative(double x) throws MathException; @@ -99,8 +95,6 @@ * @param x the point for which the first derivative should be computed * @return the value * @throws MathException if the second derivative couldn't be computed. - * @throws RuntimeException if the operation isn't supported, the argument - * was outside the supported domain or any other problem. */ public double secondDerivative(double x) throws MathException; } 1.4 +39 -92 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java Index: UnivariateRealSolverFactory.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- UnivariateRealSolverFactory.java 11 Jul 2003 15:59:14 -0000 1.3 +++ UnivariateRealSolverFactory.java 30 Jul 2003 21:58:10 -0000 1.4 @@ -53,11 +53,6 @@ */ package org.apache.commons.math.analysis; -import java.lang.reflect.InvocationTargetException; - -import org.apache.commons.math.MathConfigurationException; -import org.apache.commons.math.MathException; - /** * A factory to easily get a default solver and some convenience * functions. @@ -68,104 +63,56 @@ * solve() method). * @version $Revision$ $Date$ */ -public class UnivariateRealSolverFactory { +public abstract class UnivariateRealSolverFactory { /** * Default constructor. */ - private UnivariateRealSolverFactory() { + protected UnivariateRealSolverFactory() { } /** + * @return a new factory. + * @todo add comment + * @todo for now, return the only concrete factory. Later, allow for a + * plugable implementation, possibly using SPI and commons-discovery. + */ + public static UnivariateRealSolverFactory newInstance() { + return new UnivariateRealSolverFactoryImpl(); + } + + /** * Create a new [EMAIL PROTECTED] UnivariateRealSolver} for the given function. The - * actual solver returned can be controlled by defining the - * <code>org.apache.commons.math.analysis.UnivariateRealSolver</code> - * property on the JVM command-line (<code> - * -Dorg.apache.commons.math.analysis.UnivariateRealSolver= - * <i>class name</i></code>). The value of the property should be any, - * fully qualified class name for a type that implements the - * [EMAIL PROTECTED] UnivariateRealSolver} interface. By default, an instance of - * [EMAIL PROTECTED] BrentSolver} is returned. + * actual solver returned is determined by the underlying factory. * @param f the function. * @return the new solver. - * @throws MathConfigurationException if a */ - public static UnivariateRealSolver newSolver(UnivariateRealFunction f) - throws MathConfigurationException { - String solverClassName = - System.getProperty( - "org.apache.commons.math.analysis.UnivariateRealSolver", - "org.apache.commons.math.analysis.BrentSolver"); - try { - Class clazz = Class.forName(solverClassName); - Class paramClass[] = new Class[1]; - paramClass[0] = UnivariateRealFunction.class; - Object param[] = new Object[1]; - param[0] = f; - return (UnivariateRealSolver)clazz.getConstructor( - paramClass).newInstance( - param); - } catch (IllegalArgumentException e) { - throw new MathConfigurationException(e); - } catch (SecurityException e) { - throw new MathConfigurationException( - "Can't access " + solverClassName, - e); - } catch (ClassNotFoundException e) { - throw new MathConfigurationException( - "Class not found: " + solverClassName, - e); - } catch (InstantiationException e) { - throw new MathConfigurationException( - "Can't instantiate " + solverClassName, - e); - } catch (IllegalAccessException e) { - throw new MathConfigurationException( - "Can't access " + solverClassName, - e); - } catch (InvocationTargetException e) { - throw new MathConfigurationException(e); - } catch (NoSuchMethodException e) { - throw new MathConfigurationException( - "No constructor with UnivariateRealFunction in " + - solverClassName, - e); - } - } - + public abstract UnivariateRealSolver newDefaultSolver( + UnivariateRealFunction f); + /** - * Convience method to solve for zeros of real univariate functions. A - * default solver is created and used for solving. + * Create a new [EMAIL PROTECTED] UnivariateRealSolver} for the given function. The + * solver is an implementation of the bisection method. * @param f the function. - * @param x0 the lower bound for the interval. - * @param x1 the upper bound for the interval. - * @return a value where the function is zero. - * @throws MathException if the iteration count was exceeded or the - * solver detects convergence problems otherwise. - */ - public static double solve(UnivariateRealFunction f, double x0, double x1) - throws MathException { - return newSolver(f).solve(x0, x1); - } - + * @return the new solver. + */ + public abstract UnivariateRealSolver newBisectionSolver( + UnivariateRealFunction f); + /** - * Convience method to solve for zeros of real univariate functions. A - * default solver is created and used for solving. + * Create a new [EMAIL PROTECTED] UnivariateRealSolver} for the given function. The + * solver is an implementation of the Brent method. * @param f the function. - * @param x0 the lower bound for the interval. - * @param x1 the upper bound for the interval. - * @param absoluteAccuracy the accuracy to be used by the solver. - * @return a value where the function is zero. - * @throws MathException if the iteration count was exceeded or the - * solver detects convergence problems otherwise. - */ - public static double solve( - UnivariateRealFunction f, - double x0, - double x1, - double absoluteAccuracy) - throws MathException { - UnivariateRealSolver solver = newSolver(f); - solver.setAbsoluteAccuracy(absoluteAccuracy); - return solver.solve(x0, x1); - } + * @return the new solver. + */ + public abstract UnivariateRealSolver newBrentSolver( + UnivariateRealFunction f); + + /** + * Create a new [EMAIL PROTECTED] UnivariateRealSolver} for the given function. The + * solver is an implementation of the secant method. + * @param f the function. + * @return the new solver. + */ + public abstract UnivariateRealSolver newSecantSolver( + UnivariateRealFunction f); } 1.4 +7 -6 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java Index: RealMatrixImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/linear/RealMatrixImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- RealMatrixImpl.java 7 Jul 2003 23:19:22 -0000 1.3 +++ RealMatrixImpl.java 30 Jul 2003 21:58:10 -0000 1.4 @@ -384,8 +384,9 @@ */ public double getEntry(int row, int column) throws IllegalArgumentException { - if (row < 1 || column < 1 || row > this.getRowDimension() - || column > this.getColumnDimension()) { + if (row < 1 || column < 1 || row > this.getRowDimension() || + column > this.getColumnDimension()) { + throw new IllegalArgumentException ("matrix entry does not exist"); } @@ -400,8 +401,9 @@ */ public void setEntry(int row, int column, double value) throws IllegalArgumentException { - if (row < 1 || column < 1 || row > this.getRowDimension() - || column > this.getColumnDimension()) { + if (row < 1 || column < 1 || row > this.getRowDimension() || + column > this.getColumnDimension()) { + throw new IllegalArgumentException ("matrix entry does not exist"); } @@ -587,7 +589,6 @@ } int nCol = this.getColumnDimension(); - int nRow = this.getRowDimension(); int nColB = b.getColumnDimension(); int nRowB = b.getRowDimension(); 1.8 +12 -15 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/special/Beta.java Index: Beta.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/special/Beta.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Beta.java 9 Jul 2003 20:03:09 -0000 1.7 +++ Beta.java 30 Jul 2003 21:58:10 -0000 1.8 @@ -143,8 +143,8 @@ double ret; - if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b) || (x < 0) - || (x > 1) || (a <= 0.0) || (b <= 0.0)) { + if (Double.isNaN(x) || Double.isNaN(a) || Double.isNaN(b) || (x < 0) || + (x > 1) || (a <= 0.0) || (b <= 0.0)) { ret = Double.NaN; } else { ContinuedFraction fraction = new ContinuedFraction() { @@ -158,15 +158,12 @@ default : 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)); + ret = -((a + m) * (a + b + m) * x) / + ((a + (2 * m)) * (a + (2 * m) + 1.0)); } else { m = (n - 1.0) / 2.0; - ret = - (m * (b - m) * x) - / ((a + (2 * m) - 1) * (a + (2 * m))); + ret = (m * (b - m) * x) / + ((a + (2 * m) - 1) * (a + (2 * m))); } break; } @@ -186,9 +183,9 @@ 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; @@ -230,8 +227,8 @@ if (Double.isNaN(a) || Double.isNaN(b) || (a <= 0.0) || (b <= 0.0)) { ret = Double.NaN; } else { - ret = Gamma.logGamma(a) + Gamma.logGamma(b) - - Gamma.logGamma(a + b); + ret = Gamma.logGamma(a) + Gamma.logGamma(b) - + Gamma.logGamma(a + b); } return ret; 1.10 +4 -7 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/special/Gamma.java Index: Gamma.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/special/Gamma.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Gamma.java 9 Jul 2003 20:03:09 -0000 1.9 +++ Gamma.java 30 Jul 2003 21:58:10 -0000 1.10 @@ -156,10 +156,7 @@ throw new ConvergenceException( "maximum number of iterations reached"); } else { - ret = Math.exp(-x + - (a * Math.log(x)) - - logGamma(a)) - * sum; + ret = Math.exp(-x + (a * Math.log(x)) - logGamma(a)) * sum; } } @@ -198,8 +195,8 @@ sum = sum + lanczos[0]; double tmp = x + g + .5; - ret = ((x + .5) * Math.log(tmp)) - tmp - + (.5 * Math.log(2.0 * Math.PI)) + Math.log(sum) - Math.log(x); + ret = ((x + .5) * Math.log(tmp)) - tmp + + (.5 * Math.log(2.0 * Math.PI)) + Math.log(sum) - Math.log(x); } return ret; 1.8 +3 -3 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/distribution/AbstractContinuousDistribution.java Index: AbstractContinuousDistribution.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/distribution/AbstractContinuousDistribution.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AbstractContinuousDistribution.java 9 Jul 2003 20:03:23 -0000 1.7 +++ AbstractContinuousDistribution.java 30 Jul 2003 21:58:11 -0000 1.8 @@ -56,7 +56,7 @@ import org.apache.commons.math.MathException; import org.apache.commons.math.analysis.RootFinding; import org.apache.commons.math.analysis.UnivariateRealFunction; -import org.apache.commons.math.analysis.UnivariateRealSolverFactory; +import org.apache.commons.math.analysis.UnivariateRealSolverUtil; /** * Base class for various continuous distributions. It provides default @@ -126,7 +126,7 @@ getDomainUpperBound(p)); // find root - double root = UnivariateRealSolverFactory.solve( + double root = UnivariateRealSolverUtil.solve( rootFindingFunction, bracket[0], bracket[1]); return root; 1.9 +3 -4 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/distribution/DistributionFactory.java Index: DistributionFactory.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/distribution/DistributionFactory.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- DistributionFactory.java 9 Jul 2003 20:03:22 -0000 1.8 +++ DistributionFactory.java 30 Jul 2003 21:58:11 -0000 1.9 @@ -83,11 +83,10 @@ /** * Create an instance of a <code>DistributionFactory</code> * @return a new factory. + * @todo for now, return the only concrete factory. Later, allow for a + * plugable implementation, possibly using SPI and commons-discovery. */ 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(); } 1.6 +2 -2 jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java Index: AbstractStorelessUnivariateStatistic.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/java/org/apache/commons/math/stat/univariate/AbstractStorelessUnivariateStatistic.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- AbstractStorelessUnivariateStatistic.java 15 Jul 2003 03:37:10 -0000 1.5 +++ AbstractStorelessUnivariateStatistic.java 30 Jul 2003 21:58:11 -0000 1.6 @@ -77,7 +77,7 @@ if (this.test(values, begin, length)) { this.clear(); int l = begin + length; - for (int i = begin; i < begin + length; i++) { + for (int i = begin; i < l; i++) { increment(values[i]); } } 1.2 +11 -11 jakarta-commons-sandbox/math/src/test/org/apache/commons/math/analysis/RealSolverTest.java Index: RealSolverTest.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/analysis/RealSolverTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- RealSolverTest.java 24 Jun 2003 03:02:28 -0000 1.1 +++ RealSolverTest.java 30 Jul 2003 21:58:11 -0000 1.2 @@ -282,27 +282,27 @@ // 14 iterations on i586 JDK 1.4.1. assertTrue(solver.getIterationCount() <= 15); // Static solve method - result = UnivariateRealSolverFactory.solve(f, -0.2, 0.2); + result = UnivariateRealSolverUtil.solve(f, -0.2, 0.2); assertEquals(result, 0, solver.getAbsoluteAccuracy()); - result = UnivariateRealSolverFactory.solve(f, -0.1, 0.3); + result = UnivariateRealSolverUtil.solve(f, -0.1, 0.3); Assert.assertEquals(result, 0, 1E-8); - result = UnivariateRealSolverFactory.solve(f, -0.3, 0.45); + result = UnivariateRealSolverUtil.solve(f, -0.3, 0.45); Assert.assertEquals(result, 0, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.3, 0.7); + result = UnivariateRealSolverUtil.solve(f, 0.3, 0.7); Assert.assertEquals(result, 0.5, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.2, 0.6); + result = UnivariateRealSolverUtil.solve(f, 0.2, 0.6); Assert.assertEquals(result, 0.5, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.05, 0.95); + result = UnivariateRealSolverUtil.solve(f, 0.05, 0.95); Assert.assertEquals(result, 0.5, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.85, 1.25); + result = UnivariateRealSolverUtil.solve(f, 0.85, 1.25); Assert.assertEquals(result, 1.0, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.8, 1.2); + result = UnivariateRealSolverUtil.solve(f, 0.8, 1.2); Assert.assertEquals(result, 1.0, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.85, 1.75); + result = UnivariateRealSolverUtil.solve(f, 0.85, 1.75); Assert.assertEquals(result, 1.0, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.55, 1.45); + result = UnivariateRealSolverUtil.solve(f, 0.55, 1.45); Assert.assertEquals(result, 1.0, 1E-6); - result = UnivariateRealSolverFactory.solve(f, 0.85, 5); + result = UnivariateRealSolverUtil.solve(f, 0.85, 5); Assert.assertEquals(result, 1.0, 1E-6); } } 1.3 +1 -58 jakarta-commons-sandbox/math/src/test/org/apache/commons/math/stat/BeanListUnivariateImplTest.java Index: BeanListUnivariateImplTest.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/math/src/test/org/apache/commons/math/stat/BeanListUnivariateImplTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- BeanListUnivariateImplTest.java 22 Jun 2003 03:57:53 -0000 1.2 +++ BeanListUnivariateImplTest.java 30 Jul 2003 21:58:11 -0000 1.3 @@ -138,62 +138,5 @@ ageU.getMax(), 0.001 ); } - - /* public void testN0andN1Conditions() throws Exception { - List list = new ArrayList(); - - StoreUnivariate u = new ListUnivariateImpl( list ); - - assertTrue("Mean of n = 0 set should be NaN", Double.isNaN( u.getMean() ) ); - assertTrue("Standard Deviation of n = 0 set should be NaN", Double.isNaN( u.getStandardDeviation() ) ); - assertTrue("Variance of n = 0 set should be NaN", Double.isNaN(u.getVariance() ) ); - - list.add( new Double(one)); - - assertTrue( "Mean of n = 1 set should be value of single item n1", u.getMean() == one); - assertTrue( "StdDev of n = 1 set should be zero, instead it is: " + u.getStandardDeviation(), u.getStandardDeviation() == 0); - assertTrue( "Variance of n = 1 set should be zero", u.getVariance() == 0); - } - - public void testSkewAndKurtosis() { - StoreUnivariate u = new StoreUnivariateImpl(); - - double[] testArray = { 12.5, 12, 11.8, 14.2, 14.9, 14.5, 21, 8.2, 10.3, 11.3, 14.1, - 9.9, 12.2, 12, 12.1, 11, 19.8, 11, 10, 8.8, 9, 12.3 }; - for( int i = 0; i < testArray.length; i++) { - u.addValue( testArray[i]); - } - - assertEquals("mean", 12.40455, u.getMean(), 0.0001); - assertEquals("variance", 10.00236, u.getVariance(), 0.0001); - assertEquals("skewness", 1.437424, u.getSkewness(), 0.0001); - assertEquals("kurtosis", 2.37719, u.getKurtosis(), 0.0001); - } - - public void testProductAndGeometricMean() throws Exception { - ListUnivariateImpl u = new ListUnivariateImpl(new ArrayList()); - u.setWindowSize(10); - - u.addValue( 1.0 ); - u.addValue( 2.0 ); - u.addValue( 3.0 ); - u.addValue( 4.0 ); - - assertEquals( "Product not expected", 24.0, u.getProduct(), Double.MIN_VALUE ); - assertEquals( "Geometric mean not expected", 2.213364, u.getGeometricMean(), 0.00001 ); - - // Now test rolling - UnivariateImpl should discount the contribution - // of a discarded element - for( int i = 0; i < 10; i++ ) { - u.addValue( i + 2 ); - } - // Values should be (2,3,4,5,6,7,8,9,10,11) - - assertEquals( "Product not expected", 39916800.0, u.getProduct(), 0.00001 ); - assertEquals( "Geometric mean not expected", 5.755931, u.getGeometricMean(), 0.00001 ); - - - } */ - }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]