PolyOpt() chains two optimizers. For a deterministic objective it runs
Adam(0.01) for maxiters iterations (300 by default) and continues
from its result with Optim$BFGS(initial_stepnorm = 0.01) (for
maxiters iterations as well, when given). An objective that gives
different values at the same point needs maxiters and is minimized with
Adam(0.1). The solution and its statistics are those of the last
optimizer. As in Julia, problems with bounds are not accepted.
Usage
PolyOpt()
Sophia(
eta = 0.001,
betas = c(0.9, 0.999),
epsilon = 1e-08,
lambda = 0.1,
k = 10L,
rho = 0.04
)Details
Sophia(eta, betas, epsilon, lambda, k, rho) is the second order
optimizer of Liu et al. (2023): a moving average m of the gradients, a
moving average h of the diagonal of the Hessian estimated as
v * (H v) with a standard normal v (Hutchinson's estimator), weight
decay x - eta * lambda * x and the step -eta * clamp(m / max(h, epsilon), -rho, rho). maxiters defaults to 1000. As in Julia, where
the Hessian estimate is made when the index of the data batch i
satisfies i %% k == 1, it is made at every iteration for k >= 2 (the
problem has a single batch) and never for k = 1. The product H v
uses the Hessian of the problem when it has one, else central finite
differences of the gradient; the random vectors come from rnorm(). The
objective of the solution is the one evaluated before the last update and
the return code is "Success"; the callback is called at every
iteration and stops the optimization when it returns TRUE.
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, PolyOpt())$u
#> [1] 1 1
set.seed(1)
solve(prob, Sophia(eta = 0.01), maxiters = 200)$objective
#> [1] 3.757161