b2 = BayesNetSampler(obj, template, groundbnet, priorweight) #s2 = SAMCRun(b2,burn,stepscale,refden,thin) #s2.sample(iters, temperature) ####################################### def test(): def close_enough(n1, n2): return (n1 - n2) < 1e-5 return (n1 - n2) < np.finfo(float).eps assert close_enough(groundtree.kld(b1), groundbnet.kld(b2.bayesnet)) b2.bayesnet.adjust_factor(1, [2], []) b2.bayesnet.set_factor(1, [0.9, 0.1, 0.9, 0.1]) b1.add_edge(2, 1, 0.9, 0.1) assert close_enough(groundtree.entropy(), groundbnet.entropy()) assert close_enough(groundtree.kld(b1), groundbnet.kld(b2.bayesnet)) energy = 0.0 count = 0 while groundbnet.kld(b2.bayesnet) >= 0.0: b2.propose() count += 1 if b2.energy() > 10000: b2.reject()
obj = BayesNetCPD(states, data) b2 = BayesNetSampler(obj, template, groundbnet, priorweight) #s2 = SAMCRun(b2,burn,stepscale,refden,thin) #s2.sample(iters, temperature) ####################################### def test(): def close_enough(n1,n2): return (n1-n2) < 1e-5 return (n1-n2) < np.finfo(float).eps assert close_enough(groundtree.kld(b1), groundbnet.kld(b2.bayesnet)) b2.bayesnet.adjust_factor(1,[2],[]) b2.bayesnet.set_factor(1,[0.9,0.1,0.9,0.1]) b1.add_edge(2,1,0.9,0.1) assert close_enough(groundtree.entropy(), groundbnet.entropy()) assert close_enough(groundtree.kld(b1), groundbnet.kld(b2.bayesnet)) energy = 0.0 count = 0 while groundbnet.kld(b2.bayesnet) >= 0.0: b2.propose() count += 1 if b2.energy() > 10000: b2.reject()