nloptr/ 0000755 0001762 0000144 00000000000 14174313043 011570 5 ustar ligges users nloptr/NAMESPACE 0000644 0001762 0000144 00000001050 14172047663 013015 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(print,nloptr)
export(auglag)
export(bobyqa)
export(ccsaq)
export(check.derivatives)
export(cobyla)
export(crs2lm)
export(direct)
export(directL)
export(is.nloptr)
export(isres)
export(lbfgs)
export(mlsl)
export(mma)
export(neldermead)
export(newuoa)
export(nl.grad)
export(nl.jacobian)
export(nl.opts)
export(nloptr)
export(nloptr.get.default.options)
export(nloptr.print.options)
export(sbplx)
export(slsqp)
export(stogo)
export(tnewton)
export(varmetric)
useDynLib(nloptr, .registration = TRUE)
nloptr/tools/ 0000755 0001762 0000144 00000000000 14171354111 012726 5 ustar ligges users nloptr/tools/cmake_call.sh 0000755 0001762 0000144 00000001452 14172020027 015337 0 ustar ligges users #! /bin/sh
: ${R_HOME=$(R RHOME)}
RSCRIPT_BIN=${R_HOME}/bin/Rscript
NCORES=`${RSCRIPT_BIN} -e "cat(min(2, parallel::detectCores(logical = FALSE)))"`
cd src
#### CMAKE CONFIGURATION ####
. ./scripts/cmake_config.sh
# Compile NLOpt from source
sh ./scripts/nlopt_download.sh ${RSCRIPT_BIN}
dot() { file=$1; shift; . "$file"; }
dot ./scripts/r_config.sh ""
${CMAKE_BIN} \
-D BUILD_SHARED_LIBS=OFF \
-D CMAKE_BUILD_TYPE=Release \
-D INSTALL_LIB_DIR=nlopt/lib \
-D CMAKE_AR=${AR} \
-D CMAKE_RANLIB=${RANLIB} \
-D NLOPT_CXX=ON \
-D NLOPT_GUILE=OFF \
-D NLOPT_MATLAB=OFF \
-D NLOPT_OCTAVE=OFF \
-D NLOPT_PYTHON=OFF \
-D NLOPT_SWIG=OFF \
-D NLOPT_TESTS=OFF \
-S nlopt-src \
-B nlopt-build
sh ./scripts/nlopt_install.sh ${CMAKE_BIN} ${NCORES} ""
# Cleanup
sh ./scripts/nlopt_cleanup.sh
nloptr/tools/winlibs.R 0000644 0001762 0000144 00000000477 14171354111 014530 0 ustar ligges users # Build against mingw-w64 build of nlopt
if(!file.exists("../windows/nlopt-2.7.1/include/nlopt.hpp")){
download.file("https://github.com/rwinlib/nlopt/archive/v2.7.1.zip", "lib.zip", quiet = TRUE)
dir.create("../windows", showWarnings = FALSE)
unzip("lib.zip", exdir = "../windows")
unlink("lib.zip")
}
nloptr/README.md 0000644 0001762 0000144 00000011225 14172072614 013054 0 ustar ligges users
# [**nloptr**](https://astamm.github.io/nloptr/)
[](https://github.com/astamm/nloptr/actions)
[](https://github.com/astamm/nloptr/actions)
[](https://app.codecov.io/gh/astamm/nloptr?branch=master)
[](https://github.com/astamm/nloptr/actions)
[](https://CRAN.R-project.org/package=nloptr)
[**nloptr**](https://astamm.github.io/nloptr/) is an R interface to
[NLopt](https://nlopt.readthedocs.io/en/latest/), a free/open-source
library for nonlinear optimization started by Steven G. Johnson,
providing a common interface for a number of different free optimization
routines available online as well as original implementations of various
other algorithms. It can be used to solve general nonlinear programming
problems with nonlinear constraints and lower and upper bounds for the
controls, such as
min*x* ∈ ℝ*n* *f*(*x*),
s.t. *g*(*x*) ≤ 0, *h*(*x*) = 0 and ℓ ≤ *x* ≤ *u*.
The [NLopt](https://nlopt.readthedocs.io/en/latest/) library is
available under the GNU Lesser General Public License (LGPL), and the
copyrights are owned by a variety of authors. See the
[website](https://nlopt.readthedocs.io/en/latest/Citing_NLopt/) for
information on how to cite NLopt and the algorithms you use.
## Installation
### Windows
On Windows, either the latest version `2.7.1` of
[NLopt](https://nlopt.readthedocs.io/en/latest/) from
[rwinlib](https://github.com/rwinlib/nlopt) (windows-release) or a
`v2.6` build from the `rtools42` toolchain (windows2022-devel) is used.
So there is nothing else to be done.
### Linux and macOS
On Unix-like platforms, we use `pkg-config` to find a suitable system
build of [NLopt](https://nlopt.readthedocs.io/en/latest/) (i.e. with
version `>= 2.7.0`).
- If it is found it is used.
- Otherwise, [NLopt](https://nlopt.readthedocs.io/en/latest/) 2.7.1 is
built from included sources using [CMake](https://cmake.org). In
this case, a binary of [CMake](https://cmake.org) stored in
environment variable `CMAKE_BIN` is searched on the `PATH` and,
alternatively, on a macOS-specific location. If that variable cannot
be set, install will abort suggesting ways of installing
[CMake](https://cmake.org).
### Installing [CMake](https://cmake.org) (macOS and Linux only)
You can install [CMake](https://cmake.org) by following [CMake
installation instructions](https://cmake.org/install/). The important
thing is that you add the [CMake](https://cmake.org) binary to your
`PATH`:
- On macOS, you can install [CMake](https://cmake.org) and then run
it. In the menu bar, there is an item *How to Install For Command
Line Use* which you can click on to have proper instructions on how
to update your `PATH`. Note that the location of the
[CMake](https://cmake.org) binary is always
`/Applications/CMake.app/Contents/bin/cmake`. Hence,
[**nloptr**](https://astamm.github.io/nloptr/) knows where to find
it even if you do not update your `PATH`.
- On Linux, it will be automatically added unless you specifically
change the default installation directory before building
[CMake](https://cmake.org).
Alternatively, you can set an environment variable `CMAKE_BIN` pointing
to a [CMake](https://cmake.org) binary of your liking on your computer
for [**nloptr**](https://astamm.github.io/nloptr/) to use.
### Installing [**nloptr**](https://astamm.github.io/nloptr/)
You can install [**nloptr**](https://astamm.github.io/nloptr/) from CRAN
using:
install.packages("nloptr")
Alternatively, you can install the development version from GitHub:
# install.packages("remotes")
remotes::install_github("astamm/nloptr")
## Acknowledgments
I would like to express my sincere gratitude to [Dirk
Eddelbuettel](https://github.com/eddelbuettel), [Jeroen
Ooms](https://github.com/jeroen), [Tomas
Kalibera](https://github.com/kalibera), Uwe Ligges and [Jelmer
Ypma](https://github.com/jyypma) for their contributions and the very
instructive discussions about the pros and cons of various build
strategies in R packages.
## Reference
Steven G. Johnson, The NLopt nonlinear-optimization package,
nloptr/man/ 0000755 0001762 0000144 00000000000 14167114573 012354 5 ustar ligges users nloptr/man/ccsaq.Rd 0000644 0001762 0000144 00000006636 14167114573 013750 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ccsaq.R
\name{ccsaq}
\alias{ccsaq}
\title{Conservative Convex Separable Approximation with Affine Approximation plus Quadratic Penalty}
\usage{
ccsaq(
x0,
fn,
gr = NULL,
lower = NULL,
upper = NULL,
hin = NULL,
hinjac = NULL,
nl.info = FALSE,
control = list(),
...
)
}
\arguments{
\item{x0}{starting point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{gr}{gradient of function \code{fn}; will be calculated numerically if
not specified.}
\item{lower, upper}{lower and upper bound constraints.}
\item{hin}{function defining the inequality constraints, that is
\code{hin>=0} for all components.}
\item{hinjac}{Jacobian of function \code{hin}; will be calculated
numerically if not specified.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{control}{list of options, see \code{nl.opts} for help.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 1)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
This is a variant of CCSA ("conservative convex separable approximation")
which, instead of constructing local MMA approximations, constructs simple
quadratic approximations (or rather, affine approximations plus a quadratic
penalty term to stay conservative)
}
\note{
``Globally convergent'' does not mean that this algorithm converges to
the global optimum; it means that it is guaranteed to converge to some local
minimum from any feasible starting point.
}
\examples{
## Solve the Hock-Schittkowski problem no. 100 with analytic gradients
x0.hs100 <- c(1, 2, 0, 4, 0, 1, 1)
fn.hs100 <- function(x) {
(x[1]-10)^2 + 5*(x[2]-12)^2 + x[3]^4 + 3*(x[4]-11)^2 + 10*x[5]^6 +
7*x[6]^2 + x[7]^4 - 4*x[6]*x[7] - 10*x[6] - 8*x[7]
}
hin.hs100 <- function(x) {
h <- numeric(4)
h[1] <- 127 - 2*x[1]^2 - 3*x[2]^4 - x[3] - 4*x[4]^2 - 5*x[5]
h[2] <- 282 - 7*x[1] - 3*x[2] - 10*x[3]^2 - x[4] + x[5]
h[3] <- 196 - 23*x[1] - x[2]^2 - 6*x[6]^2 + 8*x[7]
h[4] <- -4*x[1]^2 - x[2]^2 + 3*x[1]*x[2] -2*x[3]^2 - 5*x[6] +11*x[7]
return(h)
}
gr.hs100 <- function(x) {
c( 2 * x[1] - 20,
10 * x[2] - 120,
4 * x[3]^3,
6 * x[4] - 66,
60 * x[5]^5,
14 * x[6] - 4 * x[7] - 10,
4 * x[7]^3 - 4 * x[6] - 8 )}
hinjac.hs100 <- function(x) {
matrix(c(4*x[1], 12*x[2]^3, 1, 8*x[4], 5, 0, 0,
7, 3, 20*x[3], 1, -1, 0, 0,
23, 2*x[2], 0, 0, 0, 12*x[6], -8,
8*x[1]-3*x[2], 2*x[2]-3*x[1], 4*x[3], 0, 0, 5, -11), 4, 7, byrow=TRUE)
}
# incorrect result with exact jacobian
S <- ccsaq(x0.hs100, fn.hs100, gr = gr.hs100,
hin = hin.hs100, hinjac = hinjac.hs100,
nl.info = TRUE, control = list(xtol_rel = 1e-8))
\donttest{
S <- ccsaq(x0.hs100, fn.hs100, hin = hin.hs100,
nl.info = TRUE, control = list(xtol_rel = 1e-8))
}
}
\references{
Krister Svanberg, ``A class of globally convergent optimization
methods based on conservative convex separable approximations,'' SIAM J.
Optim. 12 (2), p. 555-573 (2002).
}
\seealso{
\code{\link{mma}}
}
nloptr/man/sbplx.Rd 0000644 0001762 0000144 00000004246 14167114573 014001 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nm.R
\name{sbplx}
\alias{sbplx}
\title{Subplex Algorithm}
\usage{
sbplx(
x0,
fn,
lower = NULL,
upper = NULL,
nl.info = FALSE,
control = list(),
...
)
}
\arguments{
\item{x0}{starting point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{lower, upper}{lower and upper bound constraints.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{control}{list of options, see \code{nl.opts} for help.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
Subplex is a variant of Nelder-Mead that uses Nelder-Mead on a sequence of
subspaces.
}
\details{
SUBPLEX is claimed to be much more efficient and robust than the original
Nelder-Mead, while retaining the latter's facility with discontinuous
objectives.
This implementation has explicit support for bound constraints (via the
method in the Box paper as described on the \code{neldermead} help page).
}
\note{
It is the request of Tom Rowan that reimplementations of his algorithm
shall not use the name `subplex'.
}
\examples{
# Fletcher and Powell's helic valley
fphv <- function(x)
100*(x[3] - 10*atan2(x[2], x[1])/(2*pi))^2 +
(sqrt(x[1]^2 + x[2]^2) - 1)^2 +x[3]^2
x0 <- c(-1, 0, 0)
sbplx(x0, fphv) # 1 0 0
# Powell's Singular Function (PSF)
psf <- function(x) (x[1] + 10*x[2])^2 + 5*(x[3] - x[4])^2 +
(x[2] - 2*x[3])^4 + 10*(x[1] - x[4])^4
x0 <- c(3, -1, 0, 1)
sbplx(x0, psf, control = list(maxeval = Inf, ftol_rel = 1e-6)) # 0 0 0 0 (?)
}
\references{
T. Rowan, ``Functional Stability Analysis of Numerical
Algorithms'', Ph.D. thesis, Department of Computer Sciences, University of
Texas at Austin, 1990.
}
\seealso{
\code{subplex::subplex}
}
nloptr/man/crs2lm.Rd 0000644 0001762 0000144 00000006556 14167114573 014061 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/global.R
\name{crs2lm}
\alias{crs2lm}
\title{Controlled Random Search}
\usage{
crs2lm(
x0,
fn,
lower,
upper,
maxeval = 10000,
pop.size = 10 * (length(x0) + 1),
ranseed = NULL,
xtol_rel = 1e-06,
nl.info = FALSE,
...
)
}
\arguments{
\item{x0}{initial point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{lower, upper}{lower and upper bound constraints.}
\item{maxeval}{maximum number of function evaluations.}
\item{pop.size}{population size.}
\item{ranseed}{prescribe seed for random number generator.}
\item{xtol_rel}{stopping criterion for relative change reached.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
The Controlled Random Search (CRS) algorithm (and in particular, the CRS2
variant) with the `local mutation' modification.
}
\details{
The CRS algorithms are sometimes compared to genetic algorithms, in that
they start with a random population of points, and randomly evolve these
points by heuristic rules. In this case, the evolution somewhat resembles a
randomized Nelder-Mead algorithm.
The published results for CRS seem to be largely empirical.
}
\note{
The initial population size for CRS defaults to \code{10x(n+1)} in
\code{n} dimensions, but this can be changed; the initial population must be
at least \code{n+1}.
}
\examples{
### Minimize the Hartmann6 function
hartmann6 <- function(x) {
n <- length(x)
a <- c(1.0, 1.2, 3.0, 3.2)
A <- matrix(c(10.0, 0.05, 3.0, 17.0,
3.0, 10.0, 3.5, 8.0,
17.0, 17.0, 1.7, 0.05,
3.5, 0.1, 10.0, 10.0,
1.7, 8.0, 17.0, 0.1,
8.0, 14.0, 8.0, 14.0), nrow=4, ncol=6)
B <- matrix(c(.1312,.2329,.2348,.4047,
.1696,.4135,.1451,.8828,
.5569,.8307,.3522,.8732,
.0124,.3736,.2883,.5743,
.8283,.1004,.3047,.1091,
.5886,.9991,.6650,.0381), nrow=4, ncol=6)
fun <- 0.0
for (i in 1:4) {
fun <- fun - a[i] * exp(-sum(A[i,]*(x-B[i,])^2))
}
return(fun)
}
S <- mlsl(x0 = rep(0, 6), hartmann6, lower = rep(0,6), upper = rep(1,6),
nl.info = TRUE, control=list(xtol_rel=1e-8, maxeval=1000))
## Number of Iterations....: 4050
## Termination conditions: maxeval: 10000 xtol_rel: 1e-06
## Number of inequality constraints: 0
## Number of equality constraints: 0
## Optimal value of objective function: -3.32236801141328
## Optimal value of controls:
## 0.2016893 0.1500105 0.4768738 0.2753326 0.3116516 0.6573004
}
\references{
W. L. Price, ``Global optimization by controlled random
search,'' J. Optim. Theory Appl. 40 (3), p. 333-348 (1983).
P. Kaelo and M. M. Ali, ``Some variants of the controlled random search
algorithm for global optimization,'' J. Optim. Theory Appl. 130 (2), 253-264
(2006).
}
nloptr/man/tnewton.Rd 0000644 0001762 0000144 00000004517 14167114573 014350 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tnewton.R
\name{tnewton}
\alias{tnewton}
\title{Preconditioned Truncated Newton}
\usage{
tnewton(
x0,
fn,
gr = NULL,
lower = NULL,
upper = NULL,
precond = TRUE,
restart = TRUE,
nl.info = FALSE,
control = list(),
...
)
}
\arguments{
\item{x0}{starting point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{gr}{gradient of function \code{fn}; will be calculated numerically if
not specified.}
\item{lower, upper}{lower and upper bound constraints.}
\item{precond}{logical; preset L-BFGS with steepest descent.}
\item{restart}{logical; restarting L-BFGS with steepest descent.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{control}{list of options, see \code{nl.opts} for help.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 1)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
Truncated Newton methods, also calledNewton-iterative methods, solve an
approximating Newton system using a conjugate-gradient approach and are
related to limited-memory BFGS.
}
\details{
Truncated Newton methods are based on approximating the objective with a
quadratic function and applying an iterative scheme such as the linear
conjugate-gradient algorithm.
}
\note{
Less reliable than Newton's method, but can handle very large
problems.
}
\examples{
flb <- function(x) {
p <- length(x)
sum(c(1, rep(4, p-1)) * (x - c(1, x[-p])^2)^2)
}
# 25-dimensional box constrained: par[24] is *not* at boundary
S <- tnewton(rep(3, 25), flb, lower=rep(2, 25), upper=rep(4, 25),
nl.info = TRUE, control = list(xtol_rel=1e-8))
## Optimal value of objective function: 368.105912874334
## Optimal value of controls: 2 ... 2 2.109093 4
}
\references{
R. S. Dembo and T. Steihaug, ``Truncated Newton algorithms for
large-scale optimization,'' Math. Programming 26, p. 190-212 (1982).
}
\seealso{
\code{\link{lbfgs}}
}
\author{
Hans W. Borchers
}
nloptr/man/cobyla.Rd 0000644 0001762 0000144 00000005571 14167114573 014124 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/cobyla.R
\name{cobyla}
\alias{cobyla}
\title{Constrained Optimization by Linear Approximations}
\usage{
cobyla(
x0,
fn,
lower = NULL,
upper = NULL,
hin = NULL,
nl.info = FALSE,
control = list(),
...
)
}
\arguments{
\item{x0}{starting point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{lower, upper}{lower and upper bound constraints.}
\item{hin}{function defining the inequality constraints, that is
\code{hin>=0} for all components.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{control}{list of options, see \code{nl.opts} for help.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
COBYLA is an algorithm for derivative-free optimization with nonlinear
inequality and equality constraints (but see below).
}
\details{
It constructs successive linear approximations of the objective function and
constraints via a simplex of n+1 points (in n dimensions), and optimizes
these approximations in a trust region at each step.
COBYLA supports equality constraints by transforming them into two
inequality constraints. As this does not give full satisfaction with the
implementation in NLOPT, it has not been made available here.
}
\note{
The original code, written in Fortran by Powell, was converted in C
for the Scipy project.
}
\examples{
### Solve Hock-Schittkowski no. 100
x0.hs100 <- c(1, 2, 0, 4, 0, 1, 1)
fn.hs100 <- function(x) {
(x[1]-10)^2 + 5*(x[2]-12)^2 + x[3]^4 + 3*(x[4]-11)^2 + 10*x[5]^6 +
7*x[6]^2 + x[7]^4 - 4*x[6]*x[7] - 10*x[6] - 8*x[7]
}
hin.hs100 <- function(x) {
h <- numeric(4)
h[1] <- 127 - 2*x[1]^2 - 3*x[2]^4 - x[3] - 4*x[4]^2 - 5*x[5]
h[2] <- 282 - 7*x[1] - 3*x[2] - 10*x[3]^2 - x[4] + x[5]
h[3] <- 196 - 23*x[1] - x[2]^2 - 6*x[6]^2 + 8*x[7]
h[4] <- -4*x[1]^2 - x[2]^2 + 3*x[1]*x[2] -2*x[3]^2 - 5*x[6] +11*x[7]
return(h)
}
S <- cobyla(x0.hs100, fn.hs100, hin = hin.hs100,
nl.info = TRUE, control = list(xtol_rel = 1e-8, maxeval = 2000))
## Optimal value of objective function: 680.630057374431
}
\references{
M. J. D. Powell, ``A direct search optimization method that
models the objective and constraint functions by linear interpolation,'' in
Advances in Optimization and Numerical Analysis, eds. S. Gomez and J.-P.
Hennart (Kluwer Academic: Dordrecht, 1994), p. 51-67.
}
\seealso{
\code{\link{bobyqa}}, \code{\link{newuoa}}
}
\author{
Hans W. Borchers
}
nloptr/man/isres.Rd 0000644 0001762 0000144 00000005375 14167114573 014002 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/global.R
\name{isres}
\alias{isres}
\title{Improved Stochastic Ranking Evolution Strategy}
\usage{
isres(
x0,
fn,
lower,
upper,
hin = NULL,
heq = NULL,
maxeval = 10000,
pop.size = 20 * (length(x0) + 1),
xtol_rel = 1e-06,
nl.info = FALSE,
...
)
}
\arguments{
\item{x0}{initial point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{lower, upper}{lower and upper bound constraints.}
\item{hin}{function defining the inequality constraints, that is
\code{hin>=0} for all components.}
\item{heq}{function defining the equality constraints, that is \code{heq==0}
for all components.}
\item{maxeval}{maximum number of function evaluations.}
\item{pop.size}{population size.}
\item{xtol_rel}{stopping criterion for relative change reached.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
The Improved Stochastic Ranking Evolution Strategy (ISRES) algorithm for
nonlinearly constrained global optimization (or at least semi-global:
although it has heuristics to escape local optima.
}
\details{
The evolution strategy is based on a combination of a mutation rule (with a
log-normal step-size update and exponential smoothing) and differential
variation (a Nelder-Mead-like update rule). The fitness ranking is simply
via the objective function for problems without nonlinear constraints, but
when nonlinear constraints are included the stochastic ranking proposed by
Runarsson and Yao is employed.
This method supports arbitrary nonlinear inequality and equality constraints
in addition to the bound constraints.
}
\note{
The initial population size for CRS defaults to \code{20x(n+1)} in
\code{n} dimensions, but this can be changed; the initial population must be
at least \code{n+1}.
}
\examples{
### Rosenbrock Banana objective function
fn <- function(x)
return( 100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2 )
x0 <- c( -1.2, 1 )
lb <- c( -3, -3 )
ub <- c( 3, 3 )
isres(x0 = x0, fn = fn, lower = lb, upper = ub)
}
\references{
Thomas Philip Runarsson and Xin Yao, ``Search biases in
constrained evolutionary optimization,'' IEEE Trans. on Systems, Man, and
Cybernetics Part C: Applications and Reviews, vol. 35 (no. 2), pp. 233-243
(2005).
}
\author{
Hans W. Borchers
}
nloptr/man/nloptr-package.Rd 0000644 0001762 0000144 00000011115 14167114573 015551 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/nloptr-package.R
\docType{package}
\name{nloptr-package}
\alias{nloptr-package}
\title{R interface to NLopt}
\description{
nloptr is an R interface to NLopt, a free/open-source library for nonlinear
optimization started by Steven G. Johnson, providing a common interface for
a number of different free optimization routines available online as well as
original implementations of various other algorithms. The NLopt library is
available under the GNU Lesser General Public License (LGPL), and the
copyrights are owned by a variety of authors. Most of the information here
has been taken from \href{https://nlopt.readthedocs.io/en/latest/}{the NLopt website},
where more details are available.
}
\details{
NLopt addresses general nonlinear optimization problems of the form:
min f(x) x in R^n
s.t. g(x) <= 0 h(x) = 0 lb <= x <= ub
where f is the objective function to be minimized and x represents the n
optimization parameters. This problem may optionally be subject to the bound
constraints (also called box constraints), lb and ub. For partially or
totally unconstrained problems the bounds can take -Inf or Inf. One may also
optionally have m nonlinear inequality constraints (sometimes called a
nonlinear programming problem), which can be specified in g(x), and equality
constraints that can be specified in h(x). Note that not all of the
algorithms in NLopt can handle constraints.
An optimization problem can be solved with the general nloptr interface, or
using one of the wrapper functions for the separate algorithms; auglag,
bobyqa, cobyla, crs2lm, direct, lbfgs, mlsl, mma, neldermead, newuoa, sbplx,
slsqp, stogo, tnewton, varmetric.
\tabular{ll}{ Package: \tab nloptr\cr Type: \tab Package\cr Version: \tab
0.9.9\cr Date: \tab 2013-11-22\cr License: \tab L-GPL\cr LazyLoad: \tab
yes\cr }
}
\note{
See ?nloptr for more examples.
}
\examples{
# Example problem, number 71 from the Hock-Schittkowsky test suite.
#
# \min_{x} x1*x4*(x1 + x2 + x3) + x3
# s.t.
# x1*x2*x3*x4 >= 25
# x1^2 + x2^2 + x3^2 + x4^2 = 40
# 1 <= x1,x2,x3,x4 <= 5
#
# we re-write the inequality as
# 25 - x1*x2*x3*x4 <= 0
#
# and the equality as
# x1^2 + x2^2 + x3^2 + x4^2 - 40 = 0
#
# x0 = (1,5,5,1)
#
# optimal solution = (1.00000000, 4.74299963, 3.82114998, 1.37940829)
library('nloptr')
#
# f(x) = x1*x4*(x1 + x2 + x3) + x3
#
eval_f <- function( x ) {
return( list( "objective" = x[1]*x[4]*(x[1] + x[2] + x[3]) + x[3],
"gradient" = c( x[1] * x[4] + x[4] * (x[1] + x[2] + x[3]),
x[1] * x[4],
x[1] * x[4] + 1.0,
x[1] * (x[1] + x[2] + x[3]) ) ) )
}
# constraint functions
# inequalities
eval_g_ineq <- function( x ) {
constr <- c( 25 - x[1] * x[2] * x[3] * x[4] )
grad <- c( -x[2]*x[3]*x[4],
-x[1]*x[3]*x[4],
-x[1]*x[2]*x[4],
-x[1]*x[2]*x[3] )
return( list( "constraints"=constr, "jacobian"=grad ) )
}
# equalities
eval_g_eq <- function( x ) {
constr <- c( x[1]^2 + x[2]^2 + x[3]^2 + x[4]^2 - 40 )
grad <- c( 2.0*x[1],
2.0*x[2],
2.0*x[3],
2.0*x[4] )
return( list( "constraints"=constr, "jacobian"=grad ) )
}
# initial values
x0 <- c( 1, 5, 5, 1 )
# lower and upper bounds of control
lb <- c( 1, 1, 1, 1 )
ub <- c( 5, 5, 5, 5 )
local_opts <- list( "algorithm" = "NLOPT_LD_MMA",
"xtol_rel" = 1.0e-7 )
opts <- list( "algorithm" = "NLOPT_LD_AUGLAG",
"xtol_rel" = 1.0e-7,
"maxeval" = 1000,
"local_opts" = local_opts )
res <- nloptr( x0=x0,
eval_f=eval_f,
lb=lb,
ub=ub,
eval_g_ineq=eval_g_ineq,
eval_g_eq=eval_g_eq,
opts=opts)
print( res )
}
\references{
Steven G. Johnson, The NLopt nonlinear-optimization package,
\url{https://nlopt.readthedocs.io/en/latest/}
}
\seealso{
\code{\link{optim}} \code{\link{nlm}} \code{\link{nlminb}}
\code{Rsolnp::Rsolnp} \code{Rsolnp::solnp} \code{\link{nloptr}}
\code{\link{auglag}} \code{\link{bobyqa}} \code{\link{cobyla}}
\code{\link{crs2lm}} \code{\link{direct}} \code{\link{isres}}
\code{\link{lbfgs}} \code{\link{mlsl}} \code{\link{mma}}
\code{\link{neldermead}} \code{\link{newuoa}} \code{\link{sbplx}}
\code{\link{slsqp}} \code{\link{stogo}} \code{\link{tnewton}}
\code{\link{varmetric}}
}
\author{
Steven G. Johnson and others (C code) \cr Jelmer Ypma (R interface)
\cr Hans W. Borchers (wrappers)
}
\keyword{interface}
\keyword{optimize}
nloptr/man/direct.Rd 0000644 0001762 0000144 00000010236 14167114573 014117 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/direct.R
\name{direct}
\alias{direct}
\alias{directL}
\title{DIviding RECTangles Algorithm for Global Optimization}
\usage{
direct(
fn,
lower,
upper,
scaled = TRUE,
original = FALSE,
nl.info = FALSE,
control = list(),
...
)
directL(
fn,
lower,
upper,
randomized = FALSE,
original = FALSE,
nl.info = FALSE,
control = list(),
...
)
}
\arguments{
\item{fn}{objective function that is to be minimized.}
\item{lower, upper}{lower and upper bound constraints.}
\item{scaled}{logical; shall the hypercube be scaled before starting.}
\item{original}{logical; whether to use the original implementation by
Gablonsky -- the performance is mostly similar.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{control}{list of options, see \code{nl.opts} for help.}
\item{...}{additional arguments passed to the function.}
\item{randomized}{logical; shall some randomization be used to decide which
dimension to halve next in the case of near-ties.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
DIRECT is a deterministic search algorithm based on systematic division of
the search domain into smaller and smaller hyperrectangles. The DIRECT_L
makes the algorithm more biased towards local search (more efficient for
functions without too many minima).
}
\details{
The DIRECT and DIRECT-L algorithms start by rescaling the bound constraints
to a hypercube, which gives all dimensions equal weight in the search
procedure. If your dimensions do not have equal weight, e.g. if you have a
``long and skinny'' search space and your function varies at about the same
speed in all directions, it may be better to use unscaled variant of the
DIRECT algorithm.
The algorithms only handle finite bound constraints which must be provided.
The original versions may include some support for arbitrary nonlinear
inequality, but this has not been tested.
The original versions do not have randomized or unscaled variants, so these
options will be disregarded for these versions.
}
\note{
The DIRECT_L algorithm should be tried first.
}
\examples{
### Minimize the Hartmann6 function
hartmann6 <- function(x) {
n <- length(x)
a <- c(1.0, 1.2, 3.0, 3.2)
A <- matrix(c(10.0, 0.05, 3.0, 17.0,
3.0, 10.0, 3.5, 8.0,
17.0, 17.0, 1.7, 0.05,
3.5, 0.1, 10.0, 10.0,
1.7, 8.0, 17.0, 0.1,
8.0, 14.0, 8.0, 14.0), nrow=4, ncol=6)
B <- matrix(c(.1312,.2329,.2348,.4047,
.1696,.4135,.1451,.8828,
.5569,.8307,.3522,.8732,
.0124,.3736,.2883,.5743,
.8283,.1004,.3047,.1091,
.5886,.9991,.6650,.0381), nrow=4, ncol=6)
fun <- 0.0
for (i in 1:4) {
fun <- fun - a[i] * exp(-sum(A[i,]*(x-B[i,])^2))
}
return(fun)
}
S <- directL(hartmann6, rep(0,6), rep(1,6),
nl.info = TRUE, control=list(xtol_rel=1e-8, maxeval=1000))
## Number of Iterations....: 500
## Termination conditions: stopval: -Inf
## xtol_rel: 1e-08, maxeval: 500, ftol_rel: 0, ftol_abs: 0
## Number of inequality constraints: 0
## Number of equality constraints: 0
## Current value of objective function: -3.32236800687327
## Current value of controls:
## 0.2016884 0.1500025 0.4768667 0.2753391 0.311648 0.6572931
}
\references{
D. R. Jones, C. D. Perttunen, and B. E. Stuckmann,
``Lipschitzian optimization without the lipschitz constant,'' J.
Optimization Theory and Applications, vol. 79, p. 157 (1993).
J. M. Gablonsky and C. T. Kelley, ``A locally-biased form of the DIRECT
algorithm," J. Global Optimization, vol. 21 (1), p. 27-37 (2001).
}
\seealso{
The \code{dfoptim} package will provide a pure R version of this
algorithm.
}
\author{
Hans W. Borchers
}
nloptr/man/stogo.Rd 0000644 0001762 0000144 00000004307 14167114573 014002 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/global.R
\name{stogo}
\alias{stogo}
\title{Stochastic Global Optimization}
\usage{
stogo(
x0,
fn,
gr = NULL,
lower = NULL,
upper = NULL,
maxeval = 10000,
xtol_rel = 1e-06,
randomized = FALSE,
nl.info = FALSE,
...
)
}
\arguments{
\item{x0}{initial point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{gr}{optional gradient of the objective function.}
\item{lower, upper}{lower and upper bound constraints.}
\item{maxeval}{maximum number of function evaluations.}
\item{xtol_rel}{stopping criterion for relative change reached.}
\item{randomized}{logical; shall a randomizing variant be used?}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
StoGO is a global optimization algorithm that works by systematically
dividing the search space into smaller hyper-rectangles.
}
\details{
StoGO is a global optimization algorithm that works by systematically
dividing the search space (which must be bound-constrained) into smaller
hyper-rectangles via a branch-and-bound technique, and searching them by a
gradient-based local-search algorithm (a BFGS variant), optionally including
some randomness.
}
\note{
Only bound-constrained problems are supported by this algorithm.
}
\examples{
### Rosenbrock Banana objective function
fn <- function(x)
return( 100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2 )
x0 <- c( -1.2, 1 )
lb <- c( -3, -3 )
ub <- c( 3, 3 )
stogo(x0 = x0, fn = fn, lower = lb, upper = ub)
}
\references{
S. Zertchaninov and K. Madsen, ``A C++ Programme for Global
Optimization,'' IMM-REP-1998-04, Department of Mathematical Modelling,
Technical University of Denmark.
}
\author{
Hans W. Borchers
}
nloptr/man/nl.grad.Rd 0000644 0001762 0000144 00000002213 14167114573 014166 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gradients.R
\name{nl.grad}
\alias{nl.grad}
\alias{nl.jacobian}
\title{Numerical Gradients and Jacobians}
\usage{
nl.grad(x0, fn, heps = .Machine$double.eps^(1/3), ...)
}
\arguments{
\item{x0}{point as a vector where the gradient is to be calculated.}
\item{fn}{scalar function of one or several variables.}
\item{heps}{step size to be used.}
\item{\dots}{additional arguments passed to the function.}
}
\value{
\code{grad} returns the gradient as a vector; \code{jacobian}
returns the Jacobian as a matrix of usual dimensions.
}
\description{
Provides numerical gradients and jacobians.
}
\details{
Both functions apply the ``central difference formula'' with step size as
recommended in the literature.
}
\examples{
fn1 <- function(x) sum(x^2)
nl.grad(seq(0, 1, by = 0.2), fn1)
## [1] 0.0 0.4 0.8 1.2 1.6 2.0
nl.grad(rep(1, 5), fn1)
## [1] 2 2 2 2 2
fn2 <- function(x) c(sin(x), cos(x))
x <- (0:1)*2*pi
nl.jacobian(x, fn2)
## [,1] [,2]
## [1,] 1 0
## [2,] 0 1
## [3,] 0 0
## [4,] 0 0
}
\author{
Hans W. Borchers
}
nloptr/man/print.nloptr.Rd 0000644 0001762 0000144 00000001721 14167114573 015315 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/print.nloptr.R
\name{print.nloptr}
\alias{print.nloptr}
\title{Print results after running nloptr}
\usage{
\method{print}{nloptr}(x, show.controls = TRUE, ...)
}
\arguments{
\item{x}{object containing result from minimization.}
\item{show.controls}{Logical or vector with indices. Should we show the
value of the control variables in the solution? If \code{show.controls} is a
vector with indices, it is used to select which control variables should be
shown. This can be useful if the model contains a set of parameters of
interest and a set of nuisance parameters that are not of immediate
interest.}
\item{...}{further arguments passed to or from other methods.}
}
\description{
This function prints the nloptr object that holds the results from a
minimization using \code{nloptr}.
}
\seealso{
\code{\link[nloptr:nloptr]{nloptr}}
}
\author{
Jelmer Ypma
}
\keyword{interface}
\keyword{optimize}
nloptr/man/varmetric.Rd 0000644 0001762 0000144 00000004307 14167114573 014643 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/varmetric.R
\name{varmetric}
\alias{varmetric}
\title{Shifted Limited-memory Variable-metric}
\usage{
varmetric(
x0,
fn,
gr = NULL,
rank2 = TRUE,
lower = NULL,
upper = NULL,
nl.info = FALSE,
control = list(),
...
)
}
\arguments{
\item{x0}{initial point for searching the optimum.}
\item{fn}{objective function to be minimized.}
\item{gr}{gradient of function \code{fn}; will be calculated numerically if
not specified.}
\item{rank2}{logical; if true uses a rank-2 update method, else rank-1.}
\item{lower, upper}{lower and upper bound constraints.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{control}{list of control parameters, see \code{nl.opts} for help.}
\item{...}{further arguments to be passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
Shifted limited-memory variable-metric algorithm.
}
\details{
Variable-metric methods are a variant of the quasi-Newton methods,
especially adapted to large-scale unconstrained (or bound constrained)
minimization.
}
\note{
Based on L. Luksan's Fortran implementation of a shifted
limited-memory variable-metric algorithm.
}
\examples{
flb <- function(x) {
p <- length(x)
sum(c(1, rep(4, p-1)) * (x - c(1, x[-p])^2)^2)
}
# 25-dimensional box constrained: par[24] is *not* at the boundary
S <- varmetric(rep(3, 25), flb, lower=rep(2, 25), upper=rep(4, 25),
nl.info = TRUE, control = list(xtol_rel=1e-8))
## Optimal value of objective function: 368.105912874334
## Optimal value of controls: 2 ... 2 2.109093 4
}
\references{
J. Vlcek and L. Luksan, ``Shifted limited-memory variable metric
methods for large-scale unconstrained minimization,'' J. Computational Appl.
Math. 186, p. 365-390 (2006).
}
\seealso{
\code{\link{lbfgs}}
}
\author{
Hans W. Borchers
}
nloptr/man/mlsl.Rd 0000644 0001762 0000144 00000010037 14167114573 013613 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mlsl.R
\name{mlsl}
\alias{mlsl}
\title{Multi-level Single-linkage}
\usage{
mlsl(
x0,
fn,
gr = NULL,
lower,
upper,
local.method = "LBFGS",
low.discrepancy = TRUE,
nl.info = FALSE,
control = list(),
...
)
}
\arguments{
\item{x0}{initial point for searching the optimum.}
\item{fn}{objective function that is to be minimized.}
\item{gr}{gradient of function \code{fn}; will be calculated numerically if
not specified.}
\item{lower, upper}{lower and upper bound constraints.}
\item{local.method}{only \code{BFGS} for the moment.}
\item{low.discrepancy}{logical; shall a low discrepancy variation be used.}
\item{nl.info}{logical; shall the original NLopt info been shown.}
\item{control}{list of options, see \code{nl.opts} for help.}
\item{...}{additional arguments passed to the function.}
}
\value{
List with components:
\item{par}{the optimal solution found so far.}
\item{value}{the function value corresponding to \code{par}.}
\item{iter}{number of (outer) iterations, see \code{maxeval}.}
\item{convergence}{integer code indicating successful completion (> 0)
or a possible error number (< 0).}
\item{message}{character string produced by NLopt and giving additional
information.}
}
\description{
The ``Multi-Level Single-Linkage'' (MLSL) algorithm for global optimization
searches by a sequence of local optimizations from random starting points.
A modification of MLSL is included using a low-discrepancy sequence (LDS)
instead of pseudorandom numbers.
}
\details{
MLSL is a \verb{multistart' algorithm: it works by doing a sequence of local optimizations (using some other local optimization algorithm) from random or low-discrepancy starting points. MLSL is distinguished, however by a }clustering' heuristic that helps it to avoid repeated searches of the same
local optima, and has some theoretical guarantees of finding all local
optima in a finite number of local minimizations.
The local-search portion of MLSL can use any of the other algorithms in
NLopt, and in particular can use either gradient-based or derivative-free
algorithms. For this wrapper only gradient-based \code{L-BFGS} is available
as local method.
}
\note{
If you don't set a stopping tolerance for your local-optimization
algorithm, MLSL defaults to \code{ftol_rel=1e-15} and \code{xtol_rel=1e-7}
for the local searches.
}
\examples{
### Minimize the Hartmann6 function
hartmann6 <- function(x) {
n <- length(x)
a <- c(1.0, 1.2, 3.0, 3.2)
A <- matrix(c(10.0, 0.05, 3.0, 17.0,
3.0, 10.0, 3.5, 8.0,
17.0, 17.0, 1.7, 0.05,
3.5, 0.1, 10.0, 10.0,
1.7, 8.0, 17.0, 0.1,
8.0, 14.0, 8.0, 14.0), nrow=4, ncol=6)
B <- matrix(c(.1312,.2329,.2348,.4047,
.1696,.4135,.1451,.8828,
.5569,.8307,.3522,.8732,
.0124,.3736,.2883,.5743,
.8283,.1004,.3047,.1091,
.5886,.9991,.6650,.0381), nrow=4, ncol=6)
fun <- 0.0
for (i in 1:4) {
fun <- fun - a[i] * exp(-sum(A[i,]*(x-B[i,])^2))
}
return(fun)
}
S <- mlsl(x0 = rep(0, 6), hartmann6, lower = rep(0,6), upper = rep(1,6),
nl.info = TRUE, control=list(xtol_rel=1e-8, maxeval=1000))
## Number of Iterations....: 1000
## Termination conditions:
## stopval: -Inf, xtol_rel: 1e-08, maxeval: 1000, ftol_rel: 0, ftol_abs: 0
## Number of inequality constraints: 0
## Number of equality constraints: 0
## Current value of objective function: -3.32236801141552
## Current value of controls:
## 0.2016895 0.1500107 0.476874 0.2753324 0.3116516 0.6573005
}
\references{
A. H. G. Rinnooy Kan and G. T. Timmer, ``Stochastic global
optimization methods'' Mathematical Programming, vol. 39, p. 27-78 (1987).
Sergei Kucherenko and Yury Sytsko, ``Application of deterministic
low-discrepancy sequences in global optimization,'' Computational
Optimization and Applications, vol. 30, p. 297-318 (2005).
}
\seealso{
\code{\link{direct}}
}
\author{
Hans W. Borchers
}
nloptr/man/figures/ 0000755 0001762 0000144 00000000000 14167114573 014020 5 ustar ligges users nloptr/man/figures/logo.png 0000644 0001762 0000144 00000053467 14167114573 015505 0 ustar ligges users PNG
IHDR X? iCCPicc 8U]hU>+$Ԧ5lRфem,lAݝi&3i)>A['!j-P(G 3k~s,[%,-:t}
}-+*&¿ gPG݅ج8"e Ų]A b ;l õ Wϙ2_E,(ۈ#Zsێ<5)"E6N#ӽEkۃO0}*rUt.iei # ]r
>cU{t7+ԙg߃xu