LsqFit.jl icon indicating copy to clipboard operation
LsqFit.jl copied to clipboard

lmfit returns optimum worse than starting point

Open chriswaudby opened this issue 4 years ago • 3 comments

I'm trying to run a least squares fit, with lower/upper bounds, but the result that gets returned is worse than the starting point! My residuals function is a fairly complex calculation - I'm not sure how to wrap it up into a simple example here - but the end result is below:

julia> p0 = [0.020250043260463747, 1285.3299488743028, 2.0, 16.88799046247614, 5.766575053897874, 90.7064551215671]
julia> lower = [0.001, 10, 2, 2, 2, 2]
julia> upper = [0.5, 1e5, 200, 200, 200, 200]
julia> sum(residuals(p0).^2)  # SSR for starting point
3499.916361506747

julia> fit = LsqFit.lmfit(p -> residuals(p), p0, Float64[], lower=lower, upper=upper);
julia> sum(fit.resid.^2)  # SSR of 'optimum' point
242587.48739601774

julia> fit = LsqFit.lmfit(p -> residuals(p), p0, Float64[], lower=p0, upper=p0);
julia> sum(fit.resid.^2)
3499.916361506747

julia> fit = LsqFit.lmfit(p -> residuals(p), p0, Float64[])
julia> sum(fit.resid.^2)  # SSR of unconstrained (unphysical) optimum
117.90107057638473

I noticed that one of the initial parameters is equal to the lower bound, but if I increase this I still get the same wrong result.

chriswaudby avatar Oct 08 '20 12:10 chriswaudby

I noticed the same behavior when using bounds. Unfortunately I can not reproduce it with a MWE and I can't share the original piece of code :(

jibaneza avatar Dec 08 '20 18:12 jibaneza

Interesting. I wonder if it fails to take a step at all and then reports a failed step. It's a bit hard without a mwe, but I can try to look at some point.

pkofod avatar Dec 17 '20 13:12 pkofod

Did #182 fix this?

pkofod avatar Oct 31 '21 21:10 pkofod

Please reopen with an example and I'll try to debug it.

pkofod avatar Sep 03 '22 15:09 pkofod