Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error? in OptimizationPackage/Optimization.md Documentation #837

Open
gbarz opened this issue Sep 29, 2024 · 0 comments
Open

Error? in OptimizationPackage/Optimization.md Documentation #837

gbarz opened this issue Sep 29, 2024 · 0 comments
Labels
question Further information is requested

Comments

@gbarz
Copy link

gbarz commented Sep 29, 2024

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)

@gbarz gbarz added the question Further information is requested label Sep 29, 2024
@gbarz gbarz changed the title Unclear re documentation examples: OptimizationPackage/Optimization.md Error? in OptimizationPackage/Optimization.md Documentation Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant