Add the Wood() test function and some tests.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 6 Mar 2013 22:12:43 +0000 (17:12 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 6 Mar 2013 22:12:43 +0000 (17:12 -0500)
optimization/test_functions/wood.m [new file with mode: 0644]
optimization/test_functions/wood1.m [new file with mode: 0644]
optimization/test_functions/wood_gradient.m [new file with mode: 0644]
optimization/test_functions/wood_gradient1.m [new file with mode: 0644]
optimization/test_functions/wood_hessian.m [new file with mode: 0644]
optimization/test_functions/wood_hessian1.m [new file with mode: 0644]
tests/wood_gradient_tests.m [new file with mode: 0644]
tests/wood_tests.m [new file with mode: 0644]

diff --git a/optimization/test_functions/wood.m b/optimization/test_functions/wood.m
new file mode 100644 (file)
index 0000000..3e11a40
--- /dev/null
@@ -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 (file)
index 0000000..6c3f319
--- /dev/null
@@ -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 (file)
index 0000000..f4dde78
--- /dev/null
@@ -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 (file)
index 0000000..0191f54
--- /dev/null
@@ -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 (file)
index 0000000..f8e38c4
--- /dev/null
@@ -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 (file)
index 0000000..60d9854
--- /dev/null
@@ -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 (file)
index 0000000..700c667
--- /dev/null
@@ -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 (file)
index 0000000..822da99
--- /dev/null
@@ -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));