h3jia / bayesfast

Next generation Bayesian analysis tools for efficient posterior sampling and evidence estimation.
Other
29 stars 6 forks source link

Standalone use of GBS #31

Open mberaha opened 3 years ago

mberaha commented 3 years ago

Hi, first of all, really nice package!

I'm running MCMC chains in Stan, since computing the gradient of my distribution is not trivial and Stan's autodiff does it for me. I wanted then to use the Gaussianized Bridge Sampler starting from the MCMC samples obtained through Stan, but the GBS class offers little documentation, and in the examples you provide it is never called directly.

So is there a way to use the Gaussianized Bridge Sampler as a standalone module? I can also code in python the (unnormalized) log density function if needed, but not its gradient

h3jia commented 3 years ago

Sorry for the documentation issue! We'll probably have a better doc in a few weeks. For now, I suppose you can do it in this way:

import bayesfast as bf

gbs = bf.evidence.GBS() # you can also set the value of n_q here
logz, logz_err = gbs(x_p, logp, logp_p)

Here x_p is your MCMC chains, better with shape (# of chains, # of steps, # of dims), logp is your pdf function, and logp_p is the logp value at x_p. If you don't give it logp_p (i.e. leave it as None), it will just re-evaluate it using logp and x_p. By default it will generate the same number of samples from logq, but you can change this by specifying n_q when initializing the GBS class.

Please let me know if you have any further questions.