From 87d434fa93b3e52e8a5a0a9d99ae43492c35e1be Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 6 Mar 2013 17:12:43 -0500 Subject: [PATCH] Add the Wood() test function and some tests. --- optimization/test_functions/wood.m | 11 +++++++++ optimization/test_functions/wood1.m | 8 +++++++ optimization/test_functions/wood_gradient.m | 11 +++++++++ optimization/test_functions/wood_gradient1.m | 8 +++++++ optimization/test_functions/wood_hessian.m | 23 +++++++++++++++++++ optimization/test_functions/wood_hessian1.m | 24 ++++++++++++++++++++ tests/wood_gradient_tests.m | 6 +++++ tests/wood_tests.m | 6 +++++ 8 files changed, 97 insertions(+) create mode 100644 optimization/test_functions/wood.m create mode 100644 optimization/test_functions/wood1.m create mode 100644 optimization/test_functions/wood_gradient.m create mode 100644 optimization/test_functions/wood_gradient1.m create mode 100644 optimization/test_functions/wood_hessian.m create mode 100644 optimization/test_functions/wood_hessian1.m create mode 100644 tests/wood_gradient_tests.m create mode 100644 tests/wood_tests.m diff --git a/optimization/test_functions/wood.m b/optimization/test_functions/wood.m new file mode 100644 index 0000000..3e11a40 --- /dev/null +++ b/optimization/test_functions/wood.m @@ -0,0 +1,11 @@ +function f = wood(x1, x2, x3, x4) + ## + ## The Wood function. See Dennis & Schnabel, Appendix B, problem #5. + ## This function has a global minimum at x=(1,1,1,1) with f(x) == 0. + ## The suggested starting point is x0=(-3, -1, -3, -1). + ## + f = 100*(x1^2 - x2)^2 + (x1 - 1)^2 + (x3 - 1)^2; + f = f + 90*(x3^2 - x4)^2; + f = f + 10.1*((x2 - 1)^2 + (x4 - 1)^2); + f = f + 19.8*(x2 - 1)*(x4 - 1); +end diff --git a/optimization/test_functions/wood1.m b/optimization/test_functions/wood1.m new file mode 100644 index 0000000..6c3f319 --- /dev/null +++ b/optimization/test_functions/wood1.m @@ -0,0 +1,8 @@ +function f = wood1(x) + ## + ## A version of the Wood function which takes a column 4-vector + ## instead of four distinct arguments. See wood.m for more + ## information. + ## + f = wood(x(1), x(2), x(3), x(4)); +end diff --git a/optimization/test_functions/wood_gradient.m b/optimization/test_functions/wood_gradient.m new file mode 100644 index 0000000..f4dde78 --- /dev/null +++ b/optimization/test_functions/wood_gradient.m @@ -0,0 +1,11 @@ +function g = wood_gradient(x1, x2, x3, x4) + ## + ## The gradient of the Wood function. See wood.m for more information. + ## + f_x1 = 400*(x1^2 - x2)*x1 + 2*x1 - 2; + f_x2 = -200*x1^2 + 220.2*x2 + 19.8*x4 - 40; + f_x3 = 360*(x3^2 - x4)*x3 + 2*x3 - 2; + f_x4 = -180*x3^2 + 19.8*x2 + 200.2*x4 - 40; + + g = [f_x1; f_x2; f_x3; f_x4]; +end diff --git a/optimization/test_functions/wood_gradient1.m b/optimization/test_functions/wood_gradient1.m new file mode 100644 index 0000000..0191f54 --- /dev/null +++ b/optimization/test_functions/wood_gradient1.m @@ -0,0 +1,8 @@ +function g = wood_gradient1(x) + ## + ## A version of the wood_gradient() function which takes a column + ## 4-vector instead of four distinct arguments. See wood_gradient.m + ## for more information. + ## + g = wood_gradient(x(1), x(2), x(3), x(4)); +end diff --git a/optimization/test_functions/wood_hessian.m b/optimization/test_functions/wood_hessian.m new file mode 100644 index 0000000..f8e38c4 --- /dev/null +++ b/optimization/test_functions/wood_hessian.m @@ -0,0 +1,23 @@ +function H = wood_hessian(x1, x2, x3, x4) + ## + ## The Hessian of the Wood function. See wood.m for more + ## information. + ## + H = zeros(4,4); + H(1,1) = 1200*x(1)^2 - 400*x(2) + 2; + H(1,2) = -400*x(1); + H(1,3) = 0; + H(1,4) = 0; + H(2,1) = H(1,2); + H(2,2) = 220.2; + H(2,3) = 0; + H(2,4) = 19.8; + H(3,1) = H(1,3); + H(3,2) = H(2,3); + H(3,3) = 1080*x(3)^2 - 360*x(4) + 2; + H(3,4) = -360*x(3); + H(4,1) = H(1,4); + H(4,2) = H(2,4); + H(4,3) = H(3,4); + H(4,4) = 200.2; +end diff --git a/optimization/test_functions/wood_hessian1.m b/optimization/test_functions/wood_hessian1.m new file mode 100644 index 0000000..60d9854 --- /dev/null +++ b/optimization/test_functions/wood_hessian1.m @@ -0,0 +1,24 @@ +function H = wood_hessian1(x) + ## + ## A version of the wood_hessian() function which takes a column + ## 4-vector instead of four distinct arguments. See wood_hessian.m + ## for more information. + ## + H = zeros(4,4); + H(1,1) = 1200*x(1)^2 - 400*x(2) + 2; + H(1,2) = -400*x(1); + H(1,3) = 0; + H(1,4) = 0; + H(2,1) = H(1,2); + H(2,2) = 220.2; + H(2,3) = 0; + H(2,4) = 19.8; + H(3,1) = H(1,3); + H(3,2) = H(2,3); + H(3,3) = 1080*x(3)^2 - 360*x(4) + 2; + H(3,4) = -360*x(3); + H(4,1) = H(1,4); + H(4,2) = H(2,4); + H(4,3) = H(3,4); + H(4,4) = 200.2; +end diff --git a/tests/wood_gradient_tests.m b/tests/wood_gradient_tests.m new file mode 100644 index 0000000..700c667 --- /dev/null +++ b/tests/wood_gradient_tests.m @@ -0,0 +1,6 @@ +## The gradient should be zero at the optimal point. + +g = wood_gradient(1,1,1,1); +unit_test_equals("wood_gradient(1,1,1,1) == 0", ... + 0, ... + wood_gradient(1,1,1,1)); diff --git a/tests/wood_tests.m b/tests/wood_tests.m new file mode 100644 index 0000000..822da99 --- /dev/null +++ b/tests/wood_tests.m @@ -0,0 +1,6 @@ +## Test the optimal point. + +f = wood(1,1,1,1); +unit_test_equals("wood(1,1,1,1) == 0", ... + 0, ... + wood(1,1,1,1)); -- 2.43.2