Skip to contents

OptimizationProblem(..., sense = MaxSense) maximizes instead of minimizing (MinSense, the default; ObjSense lists both); the solution's objective is the value of the original function. solve(prob, alg, callback = cb) calls cb(state, loss) after every evaluation of the objective, and stops when it returns TRUE (DEFAULT_CALLBACK never stops; DEFAULT_DATA is the data iterator of Julia's data driven optimizers). Solutions carry sol$stats, an OptimizationStats with the numbers of iterations and evaluations and the time.

Usage

MinSense

MaxSense

ObjSense

DEFAULT_CALLBACK(state, loss)

DEFAULT_DATA

NoAD()

OptimizationVerbosity(level = c("warn", "none", "info", "all"))

OptimizationStats(
  iterations = 0L,
  time = 0,
  fevals = 0L,
  gevals = 0L,
  hevals = 0L
)

IncompatibleOptimizerError(msg)

OptimizerMissingError(msg = "no optimization algorithm was given")

requiresgradient(alg)

requireshessian(alg)

requiresconsjac(alg)

requiresconshess(alg)

requiresbounds(alg)

requiresconstraints(alg)

allowsbounds(alg)

allowsconstraints(alg)

allowscallback(alg)

lag_hess_structure(f)

OptimizationCache(prob, alg = NULL, ...)

Arguments

state, loss

Arguments of a callback.

level

Verbosity: "none", "warn", "info" or "all".

iterations, time, fevals, gevals, hevals

Fields of OptimizationStats().

msg

A message.

alg

An optimization algorithm.

f

An OptimizationFunction.

prob

An OptimizationProblem.

...

Solver options.

Value

A trait value, a cache, a solution, a condition or a settings object.

Details

init(prob, alg, ...) returns an OptimizationCache, which solve_integrator() (Julia's solve!) solves; reinit(cache, u0, p) changes its initial point or parameters.

The traits requiresgradient, requireshessian, requiresconsjac, requiresconshess, requiresbounds, requiresconstraints, allowsbounds, allowsconstraints, allowscallback describe an optimizer, and lag_hess_structure is the sparsity pattern of the Hessian of the Lagrangian of an OptimizationFunction (dense here). NoAD() builds no derivatives (the user's or none). OptimizationVerbosity() holds verbosity settings. A solver refuses problems it cannot handle with an IncompatibleOptimizerError condition; OptimizerMissingError is signaled when no optimizer is given and no default applies.

Examples

prob <- OptimizationProblem(function(x, p) -(x[1] - 1)^2, 0, sense = MaxSense)
sol <- solve(prob, NelderMead())
sol$u; sol$objective
#> [1] 1
#> [1] -1.972152e-31
requiresgradient(LBFGSB())
#> [1] TRUE
cache <- init(prob, NelderMead())
solve_integrator(cache)$u
#> [1] 1