tweag / monad-bayes

A library for probabilistic programming in Haskell.
MIT License
407 stars 62 forks source link

Variational Inference #126

Open reubenharry opened 2 years ago

reubenharry commented 2 years ago

Most of the more popular probabilistic programming languages have implementations of variational inference (VI). As such, it's absence in monad-bayes is something of an obstacle to real-world use.

A fast variational inference implementation needs (to my current understanding) a faster autodiff library than ad, which is the most currently accessible Haskell one. There seems to be some work in this direction (vis a vis Accelerate and https://github.com/VMatthijs/CHAD) but it's early days.

In the meantime, I'd like to implement a reference implementation using ad with no concern for speed at all. Previous versions of monad-bayes had something like this, so that will be my starting point. One of the conceptual challenges is that VI only makes sense (at least simple versions) for probabilistic programs with differentiable scoring functions, so it's still unclear to me how/if to express that in the types.

As I understand more about how the implementation should work, I'll update this issue.

reubenharry commented 2 years ago

After some research, here are resources I'm finding useful:

(1) Automatic Differentiation Variational Inference: https://arxiv.org/pdf/1603.00788.pdf (2) Black Box Variational Inference: https://arxiv.org/pdf/1401.0118.pdf

These would appear to be two of the main ways to get variational inference into probabilistic programs in an automatic way.

I also note that the autodiff branch of monad-bayes has an implementation of (1). It requires some pretty scary heavy lifting (a series of reparametrizations, and a bunch of formidable types), so I might tackle this after warming up on some easier stuff