Hi all,Is there a reliable way to check the validity of a MinimizerResult based on its attributes for all (or even most) available fitting methods?
Specifically, I’m referring to the MinimizerResult attributes such as status, success, errorbars, message. The documentation says these are “possible” attributes -- one learns after the fact how important that single word is in the docs as indeed they are only sometimes present. Having the attributes always initialized to a known default if not set by the method would be kinder to the developer (I note that Minimizer does initialize these, while MinimizerResult does not). Then something like this would not raise AttributeError depending on the method chosen:
fitresult = minimize(...,method=kwargs[‘method’])if fitresult.success and fitresult.errorbars:# do somethingelse:# do something else
I think the workaround is to use Minimizer.minimize() instead of minimize() and check the attributes on the Minimizer instance.
Version info: lmfit 1.0.3, python 3.7.10thanks,Marc
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/3ae05403-5753-4050-ac3e-2ed78655fcefn%40googlegroups.com.
Hi Marc,On Tue, Nov 2, 2021 at 2:17 PM Marc W. Pound <mpo...@umd.edu> wrote:Hi all,Is there a reliable way to check the validity of a MinimizerResult based on its attributes for all (or even most) available fitting methods?I guess it sort of depends on what you mean by "validity".
Specifically, I’m referring to the MinimizerResult attributes such as status, success, errorbars, message. The documentation says these are “possible” attributes -- one learns after the fact how important that single word is in the docs as indeed they are only sometimes present. Having the attributes always initialized to a known default if not set by the method would be kinder to the developer (I note that Minimizer does initialize these, while MinimizerResult does not). Then something like this would not raise AttributeError depending on the method chosen:fitresult = minimize(...,method=kwargs[‘method’])if fitresult.success and fitresult.errorbars:# do somethingelse:# do something elseYeah, I don't disagree with that, at least not in principle. Certainly, *some* attributes could have default values indicating "not a valid value", perhaps initialized as `None`. That is, if `status` is `None`, the fit probably never really even happened....
I think the workaround is to use Minimizer.minimize() instead of minimize() and check the attributes on the Minimizer instance.Yeah, I do agree that MinimizerResult could be better. A PR to give initial values of `None` (or some other invalid value) would be welcome.
Version info: lmfit 1.0.3, python 3.7.10thanks,Marc
--Matt
I think the workaround is to use Minimizer.minimize() instead of minimize() and check the attributes on the Minimizer instance.Yeah, I do agree that MinimizerResult could be better. A PR to give initial values of `None` (or some other invalid value) would be welcome.Since Minimizer has already made a choice on the default attribute values, I propose changing line 695 in Minimizer.prepare_fit to pass those defaults when its MinimizerResult is instantiated. i.e. fromself.result = MinimizerResult()toself.result = MinimizerResult(covar=self.covar, success = self.success, errorbars = self.errorbars, etc)(but neatly wrapping them in a kwargs dict instead of a long line of parameters).I'm happy to do a PR on this.
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/1947ED98-8A14-4CB7-AF43-1922DC32E399%40gmail.com.