summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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):
"""