blei-lab / edward

A probabilistic programming language in TensorFlow. Deep generative models, variational inference.
http://edwardlib.org
Other
4.83k stars 760 forks source link

importance sampling and sequential monte carlo #271

Open dustinvtran opened 7 years ago

faezs commented 7 years ago

Hi @dustinvtran, I've been going through the codebase to figure out how to best implement SMC, and was looking for a little validation. Would subclassing from MonteCarlo and drawing inspiration from the Metropolis-Hastings implementation be the right way to go about it?

dustinvtran commented 7 years ago

Yep, I think that makes sense. The simplest version to get started would follow Metropolis-Hastings' build_update() but without the Metropolis correction. This would implement vanilla importance sampling.

matthieubulte commented 6 years ago

Hi, I'm working on an implementation of IS (a first step before SMC) and I was thinking of the two following options:

  1. Implement an ImportanceSampling class inheriting from MonteCarlo. The build_update() method would simply compute one sample from the prior and its the importance weight (likelihood ratio). Each iteration would store its result internally and only in populate the user's Empirical in the finalize() method by sampling the auto-normalized weighted approximation.

  2. Implement a WeightedEmpirical distribution, make Empirical inherit from it (with default weights of 1/N) and replace in MonteCarlo the Empirical requirement by WeightedEmpirical. Then at each iteration directly populate the user's WeightedEmpirical and auto-normalize the distribution in the finalize() method.

Which of these two options do you think make more sense? Or would you have any other suggestions / comments?

EvanKrall commented 6 years ago

I'm not a contributor, so take this with a grain of salt, but a WeightedEmpirical distribution makes more sense to me than keeping the weights internal to ImportanceSampling. It's convenient to be able to access the underlying samples & weights for approximating integrals without experiencing another round of sampling error.