Skip to contents

AbstractNLPModel(meta, obj, ...) builds a model of the NLPModels.jl interface from R functions of x: the objective obj(x), its gradient grad(x), the constraints cons(x) (the vector bounded by meta$lcon and meta$ucon), their Jacobian jac(x) (a dense matrix) and the Hessian of the Lagrangian hess(x, y, obj_weight) (a dense matrix of obj_weight * H_f + sum(y * H_c)). Missing derivatives are approximated by central differences. Evaluate the model with the functions of NLPModels, which count the evaluations in nlp$counters as NLPModels.jl does. OptimizationProblem(nlp) and OptimizationFunction(nlp) convert the model, keeping its bounds, constraint bounds, starting point and sense.

Usage

AbstractNLPModel(
  meta,
  obj,
  grad = NULL,
  cons = NULL,
  jac = NULL,
  hess = NULL,
  counters = Counters()
)

AbstractNLSModel(
  meta,
  nls_meta,
  residual,
  jac_residual = NULL,
  cons = NULL,
  jac = NULL,
  counters = NLSCounters()
)

Arguments

meta

An NLPModelMeta().

obj, grad, cons, jac, hess

Functions of the model (see Details).

counters

The evaluation counters.

nls_meta

An NLSMeta().

residual, jac_residual

The residual of a least squares model and its Jacobian.

Value

An AbstractNLPModel or AbstractNLSModel.

Details

AbstractNLSModel(meta, nls_meta, residual, ...) is a nonlinear least squares model: the objective is sum(residual(x)^2) / 2 and its gradient t(J) %*% residual(x) with J = jac_residual(x).

Examples

meta <- NLPModelMeta(2, x0 = c(-1.2, 1))
nlp <- AbstractNLPModel(meta, obj = function(x) (1 - x[1])^2 + 100 * (x[2] - x[1]^2)^2)
NLPModels$obj(nlp, c(1, 1))
#> [1] 0
NLPModels$neval_obj(nlp)
#> [1] 1
sol <- solve(OptimizationProblem(nlp), LBFGSB())
round(sol$u, 4)
#> [1] 1 1