Optim box constrained optimization

Here’s the example for box constrained optimization in the docs:

using Optim
f(x) = (1.0 - x[1])^2 + 100.0 * (x[2] - x[1]^2)^2

function g!(G, x)
    G[1] = -2.0 * (1.0 - x[1]) - 400.0 * (x[2] - x[1]^2) * x[1]
    G[2] = 200.0 * (x[2] - x[1]^2)
end

lower = [1.25, -2.1]
upper = [Inf, Inf]
initial_x = [2.0, 2.0]
inner_optimizer = GradientDescent()
results = optimize(f, g!, lower, upper, initial_x, Fminbox(inner_optimizer))

This throws a MethodError: cannot convert an object of type Optim.GradientDescent{LineSearches.InitialPrevious{Float64}, LineSearchesHagerZhang{Float64},Void,Optim.##43#45} to an object of type Optim.Fminbox

This is using Optim v0.14.1 on Julia v0.6.2. Is there an issue with the documentation, or am I getting something wrong here?

1 Like

Why not use the latest version v0.15.2?

Fair question, that I can’t answer - Pkg.update() doesn’t seem to want to upgrade me, is it possible that using Julia 0.6.2 (which I can’t change that easily on the system I’m currently on) prevents me from getting the latest version?

That’s weird, could be conflicting requirements from other packages. Not sure if this is a great idea but you can always do git checkout v0.15.2 in the .julia/v0.6/Optim folder.

Came across this quite randomly, so probably won’t try and do that until I desperately need the Fminbox constructor to work! Is this issue solved in 0.15.2?

Should be, yes. But what is your Pkg.status()? Have you already checked something else out to its master branch?

Edit: To be clear, nothing is fixed on the latest version. You’re simply using documentation for one version of Optim and trying to use it to make a constructor call in another version of the package (where the signature was different!).

All good then, apologies for the confusion! Pkg.status() shows everything as normal, no checked out packages, but as I don’t desperately need this functionality right now I’ll just wait and see - will surely get onto 0.15.2 at some point!

1 Like