-
-
Notifications
You must be signed in to change notification settings - Fork 99
Description
The code provided in the document examples below does not run successfully for me in Julia 1.10.
Instead the following is returned in both the unconstrained and constrained cases:
ERROR: UndefVarError: LBFGS not defined
In the unconstrained problem, if Optimization.LBFGS() is changed to just LBFGS(), it finds the solution. However, the constrained problem still returns the following:
ERROR: The algorithm LBFGS{Nothing, LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"} does not support constraints. Either remove the cons function passed to OptimizationFunction or use a different algorithm.
Is there something else needed to get this to run successfully?
Unconstrained rosenbrock problem
using Optimization, Zygote
rosenbrock(x, p) = (p[1] - x[1])^2 + p[2] * (x[2] - x[1]^2)^2
x0 = zeros(2)
p = [1.0, 100.0]
optf = OptimizationFunction(rosenbrock, AutoZygote())
prob = Optimization.OptimizationProblem(optf, x0, p)
sol = solve(prob, Optimization.LBFGS())
With nonlinear and bounds constraints
function con2_c(res, x, p)
res .= [x[1]^2 + x[2]^2, (x[2] * sin(x[1]) + x[1]) - 5]
end
optf = OptimizationFunction(rosenbrock, AutoZygote(), cons = con2_c)
prob = OptimizationProblem(optf, x0, p, lcons = [1.0, -Inf],
ucons = [1.0, 0.0], lb = [-1.0, -1.0],
ub = [1.0, 1.0])
res = solve(prob, Optimization.LBFGS(), maxiters = 100)