Function factory producing solver objective function returning value and (possibly) gradient at the same time.

objective(solver, data, misfit_fn = squared_error, param_transform = NULL, ...)

Arguments

solver

object of class solver.

data

observed ('exact') data.

misfit_fn

function to compute misfit between data and result of simulation.

param_transform

function performing parameter transformation, must accept 1 parameter x and return list with components value and jacobian, the latter is optional if solver does not compute derivatives.

...

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

Value

Function with numeric parameter x returning list with one or two components:

value

numeric, objective value,

gradient

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

Examples

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_obj <- objective(s, observed_data, precision = 30.0, silent = TRUE) solver_obj(x)
#> $value #> [1] 2594156034 #> #> $gradient #> [1] -6208209534 -4059190749 -5551351184 -2246937119 #>