def do_test_delta_internal (self, net, nreps, ntasks, pct):
for ri in range(nreps):
arrv = net.sample (ntasks)
obs = arrv.subset_by_task (pct)
samples = net.slice_resample (obs, 0, 5)
arrv_from = samples[len(samples)-1]
print "Computing LIK0"
lik0 = net.log_prob (arrv_from)
for e in arrv_from:
if not e.obs_d:
# print "Testing evt ", e
dfn = qnet.GGkGibbs(net, arrv_from, e, lik0).dfn()
d0 = e.d
d_test = [ d0+delta for delta in [ -0.5, -0.1, 0.1, 0.5, 1.0, 1.5, 3.0 ] ]
for d1 in d_test:
# print "Testing departure ", d1
lik_incremental = dfn(d1)
if numpy.isinf (lik_incremental): continue # probably right
lik_true = self.compute_full_lik (net, arrv_from, e, d1)
print "%d %.4f %.4f %.4f %.4f" % (e.eid, d0, d1, lik_incremental, lik_true)
if numpy.isinf(lik_true):
self.assertTrue (numpy.isinf(lik_incremental))
else:
self.assertAlmostEquals (lik_true, lik_incremental, 5)
评论列表
文章目录