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')
评论列表
文章目录