From 29fcb29a3eefb55e33ca68300eb80730bc10bad3 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 4 Jul 2016 15:37:10 +0800 Subject: fitting_models.py: Add "report()" method --- fitting_models.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/fitting_models.py b/fitting_models.py index a864a92..44b679a 100644 --- a/fitting_models.py +++ b/fitting_models.py @@ -2,8 +2,14 @@ # # Weitan LI # Created: 2016-06-26 -# Updated: 2016-06-26 +# Updated: 2016-07-04 # +# Change logs: +# 2016-07-04: +# * Add "report()" method to class "FittingModel" +# + +from collections import OrderedDict import numpy as np import lmfit @@ -121,6 +127,31 @@ class FittingModel: p.loads(params) self.params = p + def report(self, rtype): + """ + Report the fitting results, e.g., g.o.f, chisqr, parameters, etc. + """ + if rtype == "fitting": + fitted = self.fitted + results = OrderedDict([ + ("nfev", fitted.nfev), + ("ndata", fitted.ndata), + ("nvarys", fitted.nvarys), # number of variable parameters + ("nfree", fitted.nfree), # degree of freedom + ("chisqr", fitted.chisqr), + ("redchi", fitted.redchi), + ("aic", fitted.aic), + ("bic", fitted.bic), + ]) + elif rtype == "parameters": + results = OrderedDict([ + (pn, [par.value, par.min, par.max, par.vary]) + for pn, par in self.params.items() + ]) + else: + raise ValueError("invalid rtype: %s" % rtype) + return results + class ABModel(FittingModel): """ -- cgit v1.2.2