# Optim box constrained optimization

**URL:** <https://discourse.julialang.org/t/optim-box-constrained-optimization/12463>\
**Category:** Optimization (Mathematical)\
**Created:** [July 18, 2018, 12:49pm UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463 "2018-07-18T12:49:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 18, 2018, 12:49pm UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463/1 "2018-07-18T12:49:27Z")

</div>

Here’s the example for box constrained optimization in the [docs](http://julianlsolvers.github.io/Optim.jl/stable/#user/minimization/#box-constrianed-optimization):

```julia
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?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [July 18, 2018, 12:54pm UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463/2 "2018-07-18T12:54:47Z")

</div>

Why not use the latest version v0.15.2?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 18, 2018, 1:00pm UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463/3 "2018-07-18T13:00:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [July 18, 2018, 1:08pm UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463/4 "2018-07-18T13:08:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 18, 2018, 3:31pm UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463/5 "2018-07-18T15:31:46Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [July 18, 2018, 7:57pm UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463/6 "2018-07-18T19:57:05Z")

</div>

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!).

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 19, 2018, 7:19am UTC](https://discourse.julialang.org/t/optim-box-constrained-optimization/12463/7 "2018-07-19T07:19:26Z")

</div>

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!
