View source: R/nimbleFunction_Rexecution.R
nimOptim | R Documentation |
optim
.Nimble wrapper around R's builtin optim
.
nimOptim(
par,
fn,
gr = "NULL",
...,
method = "Nelder-Mead",
lower = -Inf,
upper = Inf,
control = nimOptimDefaultControl(),
hessian = FALSE
)
par |
Initial values for the parameters to be optimized over. |
fn |
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. |
gr |
A function to return the gradient for the "BFGS", "CG" and "L-BFGS-B" methods. |
... |
IGNORED |
method |
The method to be used. See 'Details' section of |
lower |
Vector or scalar of lower bounds for parameters. |
upper |
Vector or scalar of upper bounds for parameters. |
control |
A list of control parameters. See |
hessian |
Logical. Should a Hessian matrix be returned? |
optimResultNimbleList
optim
## Not run:
objectiveFunction <- nimbleFunction(
run = function(par = double(1)) {
return(sum(par) * exp(-sum(par ^ 2) / 2))
returnType(double(0))
}
)
optimizer <- nimbleFunction(
run = function(method = character(0), fnscale = double(0)) {
control <- optimDefaultControl()
control$fnscale <- fnscale
par <- c(0.1, -0.1)
return(optim(par, objectiveFunction, method = method, control = control))
returnType(optimResultNimbleList())
}
)
cOptimizer <- compileNimble(optimizer)
cOptimizer(method = 'BFGS', fnscale = -1)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.