population_size = 50 num_iter = population_size * num_iter_per_particle mdl = SVoneSP500Model() target_log_pdf = mdl.get_logpdf_closure() # number of particles used for integrating out the latent variables mdl.mdl_param.NX = mdl.mdl_param.NX * 1 D = mdl.dim start = np.zeros(D) sampler = get_AdaptiveIndependentMetropolis_instance(D, target_log_pdf) start_time = time.time() samples, log_target_densities, times = mini_pmc(sampler, start, num_iter, population_size) time_taken = time.time() - start_time logger.info("Storing results under %s" % result_fname) store_samples(samples, result_fname) mean = np.mean(samples, axis=0) var = np.var(samples, axis=0) print "mean:", repr(mean) print "var:", repr(var) print "np.mean(var): %.3f" % np.mean(var) print "np.linalg.norm(mean): %.3f" % np.linalg.norm(mean) print "ESS: %.3f" % sampler.get_current_ess() if False: import matplotlib.pyplot as plt
bananicity = 0.03 V = 100 Z = sample_banana(700, D, bananicity, V) target_log_pdf = lambda x: log_banana_pdf( x, bananicity, V, compute_grad=False) target_grad = lambda x: log_banana_pdf(x, bananicity, V, compute_grad=True) samplers = [ get_AdaptiveMetropolis_instance(D, target_log_pdf), # the below two don't yet support weights in the update method # get_Kameleon_instance(D, target_log_pdf), # get_OracleKameleon_instance(D, target_log_pdf), get_StaticLangevin_instance(D, target_log_pdf, target_grad), get_StaticMetropolis_instance(D, target_log_pdf), get_AdaptiveLangevin_instance(D, target_log_pdf, target_grad), get_OracleKernelAdaptiveLangevin_instance(D, target_log_pdf, target_grad), get_KernelAdaptiveLangevin_instance(D, target_log_pdf, target_grad), ] for sampler in samplers: start = np.zeros(D) num_iter = 1000 samples, log_target_densities, times = mini_pmc( sampler, start, num_iter, 10) visualize_scatter_2d(samples) plt.suptitle("%s" % \ (sampler.__class__.__name__,)) plt.show()