コード例 #1
0
ファイル: pmc_banana.py プロジェクト: karlnapf/kameleon_rks
    population_sizes = [5, 10, 25, 50, 100]
    
    num_repetitions = 30
    
    num_benchmark_samples = 1000
    rng_state = np.random.get_state()
    np.random.seed(0)
    benchmark_sample = sample_banana(num_benchmark_samples, D, bananicity, V)
    np.random.set_state(rng_state)
    
    for _ in range(num_repetitions):
        for population_size in population_sizes:
            num_iter = population_size * num_iter_per_particle
            start = np.zeros(D)
            
            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_StaticMetropolis_instance(D, target_log_pdf),
                            get_AdaptiveMetropolis_instance(D, target_log_pdf),
                            get_AdaptiveIndependentMetropolis_instance(D, target_log_pdf),
                            get_StaticLangevin_instance(D, target_log_pdf, target_grad),
                            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_time = time.time()
                samples, log_target_densities, times = mini_pmc(sampler, start, num_iter, population_size)
コード例 #2
0
    return instance


if __name__ == '__main__':
    Log.set_loglevel(20)
    max_moment = 8
    D = 10
    pop_size = 10
    bananicity = 0.03
    V = 100
    Z = sample_banana(3000, D, bananicity, V)
    moments = np.array([(Z**i).mean(0) for i in range(1, max_moment)])
    pk = PolynomialKernel(3)
    print(moments)
    true_correct = np.linalg.inv(np.cov(Z.T))
    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 = [
        #
    ]

    sampler_is = get_StaticLangevin(
        D, target_log_pdf,
        target_grad)  #get_AdaptiveLangevin(D, target_log_pdf, target_grad)
    sampler_mh = get_StaticLangevin(
        D, target_log_pdf, target_grad
    )  #get_AdaptiveLangevin(D, target_log_pdf, target_grad, prec=True, step_size=1.)
    start = np.zeros(D)
    num_iter = 100