multistart.RdMultiple initial parameter wrapper function that calls other R tools for optimization, including the existing optimr() function.
multistart(parmat, fn, gr=NULL, lower=-Inf, upper=Inf,
method=NULL, hessian=FALSE,
control=list(),
...)a matrix of which each row is a set of initial values for the parameters for which optimal values are to be found. Names on the elements of this vector are preserved and used in the results data frame.
A function to be minimized (or maximized), with first argument the vector of parameters over which minimization is to take place. It should return a scalar result.
A function to return (as a vector) the gradient for those methods that can use this information.
If 'gr' is NULL, a finite-difference approximation will be used.
An open question concerns whether the SAME approximation code used for all methods,
or whether there are differences that could/should be examined?
Bounds on the variables for methods such as "L-BFGS-B" that can
handle box (or bounds) constraints.
A character string giving the name of the optimization method to be
applied. See the list allmeth in file
ctrldefault.R which is part of this package.
A logical control that if TRUE forces the computation of an approximation
to the Hessian at the final set of parameters. If FALSE (default), the hessian is
calculated if needed to provide the KKT optimality tests (see kkt in
‘Details’ for the control list).
This setting is provided primarily for compatibility with optim().
A list of control parameters. See ‘Details’.
For optimx further arguments to be passed to fn
and gr; otherwise, further arguments are not used.
An array with one row per set of starting parameters. Each row contains:
The best set of parameters found.
The value of ‘fn’ corresponding to ‘par’.
A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. This excludes those calls needed to compute the Hessian, if requested, and any calls to ‘fn’ to compute a finite-difference approximation to the gradient.
An integer code. ‘0’ indicates successful completion
A character string giving any additional information returned by the optimizer, or ‘NULL’.
Always NULL for this routine.
See the manual pages for optim() and the packages the DESCRIPTION suggests.
fnR <- function (x, gs=100.0)
{
n <- length(x)
x1 <- x[2:n]
x2 <- x[1:(n - 1)]
sum(gs * (x1 - x2^2)^2 + (1 - x2)^2)
}
grR <- function (x, gs=100.0)
{
n <- length(x)
g <- rep(NA, n)
g[1] <- 2 * (x[1] - 1) + 4*gs * x[1] * (x[1]^2 - x[2])
if (n > 2) {
ii <- 2:(n - 1)
g[ii] <- 2 * (x[ii] - 1) + 4 * gs * x[ii] * (x[ii]^2 - x[ii +
1]) + 2 * gs * (x[ii] - x[ii - 1]^2)
}
g[n] <- 2 * gs * (x[n] - x[n - 1]^2)
g
}
pm <- rbind(rep(1,4), rep(pi, 4), rep(-2,4), rep(0,4), rep(20,4))
pm <- as.matrix(pm)
cat("multistart matrix:\n")
#> multistart matrix:
print(pm)
#> [,1] [,2] [,3] [,4]
#> [1,] 1.000000 1.000000 1.000000 1.000000
#> [2,] 3.141593 3.141593 3.141593 3.141593
#> [3,] -2.000000 -2.000000 -2.000000 -2.000000
#> [4,] 0.000000 0.000000 0.000000 0.000000
#> [5,] 20.000000 20.000000 20.000000 20.000000
ans <- multistart(pm, fnR, grR, method="Rvmmin", control=list(trace=0))
ans
#> p1 p2 p3 p4 value fevals gevals
#> 1 1.0000000 1.0000000 1.0000000 1.000000 0.000000e+00 1 1
#> 2 -0.7756592 0.6130934 0.3820628 0.145972 3.701429e+00 81 49
#> 3 1.0000000 1.0000000 1.0000000 1.000000 1.533348e-29 77 57
#> 4 1.0000000 1.0000000 1.0000000 1.000000 4.979684e-30 58 40
#> 5 1.0000000 1.0000000 1.0000000 1.000000 4.979684e-30 203 138
#> convergence
#> 1 2
#> 2 0
#> 3 0
#> 4 0
#> 5 0