1 Star 0 Fork 0

zhoub86/entropy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.py 1.74 KB
一键复制 编辑 原始数据 按行查看 历史
#!/usr/bin/env python3
"""
Main file for running entropy estimators
"""
import argparse
from entropy import *
parser = argparse.ArgumentParser()
parser.add_argument("-k", type=int,
help="Alphabet size")
parser.add_argument("-L", type=int,
help="Polynoimal degree. Default c0*log(k)")
parser.add_argument("-M", type=int,
help="M/n is the right-end of approximation interval. Default c1*log(k)")
parser.add_argument("-N", type=int,
help="Threshold to apply polynomial estimator. Default c2*log(k)")
parser.add_argument("-fin", type=str,
help="fingerprint data file")
parser.add_argument("-hist", type=str,
help="histogram data file")
args = parser.parse_args()
if args.k is None:
raise Exception('Please input k!')
entropy = Entropy(k=args.k)
if args.L is not None:
entropy.degree = args.L
if args.M is not None:
entropy.ratio = args.M
if args.N is not None:
entropy.n_threhold = args.N
if args.fin is not None:
fin = np.loadtxt(args.fin, dtype=int)
elif args.hist is not None:
hist = np.loadtxt(args.hist, dtype=int)
fin = hist_to_fin(hist)
else:
raise Exception('Please input fingerprint or histogram!')
print("")
print("Parameters:")
print("Alphabet size\t\t=%d" % entropy.k)
print("Polynoimal degree\t=%d" % entropy.degree)
print("Approximation interval\t=[0,%.2f/n]" % entropy.ratio)
print("Plug-in threshold\t=%d" % (entropy.n_threhold+1))
print("")
print("Results:")
print("Sample size\t=%d" % get_sample_size(fin))
print("Plug in\t\t=%.6f bits" % entropy.estimate_plug(fin))
print("Miller Madow\t=%.6f bits" % entropy.estimate_Miller_Madow(fin))
print("Polynomial\t=%.6f bits" % entropy.estimate(fin))
print("")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhoub86/entropy.git
git@gitee.com:zhoub86/entropy.git
zhoub86
entropy
entropy
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385