commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1030464 [3/3] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/ main/java/org/apache/commons/math/analysis/ main/java/org/apache/commons/math/analysis/integration/ main/java/org/apache/commons/math/analysis/interpolat...
Date Wed, 03 Nov 2010 13:46:08 GMT
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealVectorTest.java
Wed Nov  3 13:46:04 2010
@@ -21,7 +21,7 @@ import java.util.Iterator;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.TestUtils;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.util.FastMath;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
Wed Nov  3 13:46:04 2010
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertTru
 import java.awt.geom.Point2D;
 import java.util.ArrayList;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateVectorialFunction;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
Wed Nov  3 13:46:04 2010
@@ -23,7 +23,7 @@ import static org.junit.Assert.fail;
 
 import java.io.Serializable;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.exception.ConvergenceException;
 import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
 import org.apache.commons.math.analysis.MultivariateMatrixFunction;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
Wed Nov  3 13:46:04 2010
@@ -20,9 +20,10 @@ package org.apache.commons.math.optimiza
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
-import org.apache.commons.math.optimization.direct.NelderMead;
+import org.apache.commons.math.optimization.direct.SimplexOptimizer;
+import org.apache.commons.math.optimization.direct.NelderMeadSimplex;
 import org.apache.commons.math.random.GaussianRandomGenerator;
 import org.apache.commons.math.random.JDKRandomGenerator;
 import org.apache.commons.math.random.RandomVectorGenerator;
