Description
First Time Issue Code
Yes, I read the instructions and I am sure this is a GitHub Issue.
Description
This is a followup to this discussion on the mailing list, where it was recommended to start an issue for further discussion:
https://groups.google.com/g/lmfit-py/c/nrecDPD8VT0/m/I6P990EgAwAJ
On this commit, @reneeotten forced coercion of input data, including independent variables, and data to be fit, to numpy float64 arrays. In scipy.leastsq, sqrt(epsfcn)
is multiplied by the input data to determine the step size. The default, None
, results in a step size relative to the precision of the data. If a custom model is used with internal precision less than this, it may result in the fitter not being able to converge, because the initial steps are smaller than the model resolution.
In our case, with the internal model and data both being float32, setting 'epsfcn'~>1e-13
results in the fits succeeding. If lmfit is going to coerce inputs to float64, it may be worth also forcing epsfcn to a larger value than the default, possibly conditional on whether the data had to be upcast to float. On the other hand, it may be better to only coerce in some cases, or only coerce the output, not the input. Finally, making a note in the docs that the input data is coerced to float64 and that epsfcn might need to be increased for models with less internal precision might be enough. There are a variety of tradeoffs here (see mailing list discussion).
A couple of related past issues: #727 and #723 .
A Minimal, Complete, and Verifiable example
I don't have an mcve for this at present, but can try to come up with one if a more specific example is required.
Error message:
This doesn't necessarily result in an error message, just a lack of the fit converging. In our case, lmfit>=1.0.3 failed to converge with our model until we set epsfcn=1e-10
.
Version information
Python: 3.10.9 | packaged by conda-forge | (main, Feb 2 2023, 20:20:04) [GCC 11.3.0]
lmfit: 0.0.post2673+g729491d, scipy: 1.10.0, numpy: 1.21.6,asteval: 0.9.28, uncertainties: 3.1.7
Link(s)
https://groups.google.com/g/lmfit-py/c/nrecDPD8VT0/m/I6P990EgAwAJ