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

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.

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.

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

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?

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.

1 Like

That makes sense, thank you.