def test_evidence(self):
# 2 sigma tolerance
tolerance = 2.0*np.sqrt(self.work.NS.state.info/self.work.NS.Nlive)
print('2-sigma statistic error in logZ: {0:0.3f}'.format(tolerance))
print('Analytic logZ {0}'.format(self.model.analytic_log_Z))
print('Estimated logZ {0}'.format(self.work.NS.logZ))
pos=self.work.posterior_samples['x']
#t,pval=stats.kstest(pos,self.model.distr.cdf)
stat,pval = stats.normaltest(pos.T)
print('Normal test p-value {0}'.format(str(pval)))
plt.figure()
plt.hist(pos.ravel(),normed=True)
x=np.linspace(self.model.bounds[0][0],self.model.bounds[0][1],100)
plt.plot(x,self.model.distr.pdf(x))
plt.title('NormalTest pval = {0}'.format(pval))
plt.savefig('posterior.png')
plt.figure()
plt.plot(pos.ravel(),',')
plt.title('chain')
plt.savefig('chain.png')
self.assertTrue(np.abs(self.work.NS.logZ - GaussianModel.analytic_log_Z)<tolerance, 'Incorrect evidence for normalised distribution: {0:.3f} instead of {1:.3f}'.format(self.work.NS.logZ,GaussianModel.analytic_log_Z ))
self.assertTrue(pval>0.01,'Normaltest test failed: KS stat = {0}'.format(pval))
评论列表
文章目录