Learn R Programming

gek (version 1.2.0)

banana: Rosenbrock's Banana Function

Description

Rosenbrock's banana function is defined by $$f_{\rm banana}(x_1, ..., x_d) = \sum_{k = 1}^{d - 1} (100 (x_{k+1} - x_k^2)^2 + (x_k - 1)^2)$$ with \(x_k \in [-5, 10]\) for \(k = 1, ..., d\) and \(d \geq 2\).

Usage

banana(x)
bananaGrad(x)

Value

banana returns the function value of Rosenbrock's banana function at x.

bananaGrad returns the gradient of Rosenbrock's banana function at x.

Arguments

x

a numeric vector of length d or a numeric matrix with n rows and d columns, where d must be greater than 1.

Author

Carmen van Meegen

Details

The gradient of Rosenbrock's banana function is $$\nabla f_{\rm banana}(x_1, ..., x_d) = \begin{pmatrix} -400 (x_2 - x_1)^2 x_1 + 2 (x_1 - 1) \\ 200 (x_2 - x_1)^2 - 400 x_2 (x_3 - x_2^2) + 2 (x_2 - 1) \\ \vdots \\ 200 (x_{d-1} - x_{d-2})^2 - 400 x_{d-1} (x_d - x_{d-1}^2) + 2 (x_{d-1} - 1) \\ 200 (x_d - x_{d -1}^2)\end{pmatrix}.$$

Rosenbrock's banana function has one global minimum \(f_{\rm banana}(x^{\star}) = 0\) at \(x^{\star} = (1,\dots, 1)\).

References

Jamil, M. and Yang, X.-S. (2013). A Literature Survey of Benchmark Functions for Global Optimization Problems. International Journal of Mathematical Modelling and Numerical Optimisation, 4(2):150-–194. tools:::Rd_expr_doi("10.1504/IJMMNO.2013.055204").

Rosenbrock, H. H. (1960). An Automatic Method for Finding the Greatest or least Value of a Function. The Computer Journal, 3(3):175--184. tools:::Rd_expr_doi("10.1093/comjnl/3.3.175").

Surjanovic, S. and Bingham, D. (2013). Virtual Library of Simulation Experiments: Test Functions and Datasets. https://www.sfu.ca/~ssurjano/ (retrieved January 19, 2024).

See Also

testfunctions for further test functions.

Examples

Run this code
# Contour plot of Rosenbrock's banana function with gradient field
n.grid <- 50
x1 <- seq(-2, 2, length = n.grid)
x2 <- seq(-1, 3, length = n.grid)
y <- outer(x1, x2, function(x1, x2) banana(cbind(x1, x2)))
contour(x1, x2, y, xaxs = "i", yaxs = "i", nlevels = 25, xlab = "x1", ylab = "x2")

x <- expand.grid(seq(-2, 2, length = 25), seq(-1, 3, length = 25))
gradient <- bananaGrad(x)
vectorfield(x, gradient, col = 4, scale = 1)
vectorfield(x, gradient, col = 4, scale = 1, max.len = 0.2)

# Perspective plot of Rosenbrock's banana function
col.pal <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow",
	"#FF7F00", "red", "#7F0000"))
colors <- col.pal(100)
y.facet.center <- (y[-1, -1] + y[-1, -n.grid] + y[-n.grid, -1] + y[-n.grid, -n.grid])/4
y.facet.range <- cut(y.facet.center, 100)
persp(x1, x2, y, phi = 30, theta = -315, expand = 0.75, ticktype = "detailed", 
	col = colors[y.facet.range])

Run the code above in your browser using DataLab