示例#1
0
def get_hmc_kernel():
    num_steps_min, num_steps_max, step_size_min, step_size_max = get_hmc_parameters(
    )
    target, momentum = get_target_momentum()
    hmc = HMCBase(target, momentum, num_steps_min, num_steps_max,
                  step_size_min, step_size_max)
    return hmc
示例#2
0
def sample_banana2(N, D, target):
    momentum = IsotropicZeroMeanGaussian(D=D, sigma=1.0)
    num_steps = 1000
    step_size = 0.2
    hmc = HMCBase(target, momentum, num_steps, num_steps, step_size, \
                  step_size, adaptation_schedule=None)
    start_samples = sample_banana(N, D)
    # simulate trajectory from starting point, note _proposal_trajectory is a "hidden" method
    Qs_total = []
    for i in xrange(N):
        current = start_samples[i]
        current_log_pdf = target.log_pdf(current)
        Qs, acc_probs, log_pdf_q = hmc._proposal_trajectory(
            current, current_log_pdf)
        Qs_total.append(Qs[-1])
    return np.asarray(Qs_total)
示例#3
0
def test_hmc_base_init_execute():
    num_steps_min, num_steps_max, step_size_min, step_size_max = get_hmc_parameters(
    )
    target, momentum = get_target_momentum()
    HMCBase(target, momentum, num_steps_min, num_steps_max, step_size_min,
            step_size_max)
示例#4
0
        T = 100
        k = 0
        while k < num_steps + 1:
            # KSD
            Qs_batch = Qs_total[:, k, :]
            ksd_total.append(compute_ksd(Qs_batch, target))
            k += T
        ksd_total = np.asarray(ksd_total)
        results.append([
            Qs_total, acc_probs_total, accor_total, ksd_total, ess_total,
            mean_x1_total
        ])

    # now run HMC
    momentum = IsotropicZeroMeanGaussian(D=D, sigma=1.0)
    hmc = HMCBase(target, momentum, num_steps, num_steps, step_size, \
                  step_size, adaptation_schedule=None)

    # simulate trajectory from starting point, note _proposal_trajectory is a "hidden" method
    Qs_total = []
    acc_probs_total = []
    accor_total = []
    ksd_total = []
    ess_total = []
    mean_x1_total = []
    np.random.seed(seed + 1)
    for i in xrange(M):
        current = start_samples[i]
        current_log_pdf = target.log_pdf(current)
        Qs, acc_probs, log_pdf_q = hmc._proposal_trajectory(
            current, current_log_pdf)
        # compute auto correlation on first dim