Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

testFunctions

Classical Test Functions for Unconstrained Optimisation


Description

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

Usage

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) + 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 = 0.

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

-(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

sum(x^2)/4000 - prod(cos(x/sqrt(1:n))) + 1

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

The Rastrigin function:

10*n + sum(x^2 - 10 * cos(2 * pi * x))

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

The Rosenbrock (or banana) function:

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 = 1.

The Schwefel function:

sum(-x * sin(sqrt(abs(x))))

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

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

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).

Value

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

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.

Author(s)

Enrico Schumann

References

Gilli, M., Maringer, D. and Schumann, E. (2019) Numerical Methods and Optimization in Finance. 2nd edition. Elsevier. https://www.elsevier.com/books/numerical-methods-and-optimization-in-finance/gilli/978-0-12-815065-8

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

See Also

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)

NMOF

Numerical Methods and Optimization in Finance

v2.4-1
GPL-3
Authors
Enrico Schumann [aut, cre] (<https://orcid.org/0000-0001-7601-6576>)
Initial release
2021-04-09

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.