Skip to contents

The solvers of OptimizationODE find a minimizer as the steady state of the gradient flow du/dt = -gradient(u), integrated from u0 with an ODE solver until the derivative is small: the largest component of du at most 1e-8, or at most 1e-6 times the largest component of du + u, as DynamicSS of SteadyStateDiffEq (the integration itself uses abstol = 1e-8, reltol = 1e-6). The solve options dt (the step of Euler(), the initial step of the adaptive methods) and maxiters (the largest number of steps) are passed to the ODE solver.

Usage

ODEOptimizer(alg)

ODEGradientDescent()

RKChebyshevDescent()

RKAccelerated()

HighOrderDescent()

DAEOptimizer(alg)

DAEMassMatrix()

Arguments

alg

An ODE algorithm (for DAEOptimizer, a mass matrix ODE algorithm or a DAE algorithm).

Value

An optimization algorithm. The ODE algorithm is $alg.

Details

  • ODEOptimizer(alg) uses the ODE algorithm alg; ODEGradientDescent() is Euler() (it needs dt), RKChebyshevDescent() ROCK2(), RKAccelerated() Tsit5() and HighOrderDescent() Vern7().

  • DAEOptimizer(alg) handles equality constraints cons(u) = 0 (the values of lcons and ucons are not used, only their number m): the last m equations of the gradient flow are replaced by the constraints, which makes the last m unknowns algebraic. With a mass matrix ODE algorithm the system has the mass matrix diag(c(rep(1, n - m), rep(0, m))) and is integrated to steady state; DAEMassMatrix() is Rodas5P() with finite difference Jacobians. With a fully implicit DAE algorithm (such as DFBDF()) the residual du + gradient(u) (with the constraints in the last rows) is integrated over [0, 10].

The gradient of the problem is used, finite differences when it has none. The return code is "Success" for ODEOptimizer and that of the integration for DAEOptimizer; the statistics of ODEOptimizer give the accepted steps as iterations and gradient evaluations, the right hand side evaluations as fevals. A callback is called after every step.

Examples

f <- function(u, p) sum((u - p)^2)
g <- function(u, p) 2 * (u - p)
prob <- OptimizationProblem(f, c(2, 2), c(1, 1), grad = g)
solve(prob, RKAccelerated())$u
#> [1] 1 1
solve(prob, ODEGradientDescent(), dt = 0.01)$u
#> [1] 1 1