else:
        return ((V(q) + T(p)))


def p_sharp(q, p):
    p_s = p.data
    return (p_s)


epsilon = 0.11

store = torch.zeros((chain_l, dim))
begin = time.time()
for i in range(chain_l):
    print("round {}".format(i))
    out = GNUTS(q, 0.12, H, leapfrog, max_tdepth, p_sharp)
    store[i, ] = out[0].data  # turn this on when using Nuts
    q.data = out[0].data  # turn this on when using nuts
    #print("q is {} tree length {}".format(q.data, out[1]))
total = time.time() - begin
exit()
print("total time is {}".format(total))
print("length of chain is {}".format(chain_l))
print("length of burn in is {}".format(burn_in))
print("Use logit")
store = store[burn_in:, ]
store = store.numpy()

mcmc_samples = store
correct = pickle.load(open("result_from_long_chain.pkl", 'rb'))
correct_mean = correct["correct_mean"]
Esempio n. 2
0
def p_sharp(q, p):
    _, H = getH(q, V)
    lam, Q = eigen(H.data)
    p_s = dtaudp(p.data, alp, lam, Q)
    return (p_s)


alp = 1e6
fi_fake = pi_wrap(alp, True)
gleapfrog = genleapfrog_wrap(alp, 0.1, V)

store = torch.zeros((chain_l, dim))
begin = time.time()
for i in range(chain_l):
    print("round {}".format(i))
    out = GNUTS(q, 0.1, fi_fake, gleapfrog, 10, p_sharp)
    store[i, ] = out[0].data  # turn this on when using Nuts
    q.data = out[0].data  # turn this on when using nuts

total = time.time() - begin
print("total time is {}".format(total))
print("length of chain is {}".format(chain_l))
print("length of burn in is {}".format(burn_in))
print("Use logit")
store = store[burn_in:, ]
store = store.numpy()

mcmc_samples = store
correct = pickle.load(open("result_from_long_chain.pkl", 'rb'))
correct_mean = correct["correct_mean"]
correct_cov = correct["correct_cov"]