Learn R Programming

adagio (version 0.5.9)

Testfunctions: Optimization Test Function

Description

Simple and often used test function defined in higher dimensions and with analytical gradients, especially suited for performance tests. Analytical gradients are provided with the gr prefix. The dimension is determined by the length of the input vector.

Usage

genTestfn(fname)

Arguments

fname
name of a test function as character string.

Value

  • Returns a list with components fn the function and gr its gradient. If an analytical gradient is not available, a function computing the gradient numerically will be provided.

Details

Available test functions are: Hald, Nesterov, Nesterov1, Rastrigin, Rosenbrock, Shor.

Rosenbrock -- Rosenbrock's famous valley function from 1960. It can also be regarded as a least-squares problem: $$\sum_{i=1}^{n-1} (1-x_i)^2 + 100 (x_{i+1}-x_i^2)^2$$ ll{ No. of Vars.: n >= 2 Bounds: -5.12 <= xi="" <="5.12" local="" minima:="" at="" f(-1,="" 1,="" ...,="" 1)="" for="" n="">= 4 Minimum: 0.0 Solution: xi = 1, i = 1:n }

Nesterov -- Nesterov's smooth adaptation of Rosenbrock, based on the idea of Chebyshev polynomials. This function is even more difficult to optimize than Rosenbrock's: $$(x_1 - 1)^2 / 4 + \sum_{i=1}^{n-1} (1 + x_{i+1} - 2 x_i^2)$$ ll{ No. of Vars.: n >= 2 Bounds: -5.12 <= xi="" <="5.12" local="" minima:="" ?="" minimum:="" 0.0="" solution:="" i="1:n" }<="" p="">

Rastrigin -- Rastrigin's function is a famous, non-convex example from 1989 for global optimization. It is a typical example of a multimodal function with many local minima: $$10 n + \sum_1^n (x_i^2 - 10 \cos(2 \pi x_i))$$ ll{ No. of Vars.: n >= 2 Bounds: -5.12 <= xi="" <="5.12" local="" minima:="" many="" minimum:="" 0.0="" solution:="" i="1:n" }<="" p="">

Hald -- Hald's function is a typical example of a non-smooth test function, from Hald and Madsen in 1981. $$\max_{1 \le i \le n} \frac{x_1 + x_2 t_i}{1 + x_3 t_i + x_4 t_i^2 + x_5 t_i^3} - \exp(t_i)$$ where $t_i = -1 + (i - 1)/10$ for $1 \le i \le 21$. ll{ No. of Vars.: n =5 Bounds: -1 <= xi="" <="1" local="" minima:="" ?="" minimum:="" 0.0001223713="" solution:="" (0.99987763,="" 0.25358844,="" -0.74660757,="" 0.24520150,="" -0.03749029)="" }<="" p="">

Shor -- Shor's function is another typical example of a non-smooth test function, a benchmark for Shor's R-algorithm.

References

Search the Internet.

Examples

Run this code
x <- runif(5)
hald <- genTestfn("Hald")
fn <- hald$fn; gr <- hald$gr
fn(x); gr(x)

# How is the Rastrigin function defined?
rast <- genTestfn("rastrigin")
rast$fn

# Compare analytical and numerical gradient
shor <- genTestfn("Shor")
a_gr <- shor$gr
n_gr <- function(x) adagio:::ns.grad(shor$fn, x)    # internal gradient
a_gr(x); n_gr(x)

Run the code above in your browser using DataLab