bayes_scores.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pyBN 作者: ncullen93 项目源码 文件源码
def K2(bn, data, ed=None):
    """
    K2 is bayesian posterior probability of structure given the data,
    where N'ijk = 1.
    """
    counts_dict = mle_fast(bn, data, counts=True, np=True)
    a_ijk = []
    k2 = 1
    for rv, value in counts_dict.items():
        nijk = value['cpt']
        nijk_prime = 1
        k2 *= gamma(nijk+nijk_prime)/gamma(nijk_prime)
        nij_prime = nijk_prime*(len(cpt)/bn.card(rv))
        nij = np.mean(nijk.reshape(-1, bn.card(rv)), axis=1) # sum along parents
        k2 *= gamma(nij_prime) / gamma(nij+nij_prime)

    return k2
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号