| optimFactory | R Documentation | 
A function factory which returns a function with unified input arguments, and provides compatibility with the package optimParallel.
optimFactory(optim.args = list(), hessian = FALSE, optimParallel.args = list())
optim.args | 
 A named list of optional settings for optim. See   | 
hessian | 
 A logical which specifies whether the hessian matrix is to be returned with the output.  | 
optimParallel.args | 
 A named list which is passed to   | 
The function factory optimFactory() returns a function of the form function(par, fn, gr = NULL, ..., lower, upper). It is intended to replace calls to optim or optimParallel by wrapping both functions. By default, it returns a function that corresponds to optim with default arguments.
To use optimParallel, users may specify the following arguments in optimParallel.args:
NULL)The number of cores to use during numerical optimization. Is NULL by default, which corresponds to using stats::optim. When num_cores is a numeric value, the actual number of cores is set to min(detectCores()-1, num_cores) to avoid accidentally overloading the user's system.
FALSE)A logical value which controls whether optimParallel should use central difference approximation of the gradient (FALSE) or forward difference approximation (TRUE).
FALSE)A logical value which controls whether optimParallel should return additional information about the optimization process. See optimParallel.
A function of the form function(par, fn, gr = NULL, ..., lower, upper) which returns the output obtained from calls to optim or optimParallel
Thomas Caspar Fischer
Hadley Wickham (2015) Advanced R, CRC Press. Florian Gerber and Reinhard Furrer (2019) optimParallel: An R package providing a parallel version of the L-BFGS-B optimization method, The R Journal, 11(1), 352–358
optim and
optimParallel
library(GeneralizedWendland)
library(optimParallel)
set.seed(43)
n <- 50
range <- 0.4
dist_max <- 2
theta  <- c(range, 1, 1, 0, 0)
locs <- data.frame(x = runif(n, 0, sqrt(dist_max)),
                   y = runif(n, 0, sqrt(dist_max)))
dmat  <- spam::nearest.dist(locs, locs, delta = dist_max)
Sigma <- cov.wendland(h = dmat, theta = theta)
y <- c(spam::rmvnorm(1, Sigma = Sigma))
init_parameters   <- c(0.7, 2, 0, 2, 2)
lower_constraints <- c(0.1, 0.1, 0, 0, 0)
upper_constraints <- c(sqrt(2), 2, 2, 2, 2)
mleFunction <- mleFactory(covariance = cov.wendland)
(mle_result <- mleFunction(y = y, distmat = dmat, init_parameters = init_parameters,
                       theta_llim = lower_constraints, theta_ulim = upper_constraints))
mleFunctionPar <- mleFactory(covariance = cov.wendland, optimParallel.args = list(num_cores = 2))
(mle_result_par <- mleFunctionPar(y = y, distmat = dmat, init_parameters = init_parameters,
                       theta_llim = lower_constraints, theta_ulim = upper_constraints))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.