# Optimization with complex requirements

**URL:** <https://discourse.julialang.org/t/optimization-with-complex-requirements/107266>\
**Category:** Optimization (Mathematical)\
**Tags:** optimization\
**Created:** [December 7, 2023, 11:08am UTC](https://discourse.julialang.org/t/optimization-with-complex-requirements/107266 "2023-12-07T11:08:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Post date:** [December 7, 2023, 11:08am UTC](https://discourse.julialang.org/t/optimization-with-complex-requirements/107266/1 "2023-12-07T11:08:25Z")

</div>

My optimization problem can be simplified as follows.  
A vector of coefficients `x` has an upper an lower bound for each element.  
`μ` is a function of the elements of `x` that itself has an upper and lower bound.  
And `μ` has an error that is also a function of `x` that we want to minimize.

I’ve made an attempt with both Optim.jl and JuMP.jl with simplified versions of my problem since neither seems to easily accept complex objectives like `μ` needing to be in a certain range.

To be a little bit more specific regarding my problem, I’m designing a measurement device and the error of the resultant (`μ`) depends on the dimensions of the device and I’m trying to find the optimal values for these dimensions. The `μ` should be in a certain range since those are the requirements.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [December 7, 2023, 11:20am UTC](https://discourse.julialang.org/t/optimization-with-complex-requirements/107266/2 "2023-12-07T11:20:55Z")

</div>

It feels like `Optim` and `JuMP` should work for this. Can you give more details, preferrably with code to go along with them.

Another note, if `μ` is a function of `x`, then the bounds on `μ` are redundant, since it is already determined. If the bounds are on a noisy `μ'` then it is probably a good idea to have `μ'` as a parameter and minimize the tension between `μ` and `μ'`

---

<div class="post-metadata">

**Author:** ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)\
**Post date:** [December 7, 2023, 12:09pm UTC](https://discourse.julialang.org/t/optimization-with-complex-requirements/107266/3 "2023-12-07T12:09:42Z")

</div>

I don’t understand why the bounds on `μ` are redundant. In my case, the bounds on `x` can give `μ` significantly outside the desired range. Which is why I’m trying to optimize `x`.

I think Optim.jl can only minimize an objective function and thus can’t also “reject” an invalid `μ`. JuMP.jl may be able to do these things but my attempt seems to have failed because the solvers I tried can’t take multiple objectives. And I couldn’t figure out any other solvers.

I don’t know what it means to minimize the “tension” between `μ` and `μ'` but it sounds like we’re inserting a dependent parameter to optimize for? If so that might solve the problem.

A code example of what I’ve tried is something like

`w_μ(x) = norm(dμdx(x) .* w_x)`  
`lower = [0.001, 0.002, 0.003]`  
`upper = [0.050, 0.012, 0.013]`  
`opt = optimize(w_μ, lower, upper, [0.010, 0.005, 0.008])`  
Where `w_x` is the error of `x` and is constant.  
I’ve been ignoring the constraint on `μ` since I don’t know how to implement them into Optim.jl.  
JuMP.jl threw an error when I tried to give it the complex `w_μ` objective so none of that worked.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [December 9, 2023, 8:33pm UTC](https://discourse.julialang.org/t/optimization-with-complex-requirements/107266/4 "2023-12-09T20:33:12Z")

</div>

> JuMP.jl threw an error when I tried to give it the complex . `w_μ` objective so none of that worked.

Can you share your example inn more detail? JuMP should work for this.
