Hi all!
Recently I have been interested in the implementation of probabilistic programming languages.
After much head-scratching I have figured out how to implement a simple one in Python.
I am sharing it hoping that someone finds it interesting.
Any feedback is very welcome.
8 Likes
Nice! Deferred execution and graph traversal is indeed the key for designing a PPL in Python.
I think your blog post and implementation handles the log_prob graph quite nicely, something i feel a bit missing is the forward (sample) graph. In case you find interesting, in our (@aloctavodia @RavinKumar and me) recent book we talk about designing PPL as well Chapter 10: Probabilistic Programming Languages — Bayesian Modeling and Computation in Python
2 Likes
Thanks, Bayesian Modeling and Computation was on my radar but I hadn’t checked it out yet.
Now I have one more reason to.
I think I will make another small post to explain sampling. From a graph traversal perspective it is much more interesting, since the order of evaluation matters, thus requiring a topological sort.
2 Likes
Update: I have finished writing it 
As always, any feedback is welcome.
I feel that I have not made it clear that we are sampling from the prior and posterior predictive distributions with the new API (heavily inspired by pm.sample_prior_predictive
and pm.sample_posterior_predictive(posterior)
). But I imagine that someone already familiar with PPLs would understand that.
2 Likes