aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim
diff options
context:
space:
mode:
authorAaron LI <aly@aaronly.me>2019-02-24 13:40:24 +0800
committerAaron LI <aly@aaronly.me>2019-02-24 13:40:24 +0800
commit2fccca435298939657ac5dac586eae037bd70999 (patch)
tree8c79d10cbc326bbde7907681cb5bca1d507deebf /fg21sim
parent40fa40f841f069c2d74cf0da3831dbea7ad8af1f (diff)
downloadfg21sim-2fccca435298939657ac5dac586eae037bd70999.tar.bz2
utils/analyze: Add parameter 'coef0' to loglinfit()
Diffstat (limited to 'fg21sim')
-rw-r--r--fg21sim/utils/analyze.py9
1 files 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])