Skip to contents

Small, low overhead solvers of SimpleOptimization for solve(prob, SimpleLBFGS()). Julia differentiates the objective with ForwardDiff; these use the gradient (and Hessian) of the problem when it has them, else finite differences.

Usage

SimpleLBFGS(
  threshold = 10L,
  linesearch = StrongWolfeLineSearch(maxiters = 50L, zoom_maxiters = 50L)
)

SimpleBFGS()

SimpleGradientDescent(eta = 0.01)

SimpleNewton()

SimpleSOAP(
  eta = 0.003,
  beta = c(0.95, 0.95),
  shampoo_beta = -1,
  epsilon = 1e-08,
  freq = 10L,
  max_dim = 10000L,
  weight_decay = 0.01
)

Arguments

threshold

Number of stored correction pairs.

linesearch

A StrongWolfeLineSearch().

eta

Learning rate.

beta

Decay of the first and second moments.

shampoo_beta

Decay of the preconditioners; a negative value uses beta[2].

epsilon

Constant against division by zero.

freq

Iterations between updates of the eigenbases.

max_dim

Dimensions larger than this keep the identity basis.

weight_decay

Decoupled weight decay, applied as eta * weight_decay.

Value

An optimization algorithm.

Details

  • SimpleLBFGS(threshold, linesearch): limited memory BFGS with threshold stored pairs and a Strong Wolfe line search (StrongWolfeLineSearch(), 50 bracketing and 50 zoom iterations by default). The only one of these that accepts box constraints (lb, ub), by projection. It stops with "Success" when the largest component of the projected gradient is at most max(abstol, reltol * initial value) (abstol at least sqrt(.Machine$double.eps)), "MaxIters" after maxiters iterations (default 100) and "Failure" on a non finite point or a failed line search.

  • SimpleBFGS(): the Broyden iteration (SimpleBroyden without line search) on the gradient, which converges to a stationary point; abstol (default 3e-13) bounds the largest gradient component and maxiters defaults to 100.

  • SimpleNewton(): the Newton Raphson iteration on the gradient, with the Hessian of the problem (finite differences of the gradient when it has none). Same tolerances as SimpleBFGS().

  • SimpleGradientDescent(eta): u - eta * gradient until the Euclidean norm of the gradient is below abstol (default 1e-8); maxiters defaults to 1000.

  • SimpleSOAP(...): SOAP (Shampoo with Adam in the preconditioner's eigenbasis). For a matrix u0 it runs AdamW in the eigenbasis of the Shampoo preconditioners, refreshed every freq iterations by a power iteration and a QR factorization; for a vector it is AdamW. It always runs maxiters iterations (default 1000) and returns "MaxIters".

The statistics follow Julia: SimpleBFGS() and SimpleNewton() report maxiters iterations and no evaluations, SimpleLBFGS() the iterations only.

Examples

f <- function(u, p) (1 - u[1])^2 + 100 * (u[2] - u[1]^2)^2
g <- function(u, p) c(-2 * (1 - u[1]) - 400 * u[1] * (u[2] - u[1]^2), 200 * (u[2] - u[1]^2))
prob <- OptimizationProblem(f, c(-1.2, 1), grad = g)
solve(prob, SimpleLBFGS())$u
#> [1] 1 1
solve(prob, SimpleGradientDescent(eta = 1e-3), maxiters = 200)$objective
#> [1] 3.462227