LazyPPL is a Haskell library for probabilistic programming. It
supports lazy use of probability, and we provide new Metropolis-Hastings
algorithms to allow this. LazyPPL is inspired by recent ideas in
synthetic probability theory and synthetic measure theory such as quasi-Borel
spaces and Markov
categories. Laziness appears to be a good paradigm for
non-parametric statistics. LazyPPL is inspired by many other languages,
including Church, Anglican, and MonadBayes.

LazyPPL provides two monads:

Prob a:
probability measures, supporting probability measure such as uniform ::ProbDouble,
normal ::Double->Double->ProbDouble,
bernoulli ::Double->ProbBool.
This is lazy, in other words it is an affine monad.

Meas a:
unnormalized measures, as used in Monte Carlo simulations for Bayesian
statistics. There are two key functions:

sample ::Prob a ->Meas a,
which samples from a probability measure;

score ::Double->Meas (),
which weights a measure by a given value, typically coming from a
likelihood function.

Simple example

To illustrate the basic usage, here is a very simple first example,
that doesnâ€™t use laziness. More advanced examples are in the menu above
and further examples in the Bitbucket repository.

Extensions and imports for this Literate Haskell file

{-# LANGUAGE ExtendedDefaultRules #-}moduleIndexwhereimportLazyPPLimportDistrimportGraphics.Matplotlibhiding (density)importData.List

Suppose we we know that there are fewer buses on Sundays than on
other days. I notice 4 buses in an hour, what is the probability it is a
Sunday?

model ::MeasBoolmodel =do-- Prior belief: it is Sunday with prob. 1/7 sunday <- sample $ bernoulli (1/7)-- I know the rates of buses on the different days:let rate =if sunday then3else10-- observe 4 buses score $ poissonPdf rate 4return sunday

We run a Metropolis-Hastings simulation to get a stream of draws from
this unnormalized measure. We plot a histogram of the results, which
shows the posterior probability that it is Sunday, given that we saw 4
buses.