astamm / nloptr

nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.
https://astamm.github.io/nloptr/
Other
106 stars 34 forks source link

nelder mead example references undefined rosenbrock function #75

Closed ras44 closed 2 years ago

ras44 commented 3 years ago

The nelder mean example linked to below does not define the rosenbrock function used:

https://github.com/jyypma/nloptr/blob/69b2128533e4b8cd6b864eda19b9ed5897a3120e/man/neldermead.Rd#L65

Might want to include:

rosenbrock <- function(x) { ## Rosenbrock Banana function
    100 * (x[2] - x[1]^2)^2 + (1 - x[1])^2 + 100 * (x[3] - x[2]^2)^2 + (1 - x[2])^2
}

## Not run:
# Bounded version of Nelder-Mead
lower <- c(-Inf, 0, 0)
upper <- c( Inf, 0.5, 1)
x0 <- c(0, 0.1, 0.1)
S <- neldermead(c(0, 0.1, 0.1), rosenbrock, lower, upper, nl.info = TRUE)
# $xmin = c(0.7085595, 0.5000000, 0.2500000)
# $fmin = 0.3353605
## End(Not run)