LsqFit.jl
LsqFit.jl copied to clipboard
lmfit returns optimum worse than starting point
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.
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 :(
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.
Did #182 fix this?
Please reopen with an example and I'll try to debug it.