You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2021/08/27 15:31:31 UTC

[commons-math] 01/03: Add (back) "POwELL" standard test function for optimizers.

This is an automated email from the ASF dual-hosted git repository.

erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit ca826ba76bccec6d8cade6a0a660230b180b4555
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Thu Aug 26 23:56:42 2021 +0200

    Add (back) "POwELL" standard test function for optimizers.
---
 .../optim/nonlinear/scalar/TestFunction.java       | 50 +++++++++++++++++++---
 .../std_test_func.simplex.hedar_fukushima.csv      |  3 +-
 .../std_test_func.simplex.multidirectional.csv     |  2 +
 .../noderiv/std_test_func.simplex.nelder_mead.csv  |  2 +
 4 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/TestFunction.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/TestFunction.java
index f28bf11..a82d47a 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/TestFunction.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/TestFunction.java
@@ -154,16 +154,23 @@ public enum TestFunction {
                 return 1 - Math.cos(2 * Math.PI * sqrtSum) + 0.1 * sqrtSum;
             };
         }),
+    // https://scholarship.rice.edu/handle/1911/16304
     ROSENBROCK(dim -> {
-            final int last = dim - 1;
+            if (dim % 2 != 0) {
+                throw new IllegalArgumentException("Must be a multiple of 2 (was: " + dim + ")");
+            }
+            final int last = dim / 2;
             return x -> {
                 double f = 0;
-                for (int i = 0; i < last; i++) {
-                    final double xi = x[i];
-                    final double xiP1 = x[i + 1];
-                    final double a = xiP1 - xi * xi;
-                    final double b = xi - 1;
-                    f += 1e2 * a * a + b * b;
+                for (int i = 1; i <= last; i++) {
+                    final int twoI = 2 * i;
+                    final int i0 = twoI - 1;
+                    final int i1 = twoI;
+                    final double x2iM1 = x[i0 - 1];
+                    final double x2i = x[i1 - 1];
+                    final double t2iM1 = x2i - x2iM1 * x2iM1;
+                    final double t2i = 1 - x2iM1;
+                    f += 100 * t2iM1 * t2iM1 + t2i * t2i;
                 }
                 return f;
             };
@@ -286,6 +293,35 @@ public enum TestFunction {
                 }
                 return A * sum;
             };
+        }),
+    // https://scholarship.rice.edu/handle/1911/16304
+    POWELL(dim -> {
+            if (dim % 4 != 0) {
+                throw new IllegalArgumentException("Must be a multiple of 4 (was: " + dim + ")");
+            }
+            final int last = dim / 4;
+            return x -> {
+                double sum = 0;
+                for (int i = 1; i <= last; i++) {
+                    final int fourI = 4 * i;
+                    final int i0 = fourI - 3;
+                    final int i1 = fourI - 2;
+                    final int i2 = fourI - 1;
+                    final int i3 = fourI;
+                    final double x4iM3 = x[i0 - 1];
+                    final double x4iM2 = x[i1 - 1];
+                    final double x4iM1 = x[i2 - 1];
+                    final double x4i = x[i3 - 1];
+                    final double t4iM3 = x4iM3 + 10 * x4iM2;
+                    final double t4iM2 = x4iM1 - x4i;
+                    final double t4iM1 = x4iM2 - 2 * x4iM1;
+                    final double sqT4iM1 = t4iM1 * t4iM1;
+                    final double t4i = x4iM3 - x4i;
+                    final double sqT4i = t4i * t4i;
+                    sum += t4iM3 * t4iM3 + 5 * t4iM2 * t4iM2 + sqT4iM1 * sqT4iM1 + 10 * sqT4i * sqT4i;
+                }
+                return sum;
+            };
         });
 
     /** Template for variable dimension. */
diff --git a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.hedar_fukushima.csv b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.hedar_fukushima.csv
index d6c0d66..2030e0c 100644
--- a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.hedar_fukushima.csv
+++ b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.hedar_fukushima.csv
@@ -32,10 +32,11 @@
 #
 PARABOLA, 8, 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 900, true
 ROSENBROCK, 2, 1 1, 0.9, 1.1, 1e-4, 160, true
+POWELL, 4, 0 0 0 0, 4, 5, 4e-3, 400, true
 CIGAR, 2, 0 0, 2, 3, 5e-5, 140, true
 SPHERE, 2, 0 0, 2, 3, 5e-4, 110, true
 ELLI, 2, 0 0, 3, 4, 1e-4, 150, true
-TWO_AXES, 2, 0 0, 3, 4, 1e-4, 160, true
+TWO_AXES, 2, 0 0, 3, 4, 1e-4, 170, true
 CIG_TAB, 2, 0 0, 3, 4, 1e-3, 150, true
 TABLET, 2, 0 0, 3, 4, 2e-4, 160, true
 SUM_POW, 2, 0 0, 3, 4, 1e-2, 110,  true
diff --git a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv
index bff4421..806e083 100644
--- a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv
+++ b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.multidirectional.csv
@@ -33,6 +33,8 @@
 PARABOLA, 8, 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 1500, false
 PARABOLA, 8, 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 2500, true
 ROSENBROCK, 2, 1 1, 0.9, 1.1, 3e-3, 650, true
+POWELL, 4, 0 0 0 0, 4, 5, 5e-2, 11800, false
+POWELL, 4, 0 0 0 0, 4, 5, 4e-3, 2000, true
 CIGAR, 2, 0 0, 2, 3, 5e-5, 240, false
 SPHERE, 2, 0 0, 2, 3, 5e-4, 200, false
 ELLI, 2, 0 0, 3, 4, 1e-4, 350, false
diff --git a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.nelder_mead.csv b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.nelder_mead.csv
index 5ee1cae..b70eb6b 100644
--- a/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.nelder_mead.csv
+++ b/commons-math-legacy/src/test/resources/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/std_test_func.simplex.nelder_mead.csv
@@ -34,6 +34,8 @@ PARABOLA, 8, 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 700, false
 PARABOLA, 8, 0 0 0 0 0 0 0 0, 20, 40, 1e-4, 6000, true
 ROSENBROCK, 2, 1 1, 0.9, 1.1, 1e-4, 110, false
 ROSENBROCK, 2, 1 1, 0.9, 1.1, 1e-4, 140, true
+POWELL, 4, 0 0 0 0, 4, 5, 4e-3, 290, false
+POWELL, 4, 0 0 0 0, 4, 5, 4e-3, 380, true
 CIGAR, 2, 0 0, 2, 3, 5e-5, 100, false
 SPHERE, 2, 0 0, 2, 3, 5e-4, 80, false
 ELLI, 2, 0 0, 3, 4, 1e-4, 350, false