lazyppl: Lazy Probabilistic Programming Library

[ library, mit, statistics ] [ Propose Tags ] [ Report a vulnerability ]

LazyPPL is a Haskell library for Bayesian probabilistic programming. It supports lazy use of probability, which is useful for specifying non-parametric models, and we provide new Metropolis-Hastings algorithms to allow this. For illustrations, see https://lazyppl-team.github.io/.

LazyPPL is pure Haskell and needs no BLAS or LAPACK installation.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0, 1.0.1, 1.1.0
Change log ChangeLog.md
Dependencies base (>=4.18.3.0 && <4.23), containers (>=0.6.7 && <0.9), log-domain (>=0.13.2 && <0.14), math-functions (>=0.3.4.2 && <0.4), random (>=1.3.1 && <1.4), transformers (>=0.6.1.0 && <0.7), vector (>=0.13.2.0 && <0.14) [details]
Tested with ghc ==9.6.7, ghc ==9.12.4, ghc ==9.14.1
License MIT
Copyright 2021-2026 LazyPPL team
Author LazyPPL team
Maintainer sam.staton@cs.ox.ac.uk
Uploaded by youkad at 2026-11-03T10:25:24Z
Category Statistics
Home page https://lazyppl-team.github.io/
Bug tracker https://github.com/lazyppl-team/lazyppl/issues
Source repo head: git clone https://github.com/lazyppl-team/lazyppl
Distributions Stackage:1.1.0
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 134 total (15 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-11-03 [all 1 reports]

Readme for lazyppl-1.1.0

[back to package description]

LazyPPL

LazyPPL is a Haskell library for Bayesian probabilistic programming, drawing on the fact that lazy data structures are a natural idiom for programming with infinite-dimensional Bayesian methods such as Poisson/Gaussian/Dirichlet processes.

The crucial semantic idea, inspired by developments in synthetic probability theory, is to work with two separate monads: an affine monad of probability, which supports laziness, and a commutative, non-affine monad of measures, which does not. This gives a Metropolis-Hastings implementation that works with lazy programs.

The main LazyPPL modules are on Hackage and Stackage. Various worked examples in literate Haskell are at https://lazyppl-team.github.io.

Laziness lets us specify non-parametric models cleanly: processes or infinite-dimensional functions only have their finite explored portion materialised. We have first-class

  • stochastic memoization: memoize :: (a -> Prob b) -> Prob (a -> b)
  • Gaussian processes: wiener :: Prob (Double -> Double)
  • point processes: poissonPP :: Double -> Double -> Prob [Double] (in the example demos)
  • Dirichlet processes: dp :: Double -> Prob a -> Prob (Prob a)

Examples

  • WienerDemo (lhs) is a simple implementation of regression using a Wiener process. Via maintaining a hidden table of previous calls, it appears to be a bona fide random function \(R\to R\) constructed lazily. Some values are sampled during simulation, others during plotting.

Wiener process regression

  • RegressionDemo (lhs) demonstrates piecewise linear regression. The change points are drawn from a lazy Poisson process.

Poisson-split piecewise linear regression

  • Clustering (lhs) contains some simple clustering examples, where the number of clusters is unknown. Stick-breaking is lazy, and we use stochastic memoization.

Dirichlet process clustering

  • ProgramInduction (lhs) is a simple example of program induction over an arithmetic language. Random expressions are represented as an infinite forest with a finite path through it.

Program induction

Library

  • LazyPPL.hs provides the core monads and inference. Prob is an affine monad of probability measures. Meas is a non-affine monad of unnormalised measures with sample and score. The Metropolis-Hastings algorithm mh takes a probability p of changing any given site of the rose tree of random seeds. Setting p=1/num_sites approximates single-site MH and p=1 recovers multi-site MH. We can't compute the number of active sites without forcing more of the lazy tree, so we use this p-parameterised form. A second algorithm, mh1 in lazyppl-singlesite, implements a single-site proposal kernel by inspecting the Haskell heap.
  • LazyPPL/Distributions.hs and LazyPPL/Distributions/* provide common distributions and abstract types capturing exchangeability. For example, newCustomer :: Restaurant -> Prob Table for the Chinese Restaurant Process (DirichletP.hs) and Restaurant -> Prob [Dish] for the Indian Buffet Process (IBP.hs).

Installation

Build with Cabal: install GHCup for GHC 9.14.1 and Cabal 3.18.2.0, then cabal update and cabal build in the repo root. First build takes a few minutes.

Run a demo: cabal run -fdemos wiener-exe (or regression-exe, clustering-exe, etc.), or explore in the REPL with cabal repl lib:lazyppl.

The library is pure Haskell and needs no LAPACK or BLAS installation. The plotting demos use the matplotlib Haskell wrapper, which calls into Python: sudo apt-get install -y --no-install-recommends python3-matplotlib python3-numpy python3-scipy python-is-python3.

To try lazyppl in your browser without installing anything, click Open in GitHub Codespaces. This opens a ready-to-use VS Code environment with GHC and Cabal already in place.

Writing your own probabilistic models

Under executables: in examples/package.yaml, add a stanza and run hpack examples (0.39.6) to regenerate examples/lazyppl-examples.cabal:

executables:
  # ...
  mymodel-exe:
    main:                MyModel.hs
    source-dirs:         models
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    - -main-is MyModel
    dependencies:
    - lazyppl

Run with cabal run mymodel-exe, or open in the REPL: cabal repl exe:mymodel-exe.