Function factory producing functions for use in optimization. These are
objective function and its gradient. They can be used, e.g., as parameters
fn and gr of stats::optim(). Note that the functions compute their
values through objective(), however, calls to the latter are
memoised, so actual solver should never be called twice for the same
data (x). In particular, computing value and gradient for a given x
requires only a single solver run. To obtain non-memoised functions
use make_functions() composed with objective() (see example in
make_functions()).
objective_functions(solver, data, ...)
| solver | object of class |
|---|---|
| data | observed ('exact') data. |
| ... | additional args passed to |
List with one or two components:
valueobjective value function,
gradientobjective gradient function, missing if solver does not compute Jacobian matrix.
s <- fake_adaptive_solver(4, 5) result <- run(s, c(10, 10, 10, 10), precision = 5.0, silent = TRUE) observed_data <- result$qoi x <- c(10.5, 9.44, 10.21, 8.14) solver_funs <- objective_functions(s, observed_data, precision = 30.0, silent = TRUE) solver_funs$value(x)#> [1] 2594156034solver_funs$gradient(x)#> [1] -6208209534 -4059190749 -5551351184 -2246937119