本文整理汇总了Python中stream.Stream.add_points方法的典型用法代码示例。如果您正苦于以下问题:Python Stream.add_points方法的具体用法?Python Stream.add_points怎么用?Python Stream.add_points使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Stream
的用法示例。
在下文中一共展示了Stream.add_points方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_tree
# 需要导入模块: from stream import Stream [as 别名]
# 或者: from stream.Stream import add_points [as 别名]
def _test_tree(self,real_cost, k, sizes, trials, z, chunks):
x = []
y_cor = []
y_uni = []
weights_avg = []
for size in sizes:
uni_cost = []
cor_cost = []
print "size:", size, "trials: ",
x.append(size)
for t in range(0, trials):
#uni sampling:
s = np.random.choice(range(0, self.p.shape[0]),size)
s = self.p[s]
centers = KMeans(n_clusters=k).fit(s).cluster_centers_
res = self._compute_cost(self.p, centers)
uni_cost.append(1-real_cost/res)
#non uni sampling with tree:
stream = Stream(Coreset,chunks,size,k)
stream.add_points(self.p)
p_cset, w_cset = stream.get_unified_coreset()
weights_avg.append(np.sum(w_cset))
best_cost = float("inf")
for zz in range(0, z):
e = w_KMeans.KMeans(p_cset, np.expand_dims(w_cset, axis=0), k, 300).compute()
res = self._compute_cost(self.p, e)
if res < best_cost:
best_cost = res
res = best_cost
cor_cost.append(1-real_cost/res)
sys.stdout.write(".")
sys.stdout.flush()
c_mistake = np.average(cor_cost)
u_mistake = np.average(uni_cost)
y_uni.append(u_mistake)
y_cor.append(c_mistake)
print " mistake for uniform:", round(u_mistake, 10), "coreset:", round(c_mistake, 10)
print "weight average mistake for all(!) of the trails(should be clost to 0): ", 1-np.sum(self.w)/np.average(weights_avg)
return x, y_uni, y_cor