Non-Linear Least Squares Minimization, with flexible Parameter settings, based on scipy.optimize, and with many additional classes and methods for curve fitting.
Using scalar minimizers andnumdifftoolsand parameters with bounds, the reported value for the last parameter in the list can be (slightly) from the actual best-fit value.
I believe this is due to Miniminze._calculate_covariance_matrix and specifically numdifftools.Hessian allowing the values to change and not fully restoring the values. I'm not sure why this affects only the final variable, but it appears to be that way.
Description
Using scalar minimizers and
numdifftools
and parameters with bounds, the reported value for the last parameter in the list can be (slightly) from the actual best-fit value.I believe this is due to
Miniminze._calculate_covariance_matrix
and specificallynumdifftools.Hessian
allowing the values to change and not fully restoring the values. I'm not sure why this affects only the final variable, but it appears to be that way.A Minimal, Complete, and Verifiable example
Error message:
The output of the above script is
Note that although the best chi-square is correctly reported, the value for
slope
is off slightly.FWIW, this won't happen if the bounds are removed or if
numdifftools
is not installed.Version information
Python: 3.7.7 (default, Mar 23 2020, 22:36:06) [GCC 7.3.0]
lmfit: 1.0.1, scipy: 1.4.1, numpy: 1.18.1, asteval: 0.9.18, uncertainties: 3.1.2
And: numdifftools version 0.9.39.
Link(s)
This began as a discussion on the mailing list: https://groups.google.com/d/msg/lmfit-py/uof1FDWOD7M/d7muQSQyAQAJ