def normalize_source_weights(points, wcounts):
wsum = 0.0
wcounts_sum = 0
for p in points:
wsum += p.weight * wcounts[p.tag]
wcounts_sum += wcounts[p.tag]
print("The summation of window counts: %d" % wcounts_sum)
print("The iniital summation(weight * window_counts): %f" % wsum)
factor = 1.0 / wsum
weights = {}
for p in points:
weights[p.tag] = p.weight * factor
# validate
wsum = 0.0
for event in weights:
wsum += wcounts[event] * weights[event]
if not np.isclose(wsum, 1.0):
raise ValueError("Error normalize source weights: %f" % wsum)
print("The normalized sum is: %f" % wsum)
print("Final weights: %s" % weights)
return weights
source_weights.py 文件源码
python
阅读 32
收藏 0
点赞 0
评论 0
评论列表
文章目录