本文整理汇总了Python中histogram.Histogram.fit方法的典型用法代码示例。如果您正苦于以下问题:Python Histogram.fit方法的具体用法?Python Histogram.fit怎么用?Python Histogram.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类histogram.Histogram
的用法示例。
在下文中一共展示了Histogram.fit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_1dfit
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import fit [as 别名]
def test_1dfit(self):
p = [100, -20, 1, -0.2]
h = Histogram(100, [0, 10])
x = h.axes[0].bincenters
h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))
p0 = [1, 1, 1, 1]
popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)
assert np.allclose(popt, p, rtol=0.03, atol=0.5)
assert pcov.shape == (len(p), len(p))
示例2: test_2dfit
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import fit [as 别名]
def test_2dfit(self):
fn = lambda xy, *p: poly(p[:4])(xy[0]) + poly([0] + list(p[4:]))(xy[1])
p = [100, -20, 1, -0.2, 80, -5, 0.8]
h = Histogram(100, [0, 10], 100, [0, 10])
xy = h.grid
h.data = fn(xy, *p)
h.data += rand.normal(0, np.sqrt(p[0]), h.data.shape)
p0 = [1, 1, 1, 1, 1, 1, 1]
popt, pcov, ptest = h.fit(fn, p0)
assert np.allclose(popt, p, rtol=0.01, atol=0.01)
assert pcov.shape == (len(p), len(p))
示例3: test_1dfit_zeros
# 需要导入模块: from histogram import Histogram [as 别名]
# 或者: from histogram.Histogram import fit [as 别名]
def test_1dfit_zeros(self):
p = [100, -20, 1, -0.2]
h = Histogram(100, [0, 10])
x = h.axes[0].bincenters
h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))
ii = rand.randint(0, h.axes[0].nbins, 5)
h.data[ii] = 0
p0 = [1, 1, 1, 1]
popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)
assert np.allclose(popt, p, rtol=0.1, atol=1.0)
assert pcov.shape == (len(p), len(p))