summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-07-04 15:37:10 +0800
committerAaron LI <aaronly.me@outlook.com>2016-07-04 15:37:10 +0800
commit29fcb29a3eefb55e33ca68300eb80730bc10bad3 (patch)
treeeadfc264ceda9baf274cce2fbd801fe32435df67
parent718963dfb658fe2dd333d2df88a809c9d3d9383e (diff)
downloadcexcess-29fcb29a3eefb55e33ca68300eb80730bc10bad3.tar.bz2
fitting_models.py: Add "report()" method
-rw-r--r--fitting_models.py33
1 files changed, 32 insertions, 1 deletions
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):
"""