1 Star 0 Fork 2

xiaxiaxia110/Intrusion-Detection

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MLE.py 997 Bytes
一键复制 编辑 原始数据 按行查看 历史
Renovamen 提交于 2019-06-14 15:26 +08:00 . [Feat] Add bayesian network
import numpy as np
def mle(bn, data):
nodes = list(bn.nodes())
F = dict([(rv, {}) for rv in nodes])
for i, n in enumerate(nodes):
F[n]['values'] = list(np.unique(data[:,i]))
bn.F[n]['values'] = list(np.unique(data[:,i]))
obs_dict = dict([(rv,[]) for rv in nodes])
for rv in nodes:
p_idx = int(np.prod([bn.card(p) for p in bn.parents(rv)])*bn.card(rv))
F[rv]['cpt'] = [0]*p_idx
bn.F[rv]['cpt'] = [0]*p_idx
for row in data:
for rv in nodes:
obs_dict[rv] = row[rv]
for rv in nodes:
rv_dict= { n: obs_dict[n] for n in obs_dict if n in bn.scope(rv) }
offset = bn.cpt_indices(target = rv, val_dict = rv_dict)[0]
F[rv]['cpt'][offset]+=1
for rv in nodes:
F[rv]['parents'] = [var for var in nodes if rv in bn.E[var]]
for i in range(0,len(F[rv]['cpt']),bn.card(rv)):
temp_sum = float(np.sum(F[rv]['cpt'][i:(i+bn.card(rv))]))
for j in range(bn.card(rv)):
F[rv]['cpt'][i+j] /= (temp_sum+1e-7)
F[rv]['cpt'][i+j] = round(F[rv]['cpt'][i+j],5)
bn.F = F
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaxiaxia110/Intrusion-Detection.git
git@gitee.com:xiaxiaxia110/Intrusion-Detection.git
xiaxiaxia110
Intrusion-Detection
Intrusion-Detection
master

搜索帮助