objective_functions: Solver objective functions

Description Usage Arguments Value See Also Examples

View source: R/objective.R

Description

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()).

Usage

1

Arguments

solver

object of class solver.

data

observed ('exact') data.

...

additional args passed to objective() or memoise::memoise(), note that some solvers can have some mandatory parameters (see required_args()), e.g. solvers created with adaptive_shell_solver() require precision.

Value

List with one or two components:

value

objective value function,

gradient

objective gradient function, missing if solver does not compute Jacobian matrix.

See Also

memoise::memoise()

Examples

1
2
3
4
5
6
7
8
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)
solver_funs$gradient(x)

maciejsmolka/solvergater documentation built on Jan. 1, 2021, 8:28 a.m.