Optim.jl icon indicating copy to clipboard operation
Optim.jl copied to clipboard

Cannot use Options with box constrained optimization (without providing gradient?)

Open benoitseron opened this issue 1 year ago • 2 comments

I am trying to optimize a function in a box constrained setting. I cannot provide its gradient. This seems not to be an issue if I am not asking for any options, but as soon as I put some, I have the following error.

x_0 = [1., 1.]
lower = zeros(length(x_0))
upper = ones(length(x_0))

optimize(f, x_0, Optim.Options(time_limit = 15.0))
# works
optimize(f,lower, upper, x_0)
# works

optimize(f,lower, upper, x_0 , Optim.Options(time_limit = 15.0))
# fails :

# MethodError: objects of type Vector{Float64} are not callable
# Use square brackets [] for indexing an Array.

# I assume that the problem comes from not providing "g"

I am not sure if this comes from misuse from my side.

benoitseron avatar Oct 26 '22 12:10 benoitseron

Have you tried explicitly instantiating the solver and wrapping it in Fminbox? e.g. Fminbox(NelderMead()).

Fminbox is used in the examples under Box Constrained Optimization. It's a bit indirect to learn about it; the documentation could certainly use some updating. Also, I am not sure if Fminbox works for gradient-free solvers.

Edit: I just checked the source code and Fminbox does indeed seem to support gradient-free methods.

jecs avatar Oct 27 '22 14:10 jecs

There might be missing a dispatch somewhere. Try to specify Fminbox explicitly before the options as @jecs stated.

pkofod avatar Nov 23 '22 09:11 pkofod