# Significantly different parameter estimates when using Static Array (MVector) as initial guess

**URL:** https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645
**Category:** Performance
**Tags:** question
**Created:** [August 26, 2024, 9:03pm UTC](https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645 "2024-08-26T21:03:07Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![DylanEsguerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanesguerra/32/211596_2.png) [@DylanEsguerra](https://discourse.julialang.org/u/DylanEsguerra)
#### Post date: [August 26, 2024, 9:03pm UTC](https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645/1 "2024-08-26T21:03:07Z")

</div>

Hello

I am ODE model fitting using autodiff with Optimization.jl and was looking to improve my code with the use of StaticArrays. The code runs slower than I hoped and has a lot of memory allocations (initially 4G before being cut down to 1g). StaticArrays helped a lot with reducing allocations, but that didn’t have much of an effect on runtime unless I make initial guess of parameter values an MVector. This nearly cuts runtime in half and I was super excited until I found that my parameter estimates have diverged from the original code significantly. Some are nearly 200% lower while others stay close. Loss was also very similar to when I used a regular vector. Parameter values get further from the previous codes estimates the more iterations I optimize for. Has anyone encountered this before? There 13 parameters being fit and initialized by my guess vector for a system of 81 equations. It’s quite a large script and uses data I am not comfortable sharing, but if this sounds familiar to anyone I would love some advice.

---

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [August 26, 2024, 9:26pm UTC](https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645/2 "2024-08-26T21:26:44Z")

</div>

Did you set a time limit on runtime? Perhaps earlier you just stopped after a time limit and now you do more computation in the same time, so you get farther in iterations and have better fits?

Just a thought.

---

<div class="post-metadata">

### Author: ![DylanEsguerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanesguerra/32/211596_2.png) [@DylanEsguerra](https://discourse.julialang.org/u/DylanEsguerra)
#### Post date: [August 26, 2024, 10:23pm UTC](https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645/3 "2024-08-26T22:23:55Z")

</div>

thank you, yes there is a max iterations number which is reached so it is doing the same amount both times.

---

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [August 26, 2024, 10:42pm UTC](https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645/4 "2024-08-26T22:42:32Z")

</div>

if you initialize it very close to the final values from your run without MVector does it stay there and find the same optimum?

If you run with regular arrays does it always find the same optimum?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [August 27, 2024, 2:37pm UTC](https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645/5 "2024-08-27T14:37:21Z")

</div>

Because static arrays linear algebra is not implemented the same, and small floating point differences can compound on a long optimization, I don’t think it’s too surprising at face value? You’d have to identify something actually incorrect for this to be weird. Many local optimizations are chaotic systems anyways, so it’s an expected property.

---

<div class="post-metadata">

### Author: ![DylanEsguerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanesguerra/32/211596_2.png) [@DylanEsguerra](https://discourse.julialang.org/u/DylanEsguerra)
#### Post date: [August 27, 2024, 5:19pm UTC](https://discourse.julialang.org/t/significantly-different-parameter-estimates-when-using-static-array-mvector-as-initial-guess/118645/6 "2024-08-27T17:19:41Z")

</div>

That makes sense, thank you.
