Description Usage Arguments Details Value Note Author(s) References Examples
multiStartoptim
generates pseudo-random and quasi-random numbers within the search domain specified by its bounds. Local searches are then performed by a user-selected method, either on the whole set of numbers generated as starting points, or only on the points lying under the objective function's median. When (and only when) a high number of local searches are to be performed, parallel computation can be used to speed-up the search.
1 2 3 4 5 6 | multiStartoptim(start0 = NULL, objectivefn, gradient = NULL, ...,
hessian = NULL, lower = -Inf, upper = Inf, control = list(),
method = c("L-BFGS-B", "Nelder-Mead", "nlminb"), nbtrials = NULL,
typerunif = c("runifbase", "runifantithetics", "sobol", "torus",
"niederreiterlodisp"), localsearch = c("exhaustive", "median"),
verb = FALSE, nbclusters = NULL)
|
start0 |
Starting value (a |
objectivefn |
The function to be minimized (the objective function). |
gradient |
The gradient of the objective function. |
... |
Additional parameters to be provided to objective function (see in examples) |
hessian |
The hessian parameter (or function), to be use like in optim (or nlminb). |
lower |
lower bound(s) for the search domain. Should be provided and finite. |
upper |
upper bound(s) for the search domain. Should be provided and finite. |
control |
Optimization control parameters defined exactly as in |
method |
The method used for local search. Can be either "L-BFGS-B", "Nelder-Mead" from |
nbtrials |
Number of pseudo-random and quasi-random numbers generated within the search domain specified by the |
typerunif |
The type of pseudo-random and quasi-random numbers simulation chosen. The default method "runifbase" is based on uniform pseudo-random numbers generated from SF-Mersenne Twister algorithm, implemented in package |
localsearch |
The local searches are performed by a user-selected method, either on the whole set of numbers generated as starting points, or only on the points lying under the objective function's median. |
verb |
If |
nbclusters |
The number of clusters on a local host to be used for parallel computation. |
For details on the methods used for local searches, refer to optim
or nlminb
.
For details on the random or quasi-random simulation, refer to package randtoolbox
, especially its vignette.
For details on parallel computation on a simple network of workstations, refer to package snow
.
If verb != TRUE
, a list with the values obtained from optim
or nlminb
. Or else, the list of values from optim
or nlminb
, plus a list of additional information on the iterations and the objective function values obtained whenever the algorithm finds a better solution.
Minimization is performed by default. To maximize, try scaling the objective with -1.
Thierry Moudiki
C. Dutang, P. Savicky (2013). randtoolbox: Generating and Testing Random Numbers. R package version 1.14.
M. J. A. Eugster, J. Knaus, C. Porzelius, M. Schmidberger, E. Vicedo (2011). Hands-on tutorial for parallel computing with R. Computational Statistics. Springer.
M. Gilli, E. Schumann (2010). A Note on 'Good Starting Values' in Numerical Optimisation. Available at SSRN.
F. Glover, G. Kochenberger (2003). Handbook of Metaheuristics. Kluwer Academic Publishers.
H. Niederreiter (1992). Random Number Generation and Quasi-Monte Carlo Methods. Society for Industrial and Applied Mathematics.
M. Schmidberger, M. Morgan, D. Eddelbuettel, H. Yu, L. Tierney, U. Mansmann(2009). State of the art in parallel computing with R. Journal of Statistical Software.
L. Tierney, A. J. Rossini, Na Li and H. Sevcikova (2013). snow: Simple Network of Workstations. R package version 0.3-12.
A. Zhigljavsky, A. Zilinkas (2008). Stochastic Global Optimization. Springer Science+Business Media.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | ### Example from optim :
# "wild" function, global minimum at about -15.81515
fw <- function (x)
{
10*sin(0.3*x)*sin(1.3*x^2) + 0.00001*x^4 + 0.2*x+80
}
plot(fw, -50, 50, n = 1000, main = "optim() minimising 'wild function'")
(minfw <- multiStartoptim(objectivefn = fw, lower = -40,
upper = 40, method = "nlminb", nbtrials = 500,
typerunif = "sobol", verb = TRUE))
points(minfw$res$par, minfw$res$objective, pch = 8, lwd = 2, col = "red", cex = 2)
### Calibrating the Nelson-Siegel-Svensson model (from Gilli, Schumann (2010)) :
# Nelson - Siegel - Svensson model
NSS2 <- function(betaV, mats)
{
gam1 <- mats / betaV [5]
gam2 <- mats / betaV [6]
aux1 <- 1 - exp (- gam1)
aux2 <- 1 - exp (- gam2)
betaV[1] + betaV[2] * (aux1 / gam1) +
betaV[3] * (aux1 / gam1 + aux1 - 1) +
betaV[4] * (aux2 / gam2 + aux2 - 1)
}
betaTRUE <- c(5, -2 ,5, -5 ,1 ,3)
mats <- c(1 ,3 ,6 ,9 ,12 ,15 ,18 ,21 ,24 ,30 ,36 ,48 ,60 ,72 ,84 ,
96,108 ,120)/ 12
yM <- NSS2 (betaTRUE, mats)
dataList <- list ( yM = yM, mats = mats, model = NSS2)
plot (mats, yM, xlab = " maturities in years ", ylab =" yields in pct. ")
# define objective function
OF <- function (betaV, dataList) {
mats <- dataList$mats
yM <- dataList$yM
model <- dataList$model
y <- model(betaV, mats)
aux <- y - yM
crossprod(aux)
}
settings <- list (min = c( 0, -15, -30, -30 ,0 ,3),
max = c (15, 30, 30, 30 ,3 ,6), d = 6)
NSStest <- multiStartoptim(objectivefn = OF, data = dataList,
lower = settings$min,
upper = settings$max,
method = "nlminb",
nbtrials = 50, typerunif = "torus")
lines(mats, NSS2(NSStest$par, mats), col = 'blue')
# (Only) when nbtrials is high, parallelization makes the computation faster.
# Try a lower number of trials and compare the expressions with a timer.
nbtrials <- 500
#t1 <- multiStartoptim(objectivefn = OF, data = dataList,
# lower = settings$min,
# upper = settings$max,
# nbtrials = nbtrials,
# typerunif = "sobol",
# method="nlminb",
# nbclusters=2)
t0 <- multiStartoptim(objectivefn = OF, data = dataList,
lower = settings$min,
upper = settings$max,
nbtrials=nbtrials,
typerunif="sobol",
method="nlminb")
#all.equal(t0, t1)
|
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
$res
$res$par
[1] -15.81515
$res$objective
[1] 67.46773
$res$convergence
[1] 0
$res$iterations
[1] 5
$res$evaluations
function gradient
9 8
$res$message
[1] "both X-convergence and relative convergence (5)"
$iteration_no
[1] 1 2 3 7 8 15 73 131 466
$startingparams_sequence
[1] 29.4074334 9.4074334 -30.5925666 -0.5925666 -5.5925666 -15.5925666
[7] -17.4675666 -15.2800666 -14.8113166
$foundparams_sequence
[1] 28.303752 10.609181 -29.597542 -1.190591 -4.532845 -16.117845 -15.967215
[8] -15.661611 -15.815151
$objective_val_sequence
[1] 84.04052 81.84853 76.56611 76.39410 69.31956 67.52682 67.48679 67.47030
[9] 67.46773
|
| | 0%
|
|= | 2%
|
|=== | 4%
|
|==== | 6%
|
|====== | 8%
|
|======= | 10%
|
|======== | 12%
|
|========== | 14%
|
|=========== | 16%
|
|============= | 18%
|
|============== | 20%
|
|=============== | 22%
|
|================= | 24%
|
|================== | 26%
|
|==================== | 28%
|
|===================== | 30%
|
|====================== | 32%
|
|======================== | 34%
|
|========================= | 36%
|
|=========================== | 38%
|
|============================ | 40%
|
|============================= | 42%
|
|=============================== | 44%
|
|================================ | 46%
|
|================================== | 48%
|
|=================================== | 50%
|
|==================================== | 52%
|
|====================================== | 54%
|
|======================================= | 56%
|
|========================================= | 58%
|
|========================================== | 60%
|
|=========================================== | 62%
|
|============================================= | 64%
|
|============================================== | 66%
|
|================================================ | 68%
|
|================================================= | 70%
|
|================================================== | 72%
|
|==================================================== | 74%
|
|===================================================== | 76%
|
|======================================================= | 78%
|
|======================================================== | 80%
|
|========================================================= | 82%
|
|=========================================================== | 84%
|
|============================================================ | 86%
|
|============================================================== | 88%
|
|=============================================================== | 90%
|
|================================================================ | 92%
|
|================================================================== | 94%
|
|=================================================================== | 96%
|
|===================================================================== | 98%
|
|======================================================================| 100%
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 15%
|
|=========== | 16%
|
|============ | 17%
|
|============ | 18%
|
|============= | 18%
|
|============= | 19%
|
|============== | 19%
|
|============== | 20%
|
|============== | 21%
|
|=============== | 21%
|
|=============== | 22%
|
|================ | 22%
|
|================ | 23%
|
|================= | 24%
|
|================= | 25%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 29%
|
|===================== | 30%
|
|===================== | 31%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|======================== | 35%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================= | 48%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 49%
|
|=================================== | 50%
|
|=================================== | 51%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 59%
|
|========================================== | 60%
|
|========================================== | 61%
|
|=========================================== | 61%
|
|=========================================== | 62%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================= | 64%
|
|============================================= | 65%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 72%
|
|=================================================== | 73%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|====================================================== | 78%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|======================================================== | 81%
|
|========================================================= | 81%
|
|========================================================= | 82%
|
|========================================================== | 82%
|
|========================================================== | 83%
|
|=========================================================== | 84%
|
|=========================================================== | 85%
|
|============================================================ | 85%
|
|============================================================ | 86%
|
|============================================================= | 87%
|
|============================================================= | 88%
|
|============================================================== | 88%
|
|============================================================== | 89%
|
|=============================================================== | 89%
|
|=============================================================== | 90%
|
|=============================================================== | 91%
|
|================================================================ | 91%
|
|================================================================ | 92%
|
|================================================================= | 92%
|
|================================================================= | 93%
|
|================================================================== | 94%
|
|================================================================== | 95%
|
|=================================================================== | 95%
|
|=================================================================== | 96%
|
|==================================================================== | 97%
|
|==================================================================== | 98%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 99%
|
|======================================================================| 100%
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.