Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nimOptim

Nimble wrapper around R's builtin optim.


Description

Nimble wrapper around R's builtin optim.

Usage

nimOptim(par, fn, gr = "NULL", ..., method = "Nelder-Mead", lower = -Inf,
  upper = Inf, control = nimOptimDefaultControl(), hessian = FALSE)

Arguments

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 optim. One of: "Nelder-Mead", "BFGS", "CG", "L-BFGS-B". Note that the R methods "SANN", "Brent" are not supported.

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 Details section of optim.

hessian

Logical. Should a Hessian matrix be returned?

Value

See Also

Examples

## 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)

nimble

MCMC, Particle Filtering, and Programmable Hierarchical Modeling

v0.11.0
BSD_3_clause + file LICENSE | GPL (>= 2)
Authors
Perry de Valpine [aut], Christopher Paciorek [aut, cre], Daniel Turek [aut], Nick Michaud [aut], Cliff Anderson-Bergman [aut], Fritz Obermeyer [aut], Claudia Wehrhahn Cortes [aut] (Bayesian nonparametrics system), Abel Rodrìguez [aut] (Bayesian nonparametrics system), Duncan Temple Lang [aut] (packaging configuration), Sally Paganin [aut] (reversible jump MCMC), Jagadish Babu [ctb] (code for the compilation system for an early version of NIMBLE), Lauren Ponisio [ctb] (contributions to the cross-validation code), Peter Sujan [ctb] (multivariate t distribution code)
Initial release
2021-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.