本文整理汇总了Python中streamhist.StreamHist.update方法的典型用法代码示例。如果您正苦于以下问题:Python StreamHist.update方法的具体用法?Python StreamHist.update怎么用?Python StreamHist.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类streamhist.StreamHist
的用法示例。
在下文中一共展示了StreamHist.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_len
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_len():
h = StreamHist(maxbins=5)
assert len(h) == 0
h.update(range(5))
assert len(h) == len(h.bins) == 5
h.update(range(5))
assert len(h) == len(h.bins) == 5
示例2: test_counts
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_counts():
data = [605, 760, 610, 615, 605, 780, 605, 905]
h = StreamHist(maxbins=4, weighted=False)
for p in data:
h.update(p)
counts = [b[1] for b in h.bins]
assert len(data) == reduce(operator.add, counts) == h.total
示例3: test_missing
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_missing():
data = [1, None, 1, 4, 6]
h = StreamHist(maxbins=2)
for p in data:
h.update(p)
assert h.missing_count == 1
assert len(h.bins) == 2
assert h.bins[0][0] == 1 and h.bins[1][0] == 5
示例4: test_bounds
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_bounds():
points = range(15)
h = StreamHist(maxbins=8)
h.update(points)
assert h.bounds() == (0, 14)
h = StreamHist()
assert h.bounds() == (None, None)
示例5: test_negative_densities
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_negative_densities():
points = 10000
h = StreamHist()
data = make_normal(points)
h.update(data)
from numpy import linspace
x = linspace(h.min(), h.max(), 100)
assert all([h.pdf(t) >= 0. for t in x])
示例6: test_freeze
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_freeze():
points = 100000
h = StreamHist(freeze=500)
for p in make_normal(points):
h.update(p)
assert about(h.sum(0), points/2.0, points/50.0)
assert about(h.median(), 0, 0.05)
assert about(h.mean(), 0, 0.05)
assert about(h.var(), 1, 0.05)
示例7: test_string
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_string():
h = StreamHist(maxbins=5)
assert str(h) == "Empty histogram"
h.update(range(5))
string = "Mean\tCount\n----\t-----\n"
string += "0\t1\n1\t1\n2\t1\n3\t1\n4\t1"
string += "\n----\t-----\nMissing values: 0\nTotal count: 5"
assert str(h) == string
示例8: test_var
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_var():
assert StreamHist().update(1).var() is None
h = StreamHist()
for p in [1, 1, 2, 3, 4, 5, 6, 6]:
h.update(p)
assert h.var() == 3.75
h = StreamHist()
for p in make_normal(10000):
h.update(p)
assert about(h.var(), 1, 0.05)
示例9: test_exact_median
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_exact_median():
points = range(15) # Odd number of points
h = StreamHist(maxbins=17)
h.update(points)
assert h.median() == 7
points = range(16) # Even number of points
h = StreamHist(maxbins=17)
h.update(points)
assert h.median() == 7.5
示例10: test_copy
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_copy():
h1 = StreamHist()
h2 = h1.copy()
assert h1.bins == h2.bins
h1.update(make_normal(1000))
assert h1.bins != h2.bins
h2 = h1.copy()
assert h1.bins == h2.bins
h1 = StreamHist().update([p for p in range(4)])
h2 = h1.copy()
assert h1.to_dict() == h2.to_dict()
示例11: test_trim
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_trim():
points = 1000
h = StreamHist(maxbins=10)
for _ in range(points):
h.update(rand_int(10))
assert len(h.bins) == 10 and h.total == points
h = StreamHist(maxbins=10)
for _ in range(points):
h.insert(rand_int(10), 1)
h.trim()
assert len(h.bins) == 10 and h.total == points
示例12: test_update_vs_insert
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_update_vs_insert():
points = 1000
data = make_normal(points)
h1 = StreamHist(maxbins=50)
h1.update(data)
h2 = StreamHist(maxbins=50)
for i, p in enumerate(data):
h2.insert(p, 1)
h2.trim()
h2.trim()
assert h1.to_dict() == h2.to_dict()
示例13: test_median_mean
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_median_mean():
points = 10000
h = StreamHist()
for p in make_uniform(points):
h.update(p)
assert about(h.median(), 0.5, 0.05)
h = StreamHist()
for p in make_normal(points):
h.update(p)
assert about(h.median(), 0, 0.05)
assert about(h.mean(), 0, 0.05)
示例14: test_density
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_density():
h = StreamHist()
for p in [1., 2., 2., 3.]:
h.update(p)
assert about(0.0, h.density(0.0), 1e-10)
assert about(0.0, h.density(0.5), 1e-10)
assert about(0.5, h.density(1.0), 1e-10)
assert about(1.5, h.density(1.5), 1e-10)
assert about(2.0, h.density(2.0), 1e-10)
assert about(1.5, h.density(2.5), 1e-10)
assert about(0.5, h.density(3.0), 1e-10)
assert about(0.0, h.density(3.5), 1e-10)
assert about(0.0, h.density(4.0), 1e-10)
示例15: test_quantiles
# 需要导入模块: from streamhist import StreamHist [as 别名]
# 或者: from streamhist.StreamHist import update [as 别名]
def test_quantiles():
points = 10000
h = StreamHist()
for p in make_uniform(points):
h.update(p)
assert about(h.quantiles(0.5)[0], 0.5, 0.05)
h = StreamHist()
for p in make_normal(points):
h.update(p)
a, b, c = h.quantiles(0.25, 0.5, 0.75)
assert about(a, -0.66, 0.05)
assert about(b, 0.00, 0.05)
assert about(c, 0.66, 0.05)