# Optim.jl Implementing box minimization does not work for me

**URL:** <https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293>\
**Category:** General Usage\
**Tags:** package\
**Created:** [July 31, 2023, 8:14am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293 "2023-07-31T08:14:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ditfurth](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@ditfurth](https://discourse.julialang.org/u/ditfurth)\
**Post date:** [July 31, 2023, 8:14am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293/1 "2023-07-31T08:14:29Z")

</div>

Hi all,

I am trying to implement a box minimization, but am struggling to do so.

I am at the moment trying to run the line:

```julia
    results = optimize(x -> blp_iteration(dt, z, x, W, random_coeff, fixed_coeff,agents), init, lower, upper, Fminbox(BFGS()), Optim.Options(f_tol = 1e-40, x_tol = 1e-40, g_tol = 1e-40, iterations = 5000))

```

and have been using [Minimizing a function - Optim.jl](http://julianlsolvers.github.io/Optim.jl/v0.9.3/user/minimization/#box-minimization) to figure it out. There, it suggests running Fminbox{BFGS}() which does not work at all for me. What I get is the error:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed349399f21b83421a16c0071807d65649526983.jpeg)

This error does not come, when I remove lower, upper, and Fminbox(). Then, it just manages to solve it.

Best,  
Jakob

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [July 31, 2023, 8:26am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293/2 "2023-07-31T08:26:12Z")

</div>

Hi, what is the value of `init`, `lower`, `upper` ? my intuition says that you are passing integer values instead of float values

---

<div class="post-metadata">

**Author:** ![ditfurth](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@ditfurth](https://discourse.julialang.org/u/ditfurth)\
**Post date:** [July 31, 2023, 8:29am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293/3 "2023-07-31T08:29:20Z")

</div>

```julia
init = [0.4,0.4,0,0.4]
lower = [0,0,-10,-10]
upper = [10,10,10,10]

```

This is how they are defined. What fix would you suggest ?

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [July 31, 2023, 8:30am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293/4 "2023-07-31T08:30:13Z")

</div>

try using:

```julia
lower = [0.0,0.0,-10.0,-10.0]
upper = [10.0,10.0,10.0,10.0]

```

---

<div class="post-metadata">

**Author:** ![ditfurth](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@ditfurth](https://discourse.julialang.org/u/ditfurth)\
**Post date:** [July 31, 2023, 9:04am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293/5 "2023-07-31T09:04:34Z")

</div>

u are right, it runs now. How did you know this?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [July 31, 2023, 10:19am UTC](https://discourse.julialang.org/t/optim-jl-implementing-box-minimization-does-not-work-for-me/102293/6 "2023-07-31T10:19:49Z")

</div>

Your lower and upper were arrays of Integers (because all initial values were Ints). The error was complaining about some operation failing for that.

You could also have used `lower = Float64[0, 0, -10, -10]`
