a probabilistic programming library for rust, built around a monad.

a model in fugue is a Model<T> value that you compose in direct style with bind and map. what that composition means is decided later, by the interpreter you hand it to — sample from the prior, replay a trace, score it, or run mcmc, hmc, smc, variational inference or abc over it. separating the model from the inference is the entire point. in most probabilistic languages the algorithm is entangled with how you declare the model, so trying a different sampler means rewriting the thing you were trying to hold constant.

the distributions are typed with their natural return types, which sounds minor and is not. bernoulli gives you a bool, poisson and binomial give you u64, categorical gives you a usize — rather than everything collapsing to f64 and being cast back at the point of use, which is where the off-by-one lives. seventeen distributions, all with validated parameters, and log-space arithmetic throughout so that multiplying a few thousand small probabilities does not quietly become zero.

there are macros for do-notation (prob!) and vectorisation (plate!), because monadic code in rust without them is unreadable and pretending otherwise helps nobody.

it is 0.2.x — pre-1.0, no semver guarantees yet, one primary maintainer. extensively tested, including property-based tests and statistical regressions against closed-form posteriors, but that is a different claim from production-ready. pin an exact version and read the changelog before upgrading.

view on github · learn it interactively at fugue.run