Learn R Programming

NMOF (version 2.10-0)

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)

Value

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

Arguments

x

a numeric vector of arguments. See Details.

Author

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.

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{\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)}\,.$$ 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\left(\sqrt{|y + \frac{x}{2} + 47|}\right) - x \sin\left(\sqrt{|x - (y + 47)|}\right)\,.$$ The minimum function value is -959.6407; reached at c(512, 404.2319).

The Griewank function is given by $$1+\frac{1}{4000} \sum^n_{i=1} x_i^2 - \prod_{i=1}^n \cos \left(\frac{x_i}{\sqrt{i}}\right)\,.$$ The function is minimised at \(x=0\); its minimum value is zero.

The Rastrigin function: $$10n + \sum_{i=1}^n \left(x_i^2 -10\cos(2\pi x_i)\right)\,.$$ The minimum function value is zero; reached at \(x=0\).

The Rosenbrock (or banana) function: $$\sum_{i=1}^{n-1}\left(100 (x_{i+1}-x_i^2)^2 + (1-x_i)^2\right)\,.$$ The minimum function value is zero; reached at \(x=1\).

The Schwefel function: $$\sum_{i=1}^n \left(-x_i \sin\left(\sqrt{|x_i|}\right)\right)\,.$$ 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(50x)) + \sin(60 e^y) + \sin(70 \sin(x)) + \sin(\sin(80y)) - \sin(10(x+y)) + \frac{1}{4}(x^2+y^2)\,.$$ The minimum function value is -3.3069; reached at c(-0.0244, 0.2106).

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

See Also

DEopt, PSopt

Examples

Run this code
## 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)

Run the code above in your browser using DataLab