Skip to contents

The optimizers of Optim.jl, through OptimizationOptimJL: first order methods (GradientDescent(), ConjugateGradient(), AcceleratedGradientDescent(), MomentumGradientDescent(), NGMRES(), OACCEL(), BFGS(), and Optim's LBFGS as Optim$LBFGS(), since LBFGS() is the L-BFGS-B method of Optimization.jl), second order methods (Newton(), NewtonTrustRegion()), the box constrained Fminbox() (which wraps a first order method in a logarithmic barrier) and the interior point IPNewton() for bounds and nonlinear constraints, and the derivative free ParticleSwarm(), SimulatedAnnealing(), SAMIN() and the Nelder Mead simplex NelderMead(). Optim's own Optim$Adam() and Optim$AdaMax() (which OptimizationOptimJL does not export, Adam being the rule of Optimisers) and the Hessian vector product trust region Optim$KrylovTrustRegion() (it uses the hv of the function, (x, v, p), when there is one, else the Hessian times the vector) are solved too. The first order methods keep their iterates on a manifold: Optim$Flat() (the default), Optim$Sphere(), Optim$Stiefel(), Optim$PowerManifold() or Optim$ProductManifold(). Optim is the module: a list of these constructors and of Optim$LineSearches.

Usage

GradientDescent(
  alphaguess = NULL,
  linesearch = NULL,
  P = NULL,
  precondprep = NULL,
  manifold = NULL
)

ConjugateGradient(
  alphaguess = NULL,
  linesearch = NULL,
  eta = 0.4,
  theta = 1,
  betamax = Inf,
  P = NULL,
  precondprep = NULL,
  manifold = NULL
)

AcceleratedGradientDescent(
  alphaguess = NULL,
  linesearch = NULL,
  manifold = NULL
)

MomentumGradientDescent(
  mu = 0.01,
  alphaguess = NULL,
  linesearch = NULL,
  manifold = NULL
)

BFGS(
  alphaguess = NULL,
  linesearch = NULL,
  initial_invH = NULL,
  initial_stepnorm = NULL,
  manifold = NULL
)

Newton(alphaguess = NULL, linesearch = NULL)

NewtonTrustRegion(
  initial_delta = 1,
  delta_hat = 100,
  delta_min = 0,
  eta = 0.1,
  rho_lower = 0.25,
  rho_upper = 0.75,
  use_fg = TRUE
)

NGMRES(
  alphaguess = NULL,
  linesearch = NULL,
  nlprecon = NULL,
  nlpreconopts = list(),
  epsilon0 = 1e-12,
  wmax = 10L,
  manifold = NULL
)

OACCEL(
  alphaguess = NULL,
  linesearch = NULL,
  nlprecon = NULL,
  nlpreconopts = list(),
  epsilon0 = 1e-12,
  wmax = 10L,
  manifold = NULL
)

Fminbox(method = NULL, mu0 = NaN, mufactor = 0.001)

SimulatedAnnealing(neighbor = NULL, temperature = NULL, keep_best = TRUE)

ParticleSwarm(lower = NULL, upper = NULL, n_particles = 0L)

NelderMead(parameters = NULL, initial_simplex = NULL)

SAMIN(
  nt = 5L,
  ns = 5L,
  t0 = 2,
  rt = 0.9,
  r_expand = 10,
  bounds_ratio = 0.6,
  neps = 5L,
  coverage_ok = FALSE,
  verbosity = 0L
)

IPNewton(linesearch = NULL, mu0 = "auto", show_linesearch = FALSE)

Optim

Arguments

alphaguess

The initial step guess of the line search (see optim_linesearches) or a number, a static first step.

linesearch

The line search (for IPNewton(), a function (state, constraints, ...); the default is its backtracking search on the barrier merit function).

P

A preconditioner: NULL, a vector (a diagonal matrix) or a matrix; the search direction solves P s = g.

precondprep

A function (P, x) returning the preconditioner at x.

manifold

NULL or Optim$Flat() (Euclidean space), or the manifold the iterates are kept on: Optim$Sphere() (unit norm), Optim$Stiefel() (orthonormal columns, of the shape of u0), Optim$PowerManifold() or Optim$ProductManifold().

eta, theta, betamax

The parameters of the Hager Zhang conjugate gradient update; for NewtonTrustRegion(), eta is the threshold of the ratio of actual and predicted reductions for accepting a step.

mu

The momentum of MomentumGradientDescent().

initial_invH

A function of x giving the initial inverse Hessian of BFGS() (NULL: the identity, scaled by initial_stepnorm).

initial_stepnorm

The norm of the first step of BFGS().

initial_delta, delta_hat, delta_min

The initial, largest and smallest trust region radii.

rho_lower, rho_upper

The ratios below which the trust region shrinks and above which it grows.

use_fg

Evaluate the gradient with the value after each step.

nlprecon, nlpreconopts

The nonlinear preconditioner of NGMRES() and OACCEL() and its options (a list of Optim options).

epsilon0

The regularization of the subspace system.

wmax

The window size.

method

The inner method of Fminbox().

mu0, mufactor

The initial barrier multiplier of Fminbox() (NaN computes one) or of IPNewton() ("auto" computes one, or a number) and the decrease factor of Fminbox().

neighbor

A function of the current point returning the proposed point (the default adds standard normal noise).

temperature

A function of the iteration giving the temperature (the default is 1 / log(t)).

keep_best

Return the best point visited.

lower, upper

The bounds of the particles.

n_particles

The number of particles (0 chooses the default).

parameters

The simplex parameters of NelderMead(): a list with alpha, beta, gamma and delta (NULL for the adaptive ones).

initial_simplex

The initial simplex of NelderMead() (NULL for the affine simplex).

nt, ns, t0, rt, r_expand, bounds_ratio, neps, coverage_ok, verbosity

The parameters of SAMIN: the temperature is reduced every nt * ns * n evaluations and the search bounds adjusted every ns * n; the initial temperature, its reduction factor, the factor that raises the temperature while the parameter space is not covered, the acceptance ratio above which the search bounds grow (below one minus it they shrink), the number of previous values compared in the convergence test, whether the parameter space counts as covered from the start and the printing level (0 to 3).

show_linesearch

Print the line search of IPNewton().

Value

An optimization algorithm.

Details

solve(prob, alg, maxiters =, abstol =, reltol =, maxtime =) maps maxiters to Optim's iterations (outer_iterations for Fminbox, with local_maxiters for its inner iterations), abstol to f_abstol, reltol to f_reltol and maxtime to time_limit; Optim's other options (g_abstol, x_abstol, x_reltol, allow_f_increases, successive_f_tol, outer_g_abstol, ...) pass through. A problem with bounds and a method that does not handle them is wrapped in Fminbox() (bounds are given to ParticleSwarm()). Without a gradient function a central difference gradient is used, and without a Hessian a difference of the gradient. The return code is "Success" when a convergence test holds, "MaxIters" at the iteration limit and "Failure" otherwise.

The Optim module

Constructors reached through Optim$ only (their names are taken by Optimization.jl or by the rules of Optimisers); Optim$BFGS and Optim$NelderMead are BFGS() and NelderMead():

Optim$LBFGS(m = 10, alphaguess, linesearch, P, precondprep, manifold, scaleinvH0)

m is the memory; scaleinvH0 scales the initial inverse Hessian.

Optim$Adam(alpha = 1e-4, beta_mean = 0.9, beta_var = 0.999, epsilon = 1e-8, manifold), Optim$AdaMax(alpha = 0.002, beta_mean, beta_var, epsilon, manifold)

alpha is the step or a function of the iteration giving it, beta_mean and beta_var the decay rates of the moment estimates and epsilon keeps the denominators positive.

Optim$KrylovTrustRegion(initial_radius = 1, max_radius = 100, eta = 0.1, rho_lower = 0.25, rho_upper = 0.75, cg_tol = 0.01)

the initial and largest trust region radii, the acceptance threshold, the ratios that shrink and grow the region and the relative residual at which the conjugate gradient iteration stops.

Optim$Flat(), Optim$Sphere(), Optim$Stiefel(retraction = "SVD")

the manifolds; the retraction of Stiefel is "SVD" (the polar factor) or "CholQR" (the Cholesky orthogonalization).

Optim$PowerManifold(inner_manifold, inner_dims, outer_dims)

prod(outer_dims) copies of inner_manifold, each a block of prod(inner_dims) entries (of shape inner_dims) of the point.

Optim$ProductManifold(m1, m2, dims1, dims2)

the product of two manifolds: the first prod(dims1) entries lie on m1, the next prod(dims2) on m2.

Examples

rosen <- function(x, p) (1 - x[1])^2 + 100 * (x[2] - x[1]^2)^2
rosg <- function(x, p) c(-2 * (1 - x[1]) - 400 * x[1] * (x[2] - x[1]^2), 200 * (x[2] - x[1]^2))
prob <- OptimizationProblem(rosen, c(-1.2, 1), grad = rosg)
solve(prob, ConjugateGradient())$u
#> [1] 1 1
solve(prob, Optim$BFGS())$u
#> [1] 1 1
solve(prob, Optim$KrylovTrustRegion(), maxiters = 40)$u
#> [1] 1.0000000 0.9999999
solve(prob, Optim$LBFGS(manifold = Optim$Sphere()))$u
#> [1] -0.7839302  0.6208490
bprob <- OptimizationProblem(rosen, c(0.5, 0.5), grad = rosg, lb = c(0, 0), ub = c(0.8, 0.8))
solve(bprob, Fminbox(), maxiters = 5)$u
#> [1] 0.80 0.64