Example #1
0
 def get_OracleKernelAdaptiveLangevin_instance(D, target_log_pdf):
     step_size = 1.
     m = 500
     N = 5000
     Z = sample_banana(N, D, bananicity, V)
     
     surrogate = KernelExpFiniteGaussian(sigma=10, lmbda=.001, m=m, D=D)
     surrogate.fit(Z)
     
     if False:
         param_bounds = {'sigma': [-2, 3]}
         bo = BayesOptSearch(surrogate, Z, param_bounds)
         best_params = bo.optimize()
         surrogate.set_parameters_from_dict(best_params)
     
     if False:
         sigma = 1. / gamma_median_heuristic(Z)
         surrogate.set_parameters_from_dict({'sigma': sigma})
     
     logger.info("kernel exp family uses %s" % surrogate.get_parameters())
 
     if False:
         import matplotlib.pyplot as plt
         Xs = np.linspace(-30, 30, 50)
         Ys = np.linspace(-20, 40, 50)
         visualise_fit_2d(surrogate, Z, Xs, Ys)
         plt.show()
         
     instance = OracleKernelAdaptiveLangevin(D, target_log_pdf, surrogate, step_size)
     
     return instance
Example #2
0
    def get_OracleKernelAdaptiveLangevin_instance(D, target_log_pdf):
        step_size = 1.
        m = 500
        N = 5000
        Z = sample_banana(N, D, bananicity, V)

        surrogate = KernelExpFiniteGaussian(sigma=10, lmbda=.001, m=m, D=D)
        surrogate.fit(Z)

        if False:
            param_bounds = {'sigma': [-2, 3]}
            bo = BayesOptSearch(surrogate, Z, param_bounds)
            best_params = bo.optimize()
            surrogate.set_parameters_from_dict(best_params)

        if False:
            sigma = 1. / gamma_median_heuristic(Z)
            surrogate.set_parameters_from_dict({'sigma': sigma})

        logger.info("kernel exp family uses %s" % surrogate.get_parameters())

        if False:
            import matplotlib.pyplot as plt
            Xs = np.linspace(-30, 30, 50)
            Ys = np.linspace(-20, 40, 50)
            visualise_fit_2d(surrogate, Z, Xs, Ys)
            plt.show()

        instance = OracleKernelAdaptiveLangevin(D, target_log_pdf, surrogate,
                                                step_size)

        return instance
def get_OracleKameleon_instance(D, target_log_pdf):
    
    step_size = 30.
    schedule = one_over_sqrt_t_schedule
    acc_star = 0.234
    gamma2 = 0.1
    n = 500
    
    Z = sample_banana(N=n, D=D, bananicity=0.03, V=100)
    
    kernel_sigma = 1. / gamma_median_heuristic(Z)
    instance = OracleKameleon(D, target_log_pdf, n, kernel_sigma, step_size, gamma2, schedule, acc_star)
    instance.set_batch(Z)
    
    return instance
    
    benchmark_samples = np.loadtxt(benchmark_samples_fname)
    benchmark_samples = benchmark_samples[np.arange(0, len(benchmark_samples), step=100)]
    return benchmark_samples

if __name__ == "__main__":

    benchmark_samples = get_benchmark_samples_mcmc()
    true_mean = np.mean(benchmark_samples, axis=0)
    true_var = np.var(benchmark_samples, axis=0)
    print("%d benchmark samples" % len(benchmark_samples))
    print "mean:", repr(true_mean)
    print "var:", repr(true_var)
    print "np.mean(var): %.3f" % np.mean(true_var)
    print "np.linalg.norm(mean): %.3f" % np.linalg.norm(true_mean)
    print "median heuristic sigma: %.3f" % (1. / gamma_median_heuristic(benchmark_samples))
    
    visualise_pairwise_marginals(benchmark_samples)
    plt.show()
    
    m = 1000
    
    lmbda = 1.
    res = 10
    log2_sigmas = np.linspace(-4, 10, res)
    log2_sigmas = np.log2([0.5, 0.7, 0.9, 1.1, 1.3, 1.5])
    
    print "log2_sigmas:", log2_sigmas
    print "sigmas:", 2 ** log2_sigmas
    Js_mean = np.zeros(res)
    Js_var = np.zeros(res)
Example #5
0
                                                    step=100)]
    return benchmark_samples


if __name__ == "__main__":

    benchmark_samples = get_benchmark_samples_mcmc()
    true_mean = np.mean(benchmark_samples, axis=0)
    true_var = np.var(benchmark_samples, axis=0)
    print("%d benchmark samples" % len(benchmark_samples))
    print "mean:", repr(true_mean)
    print "var:", repr(true_var)
    print "np.mean(var): %.3f" % np.mean(true_var)
    print "np.linalg.norm(mean): %.3f" % np.linalg.norm(true_mean)
    print "median heuristic sigma: %.3f" % (
        1. / gamma_median_heuristic(benchmark_samples))

    visualise_pairwise_marginals(benchmark_samples)
    plt.show()

    m = 1000

    lmbda = 1.
    res = 10
    log2_sigmas = np.linspace(-4, 10, res)
    log2_sigmas = np.log2([0.5, 0.7, 0.9, 1.1, 1.3, 1.5])

    print "log2_sigmas:", log2_sigmas
    print "sigmas:", 2**log2_sigmas
    Js_mean = np.zeros(res)
    Js_var = np.zeros(res)