# num_dstates = np.prod([rv.dstates for rv in cond_g.Vd]) if num_dstates > 1000: print( 'too many dstates, exact mode finding might take a while, consider parallelizing...' ) for i, rv in enumerate(query_rvs): m = get_rv_marg_map_from_bn_params(*bn, cond_g.Vd_idx, cond_g.Vc_idx, rv) mmap[i] = m assert rv.domain_type[ 0] == 'c', 'only looking at kl for cnode queries for now' crv_idx = cond_g.Vc_idx[rv] crv_marg_params = get_crv_marg(*bn, crv_idx) marg_logpdf = utils.get_scalar_gm_log_prob( None, *crv_marg_params, get_fun=True) margs[i] = marg_logpdf if baseline == 'gibbs': num_burnin = 200 num_samples = 1000 num_gm_components_for_crv = 3 disc_block_its = 40 hgsampler = HybridGaussianSampler(converted_factors, cond_g.Vd, cond_g.Vc, cond_g.Vd_idx, cond_g.Vc_idx) hgsampler.block_gibbs_sample(num_burnin=num_burnin, num_samples=num_samples, disc_block_its=disc_block_its) # np.save('cont_samples', hgsampler.cont_samples) # np.save('disc_samples', hgsampler.disc_samples)
# test_crv_idx = 1 test_crv_marg_params = get_crv_marg(*bn, test_crv_idx) print(f'true crv{test_crv_idx} marg params', test_crv_marg_params) osi_test_crv_marg_params = osi.params['w'], osi.params['Mu'][ test_crv_idx], osi.params['Var'][test_crv_idx] print(f'osi crv{test_crv_idx} marg params', osi_test_crv_marg_params) import matplotlib.pyplot as plt plt.figure() xs = np.linspace(-10, 10, 100) plt.hist(cont_samples[:, test_crv_idx], normed=True, label='samples') plt.plot(xs, np.exp( utils.get_scalar_gm_log_prob(xs, w=test_crv_marg_params[0], mu=test_crv_marg_params[1], var=test_crv_marg_params[2])), label='ground truth marg pdf') plt.plot(xs, np.exp( utils.get_scalar_gm_log_prob(xs, w=osi_test_crv_marg_params[0], mu=osi_test_crv_marg_params[1], var=osi_test_crv_marg_params[2])), label='OSI marg pdf') plt.legend(loc='best') # plt.show() save_name = __file__.split('.py')[0] plt.savefig('%s.png' % save_name)