Julia port of the LBFGS-Lite
C++ header-only library for unconstrained optimization.
From LBFGS-Lite
:
-
This library implements the Limited-Memory Broyden-Fletcher-Goldfarb-Shanno Method (L-BFGS).
-
A highly robust line search proposed by Lewis and Overton is employed.
-
Both smooth (C2) and nonsmooth (C0 but piecewise C2) functions are supported.
-
Cautious update by Li and Fukushima is employed for global convergence in nonconvex cases.
-
Externally provided maximum step size is convenient for functions defined on bounded sets.
Minimize the function
starting from x₀ = [-2.0, 1.0]
using optimize
:
function fg!(x, dx)
@. dx = sin(x) * cos(x)
return 1 + sum(abs2 ∘ sin, x) / 2
end
x₀ = Float64[-2.0, 1.0]
params = LBFGSParams{Float64}()
x, fx, st = optimize(fg!, x₀, params)
@assert isapprox(x, [-π, 0.0]; atol = 1e-6)
@assert isapprox(fx, 1.0; atol = 1e-12)
@assert Int(st) == 0
Preallocate a workspace and solve the problem in-place using optimize!
:
x = copy(x₀) # will be overwritten
params = LBFGSParams{Float64}()
work = LBFGSWorkspace(x, params) # allocate buffers
_, fx, st = optimize!(fg!, x, work, params)
@assert isapprox(x, [-π, 0.0]; atol = 1e-6)
@assert isapprox(fx, 1.0; atol = 1e-12)
@assert Int(st) == 0