This function performs numerical optimization using an optimizer
object.
Usage
apply_optimizer(optimizer = optimizer_nlm(), objective, initial, ...)Arguments
- optimizer
An object of class
optimizer.- objective
A
functionto be optimized, returning a singlenumeric. Its first argument must be anumericvector of the same length asinitial, followed by any other arguments specified by the...argument.- initial
A
numericvector with starting parameter values for the optimization.- ...
Additional arguments to be passed to
optimizer.
Value
A named list, containing at least these four elements:
valueA
numeric, the value of the estimated optimum ofobjective.parameterA
numericvector, the parameter vector where the optimum ofobjectiveis obtained.secondsA
numeric, the total optimization time in seconds.initialA
numeric, the initial parameter values.
Appended are additional output elements of the optimizer (if not excluded by
the output_ignore element via define_optimizer).
See also
define_optimizer() for creating an optimizer object.
Examples
apply_optimizer(optimizer_nlm(), function(x) x^4 + 3*x - 5, 2)
#> $value
#> [1] -7.044261
#>
#> $parameter
#> [1] -0.9085614
#>
#> $seconds
#> [1] 0.001333237
#>
#> $initial
#> [1] 2
#>
#> $error
#> [1] FALSE
#>
#> $gradient
#> [1] -6.068035e-06
#>
#> $code
#> [1] 1
#>
#> $iterations
#> [1] 7
#>
