author Michael Orlitzky Fri, 8 Mar 2013 04:18:47 +0000 (23:18 -0500) committer Michael Orlitzky Fri, 8 Mar 2013 04:18:47 +0000 (23:18 -0500)
 optimization/test_functions/rosenbrock.m [new file with mode: 0644] patch | blob optimization/test_functions/rosenbrock1.m [new file with mode: 0644] patch | blob optimization/test_functions/rosenbrock_gradient.m [new file with mode: 0644] patch | blob optimization/test_functions/rosenbrock_gradient1.m [new file with mode: 0644] patch | blob optimization/test_functions/rosenbrock_hessian.m [new file with mode: 0644] patch | blob optimization/test_functions/rosenbrock_hessian1.m [new file with mode: 0644] patch | blob tests/rosenbrock1_tests.m [new file with mode: 0644] patch | blob tests/rosenbrock_gradient_tests.m [new file with mode: 0644] patch | blob tests/rosenbrock_tests.m [new file with mode: 0644] patch | blob

diff --git a/optimization/test_functions/rosenbrock.m b/optimization/test_functions/rosenbrock.m
new file mode 100644 (file)
index 0000000..8073a0a
--- /dev/null
@@ -0,0 +1,11 @@
+function f = rosenbrock(x1, x2)
+  ##
+  ## The Rosenbrock function. See Dennis & Schnabel, Appendix B, problem #1.
+  ## (The "regular" Rosenbrock function is simply the Extended Rosenbrock
+  ## with m=1).
+  ##
+  ## This function has a minimum at x=(1,1) with f(x) == 0. The
+  ## suggested starting point is x0=(-1.2, 1).
+  ##
+  f = 100*(x2 - x1^2)^2 + (1 - x1)^2;
+end
diff --git a/optimization/test_functions/rosenbrock1.m b/optimization/test_functions/rosenbrock1.m
new file mode 100644 (file)
index 0000000..5e4df05
--- /dev/null
@@ -0,0 +1,12 @@
+function f = rosenbrock1(x)
+  ##
+  ## A version of the Rosenbrock function which takes a column
+  ## 2-vector instead of two distinct arguments. See rosenbrock.m for
+  ## more information.
+  ##
+  if (length(x) == 2)
+    f = rosenbrock(x(1), x(2));
+  else
+    f = NA;
+  end
+end
new file mode 100644 (file)
index 0000000..50c4546
--- /dev/null
@@ -0,0 +1,9 @@
+  ##
+  ## The gradient of the Rosenbrock function. See rosenbrock.m for more
+  ## information.
+  ##
+  f_x1 = -400*x1*(x2 - x1^2) + 2*x1 - 2;
+  f_x2 = 200*(x2 - x1^2);
+  g = [f_x1; f_x2];
+end
new file mode 100644 (file)
index 0000000..e8a83b6
--- /dev/null
@@ -0,0 +1,12 @@
+  ##
+  ## A version of the rosenbrock_gradient() function which takes a
+  ## column 2-vector instead of two distinct arguments. See
+  ## rosenbrock_gradient.m for more information.
+  ##
+  if (length(x) == 2)
+  else
+    g = NA;
+  end
+end
diff --git a/optimization/test_functions/rosenbrock_hessian.m b/optimization/test_functions/rosenbrock_hessian.m
new file mode 100644 (file)
index 0000000..cd2a2b5
--- /dev/null
@@ -0,0 +1,11 @@
+function H = rosenbrock_hessian(x1, x2)
+  ##
+  ## The Hessian of the Rosenbrock function. See rosenbrock.m for more
+  ## information.
+  ##
+  H = zeros(2,2);
+  H(1,1) = 1200*x1^2 - 400*x2 + 2;
+  H(1,2) = -400*x1;
+  H(2,1) = -400*x1;
+  H(2,2) = 200;
+end
diff --git a/optimization/test_functions/rosenbrock_hessian1.m b/optimization/test_functions/rosenbrock_hessian1.m
new file mode 100644 (file)
index 0000000..63a105f
--- /dev/null
@@ -0,0 +1,12 @@
+function H = rosenbrock_hessian1(x)
+  ##
+  ## A version of the rosenbrock_hessian() function which takes a column
+  ## 2-vector instead of two distinct arguments. See rosenbrock_hessian.m
+  ## for more information.
+  ##
+  if (length(x) == 2)
+    H = rosenbrock_hessian(x(1), x(2));
+  else
+    H = NA;
+  end
+end
diff --git a/tests/rosenbrock1_tests.m b/tests/rosenbrock1_tests.m
new file mode 100644 (file)
index 0000000..4931403
--- /dev/null
@@ -0,0 +1,16 @@
+## Test the optimal point.
+
+unit_test_equals("rosenbrock1([1;1]) == 0", ...
+                0, ...
+                rosenbrock1([1;1]));
+
+## It should fail with the wrong number of coordinates.
+f = rosenbrock1([1]);
+unit_test_equals("rosenbrock1 fails with too few coordinates", ...
+                true, ...
+                isna(f));
+
+f = rosenbrock1([1;2;3]);
+unit_test_equals("rosenbrock1 fails with too many coordinates", ...
+                true, ...
+                isna(f));
new file mode 100644 (file)
index 0000000..c45b8e7
--- /dev/null
@@ -0,0 +1,5 @@
+## The gradient should be zero at the optimal point.
+