From 58c6028e214c3b76634d6c3a7df943aa7651ea7b Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Wed, 28 Jul 2010 12:48:48 +0000 Subject: [PATCH] MATH-396 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@980039 13f79535-47bb-0310-9956-ffa450edef68 --- src/site/xdoc/userguide/optimization.xml | 4 ++++ .../general/PowellOptimizerTest.java | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/site/xdoc/userguide/optimization.xml b/src/site/xdoc/userguide/optimization.xml index b2389a78e..54e1c9faf 100644 --- a/src/site/xdoc/userguide/optimization.xml +++ b/src/site/xdoc/userguide/optimization.xml @@ -212,6 +212,10 @@ or to change the line-search algorithm of the inner loop if desired (the default one is a Brent solver).

+

+ The + PowellOptimizer provides an optimization method for non-differentiable functions. +

diff --git a/src/test/java/org/apache/commons/math/optimization/general/PowellOptimizerTest.java b/src/test/java/org/apache/commons/math/optimization/general/PowellOptimizerTest.java index c43efd81c..52b39fb93 100644 --- a/src/test/java/org/apache/commons/math/optimization/general/PowellOptimizerTest.java +++ b/src/test/java/org/apache/commons/math/optimization/general/PowellOptimizerTest.java @@ -39,7 +39,7 @@ public class PowellOptimizerTest { public void testSumSinc() throws MathException { final MultivariateRealFunction func = new SumSincFunction(-1); - int dim = 1; + int dim = 10; final double[] minPoint = new double[dim]; for (int i = 0; i < dim; i++) { minPoint[i] = 0; @@ -51,13 +51,13 @@ public class PowellOptimizerTest { for (int i = 0; i < dim; i++) { init[i] = minPoint[i]; } - doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-15, 1e-8); + doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-7); // Initial is far from minimum. for (int i = 0; i < dim; i++) { - init[i] = minPoint[i] + 4; + init[i] = minPoint[i] + 3; } - doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-15, 1e-8); + doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-7); } @Test @@ -83,13 +83,13 @@ public class PowellOptimizerTest { for (int i = 0; i < dim; i++) { init[i] = minPoint[i]; } - doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-15, 1e-8); + doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-8); // Initial is far from minimum. for (int i = 0; i < dim; i++) { init[i] = minPoint[i] - 20; } - doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-15, 1e-8); + doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-8); } @Test @@ -115,13 +115,13 @@ public class PowellOptimizerTest { for (int i = 0; i < dim; i++) { init[i] = maxPoint[i]; } - doTest(func, maxPoint, init, GoalType.MAXIMIZE, 1e-15, 1e-8); + doTest(func, maxPoint, init, GoalType.MAXIMIZE, 1e-9, 1e-8); // Initial is far from minimum. for (int i = 0; i < dim; i++) { init[i] = maxPoint[i] - 20; } - doTest(func, maxPoint, init, GoalType.MAXIMIZE, 1e-15, 1e-8); + doTest(func, maxPoint, init, GoalType.MAXIMIZE, 1e-9, 1e-8); } /** @@ -140,12 +140,17 @@ public class PowellOptimizerTest { double pointTol) throws MathException { final MultivariateRealOptimizer optim = new PowellOptimizer(); - final double relTol = 1e-10; optim.setConvergenceChecker(new SimpleScalarValueChecker(objTol, -1)); final RealPointValuePair result = optim.optimize(func, goal, init); final double[] found = result.getPoint(); + System.out.println("Function value at initial guess: " + func.value(init)); + System.out.println("Function value at optimum: " + result.getValue()); + System.out.println("Iterations: " + optim.getIterations()); + System.out.println("Function evaluations: " + optim.getEvaluations()); + System.out.println(Arrays.toString(found)); + for (int i = 0, dim = optimum.length; i < dim; i++) { Assert.assertEquals(optimum[i], found[i], pointTol); }