How to set lower and upper bound for SimulatedAnnealing OptimizationProblem's? Tired "lu=" and "ub=" but doesn't seem to work

This is the sampel code:

using GalacticOptim, Optim
function tmp(x,p)
   return (x[1]-2)^2 
end
prob = OptimizationProblem(tmp,[4.],lb=[3],ub=[6])
res = solve(prob,SimulatedAnnealing())

the result is correct 1.9982228757130818. However, I set a lower bound =3, so would expect it to step here. How do I get the lower bound to work?

Similarily, for:

using GalacticOptim, Optim
function tmp(x,p)
   return -(x[1]-2)^2 
end
prob = OptimizationProblem(tmp,[4.],lb=[3],ub=[6])
res = solve(prob,SimulatedAnnealing())

I would expect to just hit the upper bound, but I get the answer 400.7172021819915.

Am I missing something obvious here?
(also at https://github.com/SciML/GalacticOptim.jl/issues/171)

The modified program

using GalacticOptim, Optim
function tmp(x,p)
   return (x[1]-2)^2
end
fun = OptimizationFunction(tmp, GalacticOptim.AutoForwardDiff())
prob = OptimizationProblem(fun,[4.],lb=[3],ub=[6])
res = solve(prob,Fminbox())
println(res)

using GalacticOptim, Optim
function tmp(x,p)
   return -(x[1]-2)^2
end
fun = OptimizationFunction(tmp, GalacticOptim.AutoForwardDiff())
prob = OptimizationProblem(fun,[4.],lb=[3],ub=[6])
res = solve(prob,Fminbox())
println(res)

returns

retcode: Default
u: [3.0000000013333334]
Final objective value:     1.0000000026666669

retcode: Default
u: [5.999999999666667]
Final objective value:     -15.999999997333333

Furthermore Optim.jl’s documentation https://github.com/JuliaNLSolvers/Optim.jl/blob/adc5b277b3f915c25233b45f8f2dd61006815e63/docs/src/algo/simulated_annealing.md
does not mention support for bounds. This looks like a documentation problem to me.

1 Like

I found out about the bounds at OptimizationProblem · GalacticOptim.jl, but you might be right and those not applying to the SimulatedAnnealing algorithm.

I have a problem where derivatives don’t make sense, so I figured I was limited to that one and NelderMead (https://galacticoptim.sciml.ai/stable/local_optimizers/local_derivative_free/), which I ran into other problems with (it errors at the HPC I have access to, I’ve asked the HPC people for help with interpreting the error message the HPC yielded).

Open an issue. GalacticOptim should just wrap the algorithm in an FMinBox automatically if you add bounds.

3 Likes

Got it :+1:

There is a bounded simulated annealing algorithm in Optim.jl called SAMIN. An example of how to call it would be
opt = Optim.optimize(obj, lb, ub, θ, SAMIN())
where ib, ub and θ are all vectors.

3 Likes

Thanks for pointing that out, I will try to get it to work.