From 48aea703a690273ea0428536fd033c71e0ac3c18 Mon Sep 17 00:00:00 2001 From: stevenj Date: Wed, 29 Aug 2007 23:38:08 -0400 Subject: [PATCH] added 3 more test functions darcs-hash:20070830033808-c8de0-58085c97cc5f62162f85879266ac1b4e64d65ac7.gz --- test/testfuncs.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++-- test/testfuncs.h | 2 +- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/test/testfuncs.c b/test/testfuncs.c index 5e29d92..f01cff2 100644 --- a/test/testfuncs.c +++ b/test/testfuncs.c @@ -25,6 +25,10 @@ static double testfuncs_status(int n, const double *x, double f) #define RETURN(f) return testfuncs_status(n, x, f); +#define PI2 6.283185307179586 /* 2*pi */ +#define PI3 9.424777960769379 /* 3*pi */ +#define PI4 12.5663706143592 /* 4*pi */ + /****************************************************************************/ static double rosenbrock_f(int n, const double *x, double *grad, void *data) { @@ -200,8 +204,6 @@ static const double shekel1_xmin[4] = {4.00057,4.00069,3.99949,3.99961}; static const double shekel2_xmin[4] = {4.00075,4.00059,3.99966,3.99951}; /****************************************************************************/ -#define PI3 9.424777960769379 /* 3*pi */ -#define PI2 6.283185307179586 /* 2*pi */ static double levy_f(int n, const double *x, double *grad, void *data) { UNUSED(data); @@ -288,6 +290,73 @@ static const double convexcosh_lb[10] = {-1,0,0,0,0,0,0,0,0,0}; static const double convexcosh_ub[10] = {2,3,6,7,8,10,11,13,14,16}; static const double convexcosh_xmin[10] = {0,1,2,3,4,5,6,7,8,9}; +/****************************************************************************/ +static double branin_f(int n, const double *x, double *grad, void *data) +{ + double a = 1 - 2*x[1] + 0.05 * sin(PI4 * x[1]) - x[0]; + double b = x[1] - 0.5 * sin(PI2 * x[0]); + UNUSED(data); + if (grad) { + grad[0] = -2*a - cos(PI2 * x[0]) * PI2 * b; + grad[1] = 2*a*(0.05 * PI4 * cos(PI4*x[1]) - 2) + 2*b; + } + RETURN(sqr(a) + sqr(b)); +} + +static const double branin_lb[2] = {-10,-10}; +static const double branin_ub[2] = {10,10}; +static const double branin_xmin[2] = {1,0}; + +/****************************************************************************/ +static double shubert_f(int n, const double *x, double *grad, void *data) +{ + UNUSED(data); + int i, j; + double f = 0; + for (j = 1; j <= 5; ++j) + for (i = 0; i < n; ++i) + f -= j * sin((j+1) * x[i] + j); + if (grad) { + for (i = 0; i < n; ++i) { + grad[i] = 0; + for (j = 1; j <= 5; ++j) + grad[i] -= j * (j+1) * cos((j+1) * x[i] + j); + } + } + RETURN(f); +} + +static const double shubert_lb[2] = {-10,-10}; +static const double shubert_ub[2] = {10,10}; +static const double shubert_xmin[2] = {-6.774576, -6.774576}; + +/****************************************************************************/ +static double hansen_f(int n, const double *x, double *grad, void *data) +{ + int i; + double a = 0, b = 0; + UNUSED(data); + for (i = 1; i <= 5; ++i) + a += i * cos((i-1) * x[0] + i); + for (i = 1; i <= 5; ++i) + b += i * cos((i+1) * x[1] + i); + if (grad) { + grad[0] = 0; + for (i = 1; i <= 5; ++i) + grad[0] -= i * (i-1) * sin((i-1) * x[0] + i); + grad[0] *= b; + grad[1] = 0; + for (i = 1; i <= 5; ++i) + grad[1] -= i * (i+1) * sin((i+1) * x[1] + i); + grad[1] *= a; + } + RETURN(a*b); +} + +static const double hansen_lb[2] = {-10,-10}; +static const double hansen_ub[2] = {10,10}; +static const double hansen_xmin[2] = {-1.306708,-1.425128}; + /****************************************************************************/ /****************************************************************************/ @@ -339,5 +408,14 @@ const testfunc testfuncs[NTESTFUNCS] = { -1.03163, "Six-hump camel back function" }, { convexcosh_f, NULL, 1, 10, convexcosh_lb, convexcosh_ub, convexcosh_xmin, - 1.0, "Convex product of cosh functions" } + 1.0, "Convex product of cosh functions" }, + { branin_f, NULL, 1, 2, + branin_lb, branin_ub, branin_xmin, + -.0, "Branin function" }, + { shubert_f, NULL, 1, 2, + shubert_lb, shubert_ub, shubert_xmin, + -24.062499, "Shubert function" }, + { hansen_f, NULL, 1, 2, + hansen_lb, hansen_ub, hansen_xmin, + -176.541793, "Hansen function" } }; diff --git a/test/testfuncs.h b/test/testfuncs.h index b8256e3..e7ebc41 100644 --- a/test/testfuncs.h +++ b/test/testfuncs.h @@ -18,7 +18,7 @@ typedef struct { const char *name; } testfunc; -#define NTESTFUNCS 16 +#define NTESTFUNCS 19 extern const testfunc testfuncs[NTESTFUNCS]; extern int testfuncs_verbose; -- 2.30.2