-
Notifications
You must be signed in to change notification settings - Fork 46
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
LN_COBYLA steps out of bounds #166
Comments
Please provide a reproducible example. |
I observe the same out-of-bounds behavior. I seems that the problem occurs when the solution is close the boundary. Minimal working example using NLopt
sol = [0.05, 0.95]
function mini(x, g)
if !all(0 .≤ x .≤ 1)
println("out of bounds ", x)
end
return sum((x .- sol) .^ 2)
end
# formulate constraints in form of f(x) ≤ 0
function constraint1(result, x, g)
result[:] = -x # 0 ≤ x
end
function constraint2(result, x, g)
result[:] = x .- 1.0 # x ≤ 1
end
n = 2
opt = Opt(:LN_COBYLA, n)
opt.min_objective = mini
inequality_constraint!(opt, constraint1, zeros(n))
inequality_constraint!(opt, constraint2, zeros(n))
(minf, minx, ret) = optimize(opt, 0.5 * ones(n)) yields
Although I would not regard |
@eggix: it might step out of bounds during the search, but the final solution respects the bounds? I still can't reproduce the original error in the first post. |
Yes, the final solution respects the bounds. However, in my use case the function I want to minimize is not defined outside the bounds. I hoped the inequality constraints would be an elegant solution to restrict the evaluation of the function to inside the bounds. But it seems this is not the case, and might be outside the scope of the algorithm. |
You could try pass In general though, you should expect most algorithms could step out of bounds during the solve, but you can be sure that final solutions respect the bounds. I don't think there's anything we can/should do at the NLopt.jl level to fix this. |
Yes, this is documented. General inequality constraints may (and often will) be violated at intermediate optimization steps. However, the "box" constraints set by So, if you have a function which is not defined for certain values of the variables, I would try to re-parameterize it so that you can express that constraint in terms of box constraints. For example, if you have two variables x,y and your function is only defined for y ≥ x², you can change variables to (x,u) and let y = x²+u, with a box constraint u ≥ 0. |
While running NLopt with
LN_COBYLA
, the optimization routine violated a lower bound and the program execution stopped. Obviously, this is undesirable behaviour. I also note that this problem occurs sometimes but not always.Attached is a screenshot that shows the error stack with the bound violation numbers.
0.01 was the lower bound and 1.0 the upper bound. The algorithm assigned a value of 0.00987... to the variable.
The text was updated successfully, but these errors were encountered: