testFunctions function

Classical Test Functions for Unconstrained Optimisation

Classical Test Functions for Unconstrained Optimisation

A number of functions that have been suggested in the literature as benchmarks for unconstrained optimisation.

tfAckley(x) tfEggholder(x) tfGriewank(x) tfRastrigin(x) tfRosenbrock(x) tfSchwefel(x) tfTrefethen(x)

Arguments

  • x: a numeric vector of arguments. See Details.

Details

All functions take as argument only one variable, a numeric vector x whose length determines the dimensionality of the problem.

The Ackley function is implemented as

exp(1)+2020exp(0.21ni=1nxi2)exp(1ni=1ncos(2πxi)).exp(1)+2020exp(0.2sqrt(sum(x2)/n))exp(sum(cos(2pix))/n) \exp(1) + 20 -20 \exp{\left(-0.2 \sqrt{\frac{1}{n}\sum_{i=1}^n x_i^2}\right)} - \exp{\left(\frac{1}{n}\sum_{i=1}^n \cos(2 \pi x_i)\right)}\,.exp(1) + 20 - 20 * exp(-0.2 * sqrt(sum(x^2)/n)) - exp(sum(cos(2 * pi * x))/n)

The minimum function value is zero; reached at x=0x = 0.

The Eggholder takes a two-dimensional x, here written as xx and yy. It is defined as

(y+47)sin(y+x2+47)xsin(x(y+47)).(y+47)sin(sqrt(abs(y+x/2+47)))xsin(sqrt(abs(x(y+47)))) -(y + 47) \sin\left(\sqrt{|y + \frac{x}{2} + 47|}\right) -x \sin\left(\sqrt{|x - (y + 47)|}\right)\,.-(y + 47) * sin(sqrt(abs(y + x/2 + 47))) -x * sin(sqrt(abs(x - (y + 47))))

The minimum function value is -959.6407; reached at c(512, 404.2319).

The Griewank function is given by

1+14000i=1nxi2i=1ncos(xii).sum(x2)/4000prod(cos(x/sqrt(1:n)))+1 1+\frac{1}{4000} \sum^n_{i=1} x_i^2 - \prod_{i=1}^n \cos \left(\frac{x_i}{\sqrt{i}}\right)\,.sum(x^2)/4000 - prod(cos(x/sqrt(1:n))) + 1

The function is minimised at x=0x = 0; its minimum value is zero.

The Rastrigin function:

10n+i=1n(xi210cos(2πxi)).10n+sum(x210cos(2pix)) 10n + \sum_{i=1}^n \left(x_i^2 -10\cos(2\pi x_i)\right)\,.10*n + sum(x^2 - 10 * cos(2 * pi * x))

The minimum function value is zero; reached at x=0x = 0.

The Rosenbrock (or banana) function:

i=1n1(100(xi+1xi2)2+(1xi)2).sum(100(x[2:n]x[1:(n1)]2)2+(1x[1:(n1)])2) \sum_{i=1}^{n-1}\left(100 (x_{i+1}-x_i^2)^2 + (1-x_i)^2\right)\,.sum(100*(x[2:n] - x[1:(n - 1)]^2)^2 + (1 - x[1:(n - 1)])^2)

The minimum function value is zero; reached at x=1x = 1.

The Schwefel function:

i=1n(xisin(xi)).sum(xsin(sqrt(abs(x)))) \sum_{i=1}^n \left(-x_i \sin\left(\sqrt{|x_i|}\right)\right)\,.sum(-x * sin(sqrt(abs(x))))

The minimum function value (to about 8 digits) is 418.9829n-418.9829n; reached at x=420.9687x = 420.9687.

Trefethen's function takes a two-dimensional x (here written as xx and yy); it is defined as

exp(sin(50x))+sin(60ey)+sin(70sin(x))+sin(sin(80y))sin(10(x+y))+14(x2+y2).exp(sin(50x))+sin(60exp(y))+sin(70sin(x))+sin(sin(80y))sin(10(x+y))+(x2+y2)/4 \exp(\sin(50x)) + \sin(60 e^y) + \sin(70 \sin(x)) + \sin(\sin(80y)) - \sin(10(x+y)) + \frac{1}{4}(x^2+y^2)\,.exp(sin(50 * x)) + sin(60 * exp(y)) + sin(70 * sin(x)) + sin(sin(80 * y)) - sin(10 * (x + y)) + (x^2 + y^2)/4

The minimum function value is -3.3069; reached at c(-0.0244, 0.2106).

Returns

The objective function evaluated at x (a numeric vector of length one).

References

Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. tools:::Rd_expr_doi("10.1016/C2017-0-01621-X")

Schumann, E. (2023) Financial Optimisation with R (NMOF Manual). https://enricoschumann.net/NMOF.htm#NMOFmanual

Author(s)

Enrico Schumann

Warning

These test functions represent artificial problems. It is practically not too helpful to fine-tune a method on such functions. (That would be like memorising all the answers to a particular multiple-choice test.) The functions' main purpose is checking the numerical implementation of algorithms.

See Also

DEopt, PSopt

Examples

## persp for two-dimensional x ## Ackley n <- 100L; surf <- matrix(NA, n, n) x1 <- seq(from = -2, to = 2, length.out = n) for (i in 1:n) for (j in 1:n) surf[i, j] <- tfAckley(c(x1[i], x1[j])) persp(x1, x1, -surf, phi = 30, theta = 30, expand = 0.5, col = "goldenrod1", shade = 0.2, ticktype = "detailed", xlab = "x1", ylab = "x2", zlab = "-f", main = "Ackley (-f)", border = NA) ## Trefethen n <- 100L; surf <- matrix(NA, n, n) x1 <- seq(from = -10, to = 10, length.out = n) for (i in 1:n) for (j in 1:n) surf[i, j] <- tfTrefethen(c(x1[i], x1[j])) persp(x1, x1, -surf, phi = 30, theta = 30, expand = 0.5, col = "goldenrod1", shade = 0.2, ticktype = "detailed", xlab = "x1", ylab = "x2", zlab = "-f", main = "Trefethen (-f)", border = NA)