Skip to content

Commit

Permalink
adds Beale, Branin, Colville, Styblinski-Tang
Browse files Browse the repository at this point in the history
  • Loading branch information
kvoss committed Jun 11, 2021
1 parent e3f2bdc commit d1a512f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ x tripod
x trefethen4
x three_hump_camel_back
x dixon_price
x beale
x branin
x colville
x styblinski_tang
```

## Contributions
Expand Down
56 changes: 56 additions & 0 deletions bss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,62 @@ dixon_price(const std::vector<double>& xs)
return ret;
}

// Other functions
double
beale(const std::vector<double>& xs)
{
double x1 = xs.at(0);
double x2 = xs.at(1);
double ret = SQ(1.5 - x1 + x1*x2)
+ SQ(2.25 - x1 + x1 * SQ(x2))
+ SQ(2.625 - x1 + x1 * x2 * SQ(x2));
return ret;
}

double
branin(const std::vector<double>& xs)
{
const double
a = 1.,
b = 5.1 / (4 * SQ(pi)),
c = 5. / pi,
r = 6.,
s = 10.,
t = 1. / 8 / pi;

double x1 = xs.at(0);
double x2 = xs.at(1);
double ret = s
+ a * SQ(x2 - b*SQ(x1) + c*x1 - r)
+ s * (1. - t) * std::cos(x1);
return ret;
}

double
colville(const std::vector<double>& xs)
{
// 4 dimensional
double ret =
100. * SQ(SQ(xs.at(0)) - xs.at(1))
+ SQ(xs.at(0) - 1.)
+ SQ(xs.at(2) - 1.)
+ 90. * SQ(SQ(xs.at(2)) - xs.at(3))
+ 10.1 * (SQ(xs.at(1) - 1.) + SQ(xs.at(3) - 1.))
+ 19.8 * (xs.at(1) - 1.) * (xs.at(3) - 1.);
return ret;
}

double
styblinski_tang(const std::vector<double>& xs)
{
double ret = 0.;
for (auto &&x: xs) {
ret += SQ(x) * SQ(x) - 16.*SQ(x) + 5.*x;
}
ret /= 2.;
return ret;
}

// int
// main (int argc, char** argv)
// {
Expand Down
4 changes: 4 additions & 0 deletions bss.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ double tripod(const std::vector<double>& xs);
double trefethen4(const std::vector<double>& xs);
double three_hump_camel_back(const std::vector<double>& xs);
double dixon_price(const std::vector<double>& xs);
double beale(const std::vector<double>& xs);
double branin(const std::vector<double>& xs);
double colville(const std::vector<double>& xs);
double styblinski_tang(const std::vector<double>& xs);

#endif // _BSS_H

8 changes: 8 additions & 0 deletions cbench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ PYWRAP(tripod);
PYWRAP(trefethen4);
PYWRAP(three_hump_camel_back);
PYWRAP(dixon_price);
PYWRAP(beale);
PYWRAP(branin);
PYWRAP(colville);
PYWRAP(styblinski_tang);


static PyMethodDef
Expand Down Expand Up @@ -128,6 +132,10 @@ CBenchMethods[] = {
{"trefethen4", py_trefethen4, METH_VARARGS, "trefethen4 function"},
{"three_hump_camel_back", py_three_hump_camel_back, METH_VARARGS, "three hump camel function"},
{"dixon_price", py_dixon_price, METH_VARARGS, "dixon price function"},
{"beale", py_beale, METH_VARARGS, "beale function"},
{"branin", py_branin, METH_VARARGS, "branin function"},
{"colville", py_colville, METH_VARARGS, "colville function"},
{"styblinski_tang", py_styblinski_tang, METH_VARARGS, "styblinski_tang function"},
{NULL, NULL, 0, NULL}
};

Expand Down
4 changes: 4 additions & 0 deletions sanity-test-golden.log
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
-> ackley: 3.194178743769641
-> alpine: 0.6941110026558399
-> axis_parallel_hyperellipsoid: 2.3005
-> beale: 13.03578164
-> bohachevsky1: 0.937271222062237
-> bohachevsky2: 0.5326584774442731
-> bohachevsky3: 0.675316954888546
-> branin: 51.38785089543272
-> bukin_f6: 44.811177812216314
-> colville: 33.163000000000004
-> cross_in_tray: -1.4777274811045142
-> deceptive3: -0.0009897909414337454
-> dejong5: 12.670567474629571
Expand Down Expand Up @@ -36,6 +39,7 @@
-> six_hump_camel_back: -0.09380966666666667
-> sphere: 0.5601
-> step: 1.25
-> styblinski_tang: -0.6542739950000005
-> sum_powers: 0.053936287801
-> sum_squares: 2.3005
-> three_hump_camel_back: 0.07989516666666668
Expand Down

0 comments on commit d1a512f

Please sign in to comment.