AdamCobb / hamiltorch

PyTorch-based library for Riemannian Manifold Hamiltonian Monte Carlo (RMHMC) and inference in Bayesian neural networks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

previous sample not appended upon rejection?

YilunZhou opened this issue · comments

If my understanding about HMC (and MH in general) is correct, if the new sample (i.e. proposal) is not accepted, the previous sample should be duplicated in the sample list. However, it looks like this duplication is not done. Specifically, on

ret_params.extend(leapfrog_params)
, upon acceptance, the new sample is appended the returned sample list, but upon rejection, nothing is done. Is this a mistake in the code?

Hi,

Thanks for finding that. You are correct and I have now fixed the sampler.

If you wanted to git pull and add a small comment like "# Ensure rejected sample is duplicated" above

leapfrog_params = ret_params[-num_steps_per_sample:] ### Might want to remove grad as wastes memory

and submit a pull request, then I can accept your pull request and you will be down as a contributor. That way I can ensure this fix is attributed to you (if that is something you would like).

Thanks once again!

Adam