dp.py 文件源码

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

项目:VAE_NBP 作者: bobchennan 项目源码 文件源码
def test(epoch, prior):
    ans = np.zeros((50, 10))
    for data, lab in test_loader:
        C = prior.predict(data.numpy().reshape(data.numpy().shape[0],-1))
        for i in xrange(len(lab)):
            ans[C[i],lab[i]]+=1
    print(ans)
    s = np.sum(ans)
    v = 0
    for i in xrange(ans.shape[0]):
        for j in xrange(ans.shape[1]):
            if ans[i,j]>0:
                v += ans[i,j]/s*np.log(ans[i,j]/s/(np.sum(ans[i,:])/s)/(np.sum(ans[:,j])/s))
    print("Mutual information: "+str(v))

#prior = BayesianGaussianMixture(n_components=100, covariance_type='diag')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号