From 2fccca435298939657ac5dac586eae037bd70999 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 24 Feb 2019 13:40:24 +0800 Subject: utils/analyze: Add parameter 'coef0' to loglinfit() --- fg21sim/utils/analyze.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fg21sim/utils/analyze.py b/fg21sim/utils/analyze.py index 65dfa47..a052ad4 100644 --- a/fg21sim/utils/analyze.py +++ b/fg21sim/utils/analyze.py @@ -88,7 +88,7 @@ def countdist_integrated(x, nbin, log=True, xmin=None, xmax=None): return counts, bins, binedges -def loglinfit(x, y, **kwargs): +def loglinfit(x, y, coef0=(1, 1), **kwargs): """ Fit the data points with a log-linear model: y = a * x^b @@ -96,7 +96,10 @@ def loglinfit(x, y, **kwargs): ---------- x, y : list[float] The data points. - kwargs : dict + coef0 : two-float tuple/list, optional + The initial values of the coefficients (a0, b0). + Default: (1, 1) + **kwargs : Extra parameters passed to ``scipy.optimize.least_squares()``. Returns @@ -121,7 +124,7 @@ def loglinfit(x, y, **kwargs): "f_scale": np.mean(logy), } args.update(kwargs) - p, pcov = optimize.curve_fit(_f_poly1, logx, logy, p0=(1, 1), **args) + p, pcov = optimize.curve_fit(_f_poly1, logx, logy, p0=coef0, **args) coef = (np.exp(p[0]), p[1]) perr = np.sqrt(np.diag(pcov)) err = (np.exp(perr[0]), perr[1]) -- cgit v1.2.2