multiStart {BB} | R Documentation |
Nonlinear Optimization or Root-Finding with Multiple Starting Values
Description
Start BBsolve
or BBoptim
from multiple starting
points to obtain multiple solutions and to test sensitivity to starting values.
Usage
multiStart(par, fn, gr=NULL, action = c("solve", "optimize"),
method=c(2,3,1), lower=-Inf, upper=Inf,
project=NULL, projectArgs=NULL,
control=list(), quiet=FALSE, details=FALSE, ...)
Arguments
par |
A real matrix, each row of which is an argument to |
fn |
see |
gr |
Only required for optimization. See |
action |
A character string indicating whether to solve a nonlinear system or to optimize. Default is “solve”. |
method |
see |
upper |
An upper bound for box constraints. See |
lower |
An lower bound for box constraints. See |
project |
A projection
function or character string indicating its name. The projection
function that takes a point in |
projectArgs |
A list with arguments to the |
control |
See |
quiet |
A logical variable (TRUE/FALSE). If |
details |
Logical indicating if the result should include the full
result from |
... |
arguments passed fn (via the optimization algorithm). |
Details
The optimization or root-finder is run with each row of par
indicating
initial guesses.
Value
list with elements par
, values
, and converged
.
It optionally returns an attribute called “details”, which is a list as long as
the number of starting values, which contains the complete object returned
by dfsane
or spg
for each starting value.
References
R Varadhan and PD Gilbert (2009), BB: An R Package for Solving a Large System of Nonlinear Equations and for Optimizing a High-Dimensional Nonlinear Objective Function, J. Statistical Software, 32:4, http://www.jstatsoft.org/v32/i04/
See Also
Examples
# Use a preset seed so the example is reproducable.
require("setRNG")
old.seed <- setRNG(list(kind="Mersenne-Twister", normal.kind="Inversion",
seed=1234))
# Finding multiple roots of a nonlinear system
brownlin <- function(x) {
# Brown's almost linear system(A.P. Morgan, ACM 1983)
# two distinct solutions if n is even
# three distinct solutions if n is odd
n <- length(x)
f <- rep(NA, n)
nm1 <- 1:(n-1)
f[nm1] <- x[nm1] + sum(x) - (n+1)
f[n] <- prod(x) - 1
f
}
p <- 9
n <- 50
p0 <- matrix(rnorm(n*p), n, p) # n starting values, each of length p
ans <- multiStart(par=p0, fn=brownlin)
pmat <- ans$par[ans$conv, 1:p] # selecting only converged solutions
ord1 <- order(abs(pmat[,1]))
round(pmat[ord1, ], 3) # all 3 roots can be seen
# An optimization example
rosbkext <- function(x){
n <- length(x)
j <- 2 * (1:(n/2))
jm1 <- j - 1
sum(100 * (x[j] - x[jm1]^2)^2 + (1 - x[jm1])^2)
}
p0 <- rnorm(50)
spg(par=p0, fn=rosbkext)
BBoptim(par=p0, fn=rosbkext)
pmat <- matrix(rnorm(100), 20, 5) # 20 starting values each of length 5
ans <- multiStart(par=pmat, fn=rosbkext, action="optimize")
ans
attr(ans, "details")[[1]] #
pmat <- ans$par[ans$conv, 1:5] # selecting only converged solutions
round(pmat, 3)