chiark / gitweb /
added test function with minimum at side (i.e. one active bound constraint), which...
authorstevenj <stevenj@alum.mit.edu>
Thu, 27 Nov 2008 20:37:09 +0000 (15:37 -0500)
committerstevenj <stevenj@alum.mit.edu>
Thu, 27 Nov 2008 20:37:09 +0000 (15:37 -0500)
darcs-hash:20081127203709-c8de0-248be9ce8ebbedc63edea548940c330579979276.gz

test/testfuncs.c
test/testfuncs.h
test/testopt.cpp

index bbe75e965de72653b2e7a3a8d47722c797dc1051..e589d8248cb42d64b795bfb2cb478519212e88d3 100644 (file)
@@ -390,6 +390,48 @@ static const double corner4d_lb[4] = {0,0,0,0};
 static const double corner4d_ub[4] = {1,1,1,1};
 static const double corner4d_xmin[4] = {0,0,0,0};
 
+/****************************************************************************/
+static double side4d_f(int n, const double *x, double *grad, void *data)
+{
+     UNUSED(data);
+     UNUSED(n);
+     double x0, x1, x2, x3, d0,d1,d2,d3;
+     const double w0 = 0.1, w1 = 0.2, w2 = 0.3, w3 = 0.4;
+     x0 = +0.4977 * x[0] - 0.3153 * x[1] - 0.5066 * x[2] - 0.4391 * x[3];
+     x1 = -0.3153 * x[0] + 0.3248 * x[1] - 0.4382 * x[2] - 0.4096 * x[3];
+     x2 = -0.5066 * x[0] - 0.4382 * x[1] + 0.3807 * x[2] - 0.4543 * x[3];
+     x3 = -0.4391 * x[0] - 0.4096 * x[1] - 0.4543 * x[2] + 0.5667 * x[3];
+
+     d0 = -1. / (x0*x0 + w0*w0);
+     d1 = -1. / (x1*x1 + w1*w1);
+     d2 = -1. / (x2*x2 + w2*w2);
+     d3 = -1. / (x3*x3 + w3*w3);
+
+     if (grad) {
+         grad[0] = 2 * (x0*d0*d0 * +0.4977 +
+                        x1*d1*d1 * -0.3153 +
+                        x2*d2*d2 * -0.5066 +
+                        x3*d3*d3 * -0.4391);
+         grad[1] = 2 * (x0*d0*d0 * -0.3153 +
+                        x1*d1*d1 * +0.3248 +
+                        x2*d2*d2 * -0.4382 +
+                        x3*d3*d3 * -0.4096);
+         grad[2] = 2 * (x0*d0*d0 * -0.5066 +
+                        x1*d1*d1 * -0.4382 +
+                        x2*d2*d2 * +0.3807 +
+                        x3*d3*d3 * -0.4543);
+         grad[3] = 2 * (x0*d0*d0 * -0.4391 +
+                        x1*d1*d1 * -0.4096 +
+                        x2*d2*d2 * -0.4543 +
+                        x3*d3*d3 * +0.5667);
+     }
+     RETURN(d0 + d1 + d2 + d3);
+}
+
+static const double side4d_lb[4] = {0.1,-1,-1,-1};
+static const double side4d_ub[4] = {1,1,1,1};
+static const double side4d_xmin[4] = {0.1,0.102971169,0.0760520641,-0.0497098571};
+
 /****************************************************************************/
 /****************************************************************************/
 
@@ -456,5 +498,8 @@ const testfunc testfuncs[NTESTFUNCS] = {
        -1.0, "1d oscillating function with a single minimum" },
      { corner4d_f, NULL, 1, 4,
        corner4d_lb, corner4d_ub, corner4d_xmin,
-       1.0, "4d function with minimum at corner" }
+       1.0, "4d function with minimum at corner" },
+     { side4d_f, NULL, 1, 4,
+       side4d_lb, side4d_ub, side4d_xmin,
+       -141.285020472, "4d function with minimum at side" }
 };
index b20ea883bcc5c9cd6aabbe32fe2d187792a3cc3b..328d2e33b99132145eb5c6399a8062d9f5dfc7ba 100644 (file)
@@ -18,7 +18,7 @@ typedef struct {
      const char *name;
 } testfunc;
 
-#define NTESTFUNCS 21
+#define NTESTFUNCS 22
 extern const testfunc testfuncs[NTESTFUNCS];
 
 extern int testfuncs_verbose;
index 3ea4050ae5db4117bbab35ae5d8bad22952fa1c8..7c5c435167a9da52c72256e080f0033b99979595 100644 (file)
@@ -149,7 +149,7 @@ static int test_function(int ifunc)
     f0 = func.f(func.n, x, x + func.n, func.f_data);
     printf("Starting function value = %g\n", f0);
     
-    if (iter > 0 && testfuncs_verbose && func.has_gradient) {
+    if (iter == 0 && testfuncs_verbose && func.has_gradient) {
       printf("checking gradient:\n");
       for (i = 0; i < func.n; ++i) {
        double f;