Behaviour of fits that reach max_max_nfev #1017
Replies: 4 comments
-
|
@dangarciahe If a fit aborts because it reached For many methods, "latest" and "best so far" should not be too far off. But, this might not be the case for some global solvers. Of course, global solvers may require many function calls and fail frequently — and some more often than others. For most iterative solvers where a solution is possible, the "latest" is likely to be an improvement over the starting values. Increasing You did not provide any code or any indication of what you are trying to do or what result you actually got. If you want further help, you will have to show us what you are doing and what results you get. See https://en.wikipedia.org/wiki/Minimal_reproducible_example. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @newville, thanks for the clarification. I'm trying to do a multivariable fitting to a rather complex function under some private data. Since I'm just playing around, I tried A Minimal, Complete, and Verifiable example import lmfit
def parabolic(p):
x = float(p["x"])
y = (x)**2
print (f"x: {x:.1f}, y:{y:.1f}")
return y
fit_params = lmfit.Parameters()
fit_params.add('x', value=-2, min=-10, max=10, vary=True)
result = lmfit.minimize(parabolic, fit_params, method="ampgo", max_nfev=400)
print(lmfit.fit_report(result))Fit report: Version information: With the prints, one can see that there's a lot of near-0 evaluations, and even that the returned evaluation is worse than the last one, so returning -6.27 doesn't make much sense. Trying
Therefore, I think an improvement would be to return the overall best set of parameters, not just for ampgo but in general. If you agree on this, I would be happy to help with a PR under some guidance. |
Beta Was this translation helpful? Give feedback.
-
|
@dangarciahe well, (and: a concrete example with real code is always helpful), I do see that the ampgo method does, in fact, always return a "best parameters so far" result, and we are not actually using that, but instead using "last tried". So, this should be easily fixable (in the "ampgo" wrapper in If you'd like to play around with that a submit a PR, that would be great. Otherwise, I can put it on my ToDo list. |
Beta Was this translation helpful? Give feedback.
-
|
@newville Thanks for the info. I'll play around and submit the PR. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I've been playing around with global optimization algorithms, and I'm unsure about the intended behavior of some. When a
lmfit.minimize()problem finishes due to reachingmax_nfev, is the intended behavior to return the latest values of the parameters, or the values of the parameters for the best recorded fit?I saw #679 and #665, but I still get behaviors of return of latest values, so I'm a bit confused.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions