Behaviour of least_squares fit for aborted fits #894
Replies: 1 comment
-
@eendebakpt Thanks for the report. It looks like we are not handling that "abort because of too many function evals" with least_squares very well. I think we can (and should) fix that - as you suggest, calculate the residual and fit statistics with the last set of parameter values. In fact, we are doing that for other solvers ("if aborted, use last values, calculate all the stats"), just not "least_squares". I'm also sort of surprised that "least_squares/trf" is not converging for this fitting problem. It doesn't look that hard to me, and "leastsq" seems to handle it OK. It is certainly possible that we could be using least_squares/trf better, but I think we are using basically the default settings.... |
Beta Was this translation helpful? Give feedback.
-
In one of my applications I was optimizing on the reduced chi squared value. For one of the bad fits, the reduced chi squared reported by lmfit was negative infinity, which causes my application to pick this bad solution.
For the case at hand (minimal example below), the fitting is aborted with message
Fit aborted: number of function evaluations > 14000
. The values ofModelResult.residual
andModelResult.redchi
are both-inf
.-inf
compares to other values such as 0.0012. A better value in case of an aborted fit could beNaN
best_values
, so theresidual
can be calculatedThe change that introduced this behaviour is 5c15004 @newville.
Can we adapt the least-squares fitting code to:
NaN
instead of-inf
to signal a bad fit?residual
, even if the fit was aborted (for some reason)?Minimal example reproducing the behavior:
Beta Was this translation helpful? Give feedback.
All reactions