Log probability of samples using NUTS / HMC


I’m wondering if there is a way to recover the (unnormalised) log posterior density of each sample when doing MCMC in NumPyro? Basically an equivalent of lp__ in Stan.

Alternatively, it would still be useful if there is a way of evaluating the posterior density of some particular combination of values of all the variables, even if it isn’t automatically done during sampling.


Hi @tcbegley, for the first question, you can set extra_fields=('potential_energy',) in MCMC.run, then call the method MCMC.get_extra_fields. For the second question, I think you can use log_density or potential_energy utility, depending on your posterior values are in constrained space or unconstrained space (see the docs of those functions for more explanation).

1 Like

Perfect, thanks @fehiepsi!