# The function to optimize in JuMP

**URL:** <https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964>\
**Category:** Optimization (Mathematical)\
**Created:** [July 20, 2017, 1:36am UTC](https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964 "2017-07-20T01:36:42Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 3, 2017, 5:05pm UTC](https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964/21 "2017-08-03T17:05:24Z")

</div>

The problem is bullet number 3. See e.g. [https://github.com/JuliaDiff/ForwardDiff.jl/issues/136#issuecomment-237941790](https://github.com/JuliaDiff/ForwardDiff.jl/issues/136#issuecomment-237941790)

---

<div class="post-metadata">

**Author:** ![MCSikivie](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@MCSikivie](https://discourse.julialang.org/u/MCSikivie)\
**Post date:** [August 28, 2017, 7:20pm UTC](https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964/22 "2017-08-28T19:20:53Z")

</div>

I just want to be sure I really understand this error because I’ve seen it in another context now. Use of println(typeof(.)) statements tell me that each element of y is float64 after it is modified as well as the initial vector being Array{Float64,2}. So I’m not really assigning the same name to data of different types the way you warn me about, right? It’s the dual numbers required for autodiff that make those elements of y into a different type that somehow could not be converted back to Float64 and caused a conversion error.

Is that because Julia needs to convert the vector y to have the same number of dimensions as the scalars alpha and beta for the autodiff?

---

<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:** [August 28, 2017, 7:56pm UTC](https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964/23 "2017-08-28T19:56:48Z")

</div>

If your `Array{Float64,N}` is supposed to admit some dual numbers throughout the autodiff, then that will give you the same error. When this happens, you need to go back and see which arrays the dual numbers will be touching and initialize those using `typeof(some_arg)` as the element type of the array instead of some specific number type like `Float64` or `Int`. Type stability will make your code (a lot) faster, but it’s actually kind of different from the source of this error, so I probably should have made that point clearer.

---

<div class="post-metadata">

**Author:** ![MCSikivie](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@MCSikivie](https://discourse.julialang.org/u/MCSikivie)\
**Post date:** [August 28, 2017, 10:36pm UTC](https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964/24 "2017-08-28T22:36:20Z")

</div>

This sentence was unclear. “When this happens, you need to go back and see which arrays the dual numbers will be touching and initialize those using typeof(some\_arg) as the element type of the array instead of some specific number type…”

So if some matrix M will be perturbed, directly or indirectly, by dual numbers, the matrix M needs to be initialized to be of the same type as the parameters that determine the values of the elements inside M? At least if those parameters that determine M are variables that the function is maximized over and therefore perturbed by dual numbers?

---

<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:** [August 29, 2017, 2:03am UTC](https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964/25 "2017-08-29T02:03:09Z")

</div>

Correct, that’s what I meant!

[Previous page](https://discourse.julialang.org/t/the-function-to-optimize-in-jump/4964.md?page=1)