@@ -30,53 +31,47 @@ import org.apache.commons.math.random.Un
 import org.junit.Test;
 
 public class MultiStartMultivariateRealOptimizerTest {
-
-  @Test
-  public void testRosenbrock()
-    throws FunctionEvaluationException {
-
-    Rosenbrock rosenbrock = new Rosenbrock();
-    NelderMead underlying = new NelderMead();
-    underlying.setStartConfiguration(new double[][] {
-                                         { -1.2,  1.0 }, { 0.9, 1.2 } , {  3.5, -2.3 }
-                                     });
-    JDKRandomGenerator g = new JDKRandomGenerator();
-    g.setSeed(16069223052l);
-    RandomVectorGenerator generator =
-        new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g));
-    MultiStartMultivariateRealOptimizer optimizer =
-        new MultiStartMultivariateRealOptimizer(underlying, 10, generator);
-    optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3));
-    optimizer.setMaxEvaluations(1100);
-    RealPointValuePair optimum =
-        optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });
-
-    assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
-    assertTrue(optimizer.getEvaluations() > 900);
-    assertTrue(optimizer.getEvaluations() < 1200);
-    assertTrue(optimum.getValue() < 8.0e-4);
-
-  }
-
-  private static class Rosenbrock implements MultivariateRealFunction {
-
-      private int count;
-
-      public Rosenbrock() {
-          count = 0;
-      }
-
-      public double value(double[] x) throws FunctionEvaluationException {
-          ++count;
-          double a = x[1] - x[0] * x[0];
-          double b = 1.0 - x[0];
-          return 100 * a * a + b * b;
-      }
-
-      public int getCount() {
-          return count;
-      }
-
-  }
-
+    @Test
+    public void testRosenbrock() {
+        Rosenbrock rosenbrock = new Rosenbrock();
+        SimplexOptimizer underlying = new SimplexOptimizer();
+        NelderMeadSimplex simplex = new NelderMeadSimplex(new double[][] {
+                { -1.2,  1.0 }, { 0.9, 1.2 } , {  3.5, -2.3 }
+            });
+        underlying.setSimplex(simplex);
+        JDKRandomGenerator g = new JDKRandomGenerator();
+        g.setSeed(16069223052l);
+        RandomVectorGenerator generator =
+            new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g));
+        MultiStartMultivariateRealOptimizer optimizer =
+            new MultiStartMultivariateRealOptimizer(underlying, 10, generator);
+        optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3));
+        optimizer.setMaxEvaluations(1100);
+        RealPointValuePair optimum =
+            optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });
+
+        assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
+        assertTrue(optimizer.getEvaluations() > 900);
+        assertTrue(optimizer.getEvaluations() < 1200);
+        assertTrue(optimum.getValue() < 8.0e-4);
+    }
+
+    private static class Rosenbrock implements MultivariateRealFunction {
+        private int count;
+
+        public Rosenbrock() {
+            count = 0;
+        }
+
+        public double value(double[] x) {
+            ++count;
+            double a = x[1] - x[0] * x[0];
+            double b = 1.0 - x[0];
+            return 100 * a * a + b * b;
+        }
+
+        public int getCount() {
+            return count;
+        }
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java
Wed Nov  3 13:46:04 2010
@@ -16,7 +16,7 @@
  */
 package org.apache.commons.math.optimization.direct;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.MathException;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.analysis.SumSincFunction;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java
Wed Nov  3 13:46:04 2010
@@ -17,7 +17,7 @@
 
 package org.apache.commons.math.optimization.direct;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.optimization.GoalType;
 import org.apache.commons.math.optimization.RealPointValuePair;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java
Wed Nov  3 13:46:04 2010
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertNul
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateVectorialFunction;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java
Wed Nov  3 13:46:04 2010
@@ -17,7 +17,7 @@
 
 package org.apache.commons.math.optimization.fitting;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer;
 import org.apache.commons.math.util.FastMath;
 import org.junit.Assert;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/GaussianFitterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/GaussianFitterTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/GaussianFitterTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/GaussianFitterTest.java
Wed Nov  3 13:46:04 2010
@@ -19,7 +19,7 @@ package org.apache.commons.math.optimiza
 
 import static org.junit.Assert.assertEquals;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.optimization.OptimizationException;
 import org.apache.commons.math.optimization.general.
        LevenbergMarquardtOptimizer;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/ParametricGaussianFunctionTest.java
Wed Nov  3 13:46:04 2010
@@ -17,7 +17,7 @@
 
 package org.apache.commons.math.optimization.fitting;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.exception.ZeroException;
 import org.apache.commons.math.optimization.OptimizationException;
 import org.apache.commons.math.optimization.fitting.CurveFitter;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizerTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizerTest.java
Wed Nov  3 13:46:04 2010
@@ -24,7 +24,7 @@ import java.util.Arrays;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.exception.ConvergenceException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.exception.DimensionMismatchException;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
Wed Nov  3 13:46:04 2010
@@ -25,7 +25,7 @@ import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.exception.ConvergenceException;
 import org.apache.commons.math.exception.DimensionMismatchException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java
Wed Nov  3 13:46:04 2010
@@ -22,7 +22,7 @@ import java.util.Arrays;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.analysis.DifferentiableMultivariateVectorialFunction;
 import org.apache.commons.math.analysis.MultivariateMatrixFunction;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java
Wed Nov  3 13:46:04 2010
@@ -23,7 +23,7 @@ import java.util.ArrayList;
 
 import junit.framework.TestCase;
 
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.analysis.DifferentiableMultivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateVectorialFunction;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BracketFinderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BracketFinderTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BracketFinderTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BracketFinderTest.java
Wed Nov  3 13:46:04 2010
@@ -17,7 +17,7 @@
 package org.apache.commons.math.optimization.univariate;
 
 import org.apache.commons.math.MathException;
-import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.exception.FunctionEvaluationException;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.optimization.GoalType;
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1030464&r1=1030463&r2=1030464&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
Wed Nov  3 13:46:04 2010
@@ -19,6 +19,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Arrays;
 
 import junit.framework.TestCase;
 
@@ -1510,4 +1511,32 @@ public final class MathUtilsTest extends
             // Expected
         }
     }
+
+    public void testSortInPlace() {
+        final double[] x1 = {2,   5,  -3, 1,  4};
+        final double[] x2 = {4,  25,   9, 1, 16};
+        final double[] x3 = {8, 125, -27, 1, 64};
+        
+        MathUtils.sortInPlace(x1, x2, x3);
+
+        assertEquals(-3,  x1[0], Math.ulp(1d));
+        assertEquals(9,   x2[0], Math.ulp(1d));
+        assertEquals(-27, x3[0], Math.ulp(1d));
+
+        assertEquals(1, x1[1], Math.ulp(1d));
+        assertEquals(1, x2[1], Math.ulp(1d));
+        assertEquals(1, x3[1], Math.ulp(1d));
+
+        assertEquals(2, x1[2], Math.ulp(1d));
+        assertEquals(4, x2[2], Math.ulp(1d));
+        assertEquals(8, x3[2], Math.ulp(1d));
+
+        assertEquals(4,  x1[3], Math.ulp(1d));
+        assertEquals(16, x2[3], Math.ulp(1d));
+        assertEquals(64, x3[3], Math.ulp(1d));
+
+        assertEquals(5,   x1[4], Math.ulp(1d));
+        assertEquals(25,  x2[4], Math.ulp(1d));
+        assertEquals(125, x3[4], Math.ulp(1d));
+    }
 }



Mime
View raw message