Skip to contents

OptimizationProblem(sys, op) builds the problem of minimizing the cost of a complete system over its unknowns, subject to its constraints (equations g ~ h and inequalities, see Inequality()) and to the bounds metadata of the unknowns. op gives the starting values of the unknowns and the parameter values. The gradient of the cost and the Jacobian of the constraints are generated symbolically, and the Hessians with hess = TRUE and cons_h = TRUE.

Usage

OptimizationFunction(
  sys,
  grad = FALSE,
  hess = FALSE,
  cons_j = FALSE,
  cons_h = FALSE,
  weights = NULL,
  cons = NULL,
  ...
)

MultiObjectiveOptimizationFunction(
  sys,
  jac = FALSE,
  hess = FALSE,
  cons_j = FALSE,
  cons_h = FALSE,
  weights = NULL,
  cons = NULL,
  ...
)

OptimizationProblem(
  sys,
  op = list(),
  ...,
  lb = NULL,
  ub = NULL,
  multiobjective = FALSE,
  grad = TRUE,
  hess = FALSE,
  cons_j = TRUE,
  cons_h = FALSE,
  weights = NULL,
  u0 = NULL,
  p = NULL,
  cons = NULL,
  lcons = NULL,
  ucons = NULL,
  guesses = list(),
  missing_guess_value = NULL,
  sense = MinSense
)

Arguments

sys

A complete System with costs, an R function f(u, p), or an OptimizationFunction.

grad, hess

Generate the gradient and Hessian of the cost; for raw functions, R functions of (u, p).

cons_j, cons_h

Generate the Jacobian and Hessians of the constraints.

weights

Weights of the costs: the cost becomes sum(weights * costs). Numbers or parameters of the system.

cons

A constraint function (u, p) for raw problems.

...

Solver options stored with the problem.

jac

Generate the Jacobian of the cost vector (multiobjective).

op

Operating point: starting values and parameter values.

lb, ub

Bounds of the unknowns; both or neither.

multiobjective

Keep the costs as a vector objective.

u0, p

Starting values and parameters for raw problems.

lcons, ucons

Bounds of the constraint function for raw problems.

guesses, missing_guess_value

As in NonlinearProblem().

sense

MinSense (minimize, the default) or MaxSense; see optimization_interface.

Value

An OptimizationFunction, MultiObjectiveOptimizationFunction or OptimizationProblem.

Details

OptimizationFunction(sys) builds the functions without values: fields f, grad, hess, cons, cons_j and cons_h, each a function of (u, p). MultiObjectiveOptimizationFunction(sys) keeps the costs separate: f returns the vector of costs, jac its Jacobian and hess one function per cost; OptimizationProblem(sys, op, multiobjective = TRUE) builds a problem on it.

The problem has lb and ub (bounds of the unknowns, NULL when none is bounded), lcons and ucons (bounds of the constraint function: 0 and 0 for equations, -Inf and 0 for inequalities) and int (which unknowns are integer).

OptimizationProblem(f, u0, p) with an R function f(u, p) builds a problem without a system; grad, cons, lcons, ucons may be given.

Examples

x <- Variable("x"); y <- Variable("y"); a <- Parameter("a"); b <- Parameter("b")
sys <- complete(System(list(), costs = list((a - x)^2 + b * (y - x^2)^2), name = "rosenbrock"))
prob <- OptimizationProblem(sys, list(x ~ -1, y ~ 2, a ~ 1, b ~ 100))
sol <- solve(prob)
sol$u; sol$objective
#> x y 
#> 1 1 
#> [1] 8.35086e-22
# with a constraint: stay inside the unit disk
csys <- complete(System(list(), costs = list((a - x)^2 + b * (y - x^2)^2), name = "rosenbrock",
                        constraints = list(Inequality(x^2 + y^2, 1))))
csol <- solve(OptimizationProblem(csys, list(x ~ 0, y ~ 0, a ~ 1, b ~ 100)))
csol$u
#>         x         y 
#> 0.7864152 0.6176983