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
- 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.
Details
SimpleLBFGS(threshold, linesearch): limited memory BFGS withthresholdstored 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 mostmax(abstol, reltol * initial value)(abstolat leastsqrt(.Machine$double.eps)),"MaxIters"aftermaxitersiterations (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(default3e-13) bounds the largest gradient component andmaxitersdefaults 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 asSimpleBFGS().SimpleGradientDescent(eta):u - eta * gradientuntil the Euclidean norm of the gradient is belowabstol(default1e-8);maxitersdefaults to 1000.SimpleSOAP(...): SOAP (Shampoo with Adam in the preconditioner's eigenbasis). For a matrixu0it runs AdamW in the eigenbasis of the Shampoo preconditioners, refreshed everyfreqiterations by a power iteration and a QR factorization; for a vector it is AdamW. It always runsmaxitersiterations (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