πΌ Fugue
A type-safe, monadic probabilistic programming library for Rust β pre-1.0 and actively developed
Write elegant probabilistic programs by composing Model values in direct style; execute them with pluggable interpreters and state-of-the-art inference algorithms.
Supported Rust: 1.87+ β’ Platforms: Linux / macOS / Windows β’ Crate: fugue-ppl on crates.io
β¨ Features
- Monadic PPL: Compose probabilistic programs using pure functional abstractions
- Type-Safe Distributions: 17 built-in probability distributions with natural return types
- Multiple Inference Methods: MCMC, HMC, SMC, Variational Inference, ABC
- Comprehensive Diagnostics: R-hat convergence, effective sample size, validation
- Numerically Stable: Log-space computations throughout for robust probability arithmetic
- Ergonomic Macros: Do-notation (
prob!), vectorization (plate!), addressing (addr!)
π€ Why Fugue?
- π Type-safe distributions: natural return types (Bernoulli β
bool, Poisson/Binomial βu64, Categorical βusize) - π§© Direct-style, monadic design: compose
Model<T>values withbind/mapfor explicit, readable control flow - π Pluggable interpreters: prior sampling, replay, scoring, and safe variants
- π Diagnostics: R-hat, ESS, validation utilities, and a structured error taxonomy (see
error) - β‘ Performance-minded: O(1), allocation-free address clones (
Arc<str>with a cached hash) and numerically stable log-space computations
π¦ Distributions
Bernoulli, Beta, Binomial, Categorical, Cauchy, ChiSquared, DiscreteUniform, Exponential, Gamma, InverseGamma, Laplace, LogNormal, Normal, Poisson, StudentT, Uniform, Weibull β 17 in total, each with natural return types and validated parameters.
π§ͺ Where Fugue stands today
Fugue is 0.1.x: pre-1.0, actively developed, with no SemVer stability guarantee yet and a single primary maintainer (see Roadmap, below). It's extensively tested β hundreds of unit, integration, and property-based tests, including statistical regression tests against closed-form posteriors β but that's not the same claim as "production-ready." Treat it as a serious, honestly-scoped research-grade PPL: pin an exact version, read the CHANGELOG before upgrading, and expect breaking API changes between 0.1.x releases as the design settles.
π¦ Installation
[]
= "0.2.0"
Quickstart
π‘ Example
use *;
use StdRng;
use SeedableRng;
// Run inference with model defined in closure
let mut rng = seed_from_u64;
let samples = adaptive_mcmc_chain;
let mu_values: = samples.iter
.filter_map
.collect;
π Documentation
- User Guide - Comprehensive tutorials and examples
- API Reference - Complete API documentation
- Examples - See the
examples/directory, including one runnable example per inference method:adaptive_mcmc_chain- most foundation/statistical-modeling examples (e.g.bayesian_coin_flip.rs)hmc_chain(HMC) - see thehmcmodule rustdoc for a runnable doctestadaptive_smc(SMC) -examples/smc_inference.rsabc_smc_weighted(ABC) -examples/abc_inference.rsoptimize_meanfield_vi_with_config(VI) -examples/vi_inference.rs
- References - Zotero library for Fugue
π€ Community
- Issues & Bugs: Use GitHub Issues
- Feature Requests: Open an issue with the
enhancementlabel - Discord: Join our Discord server
πΊοΈ Roadmap
This project is an ongoing exploration of probabilistic programming in Rust. While many pieces are production-leaning, parts may not be 100% complete or correct yet. Iβm steadily working toward a more robust implementation and broader feature set.
Planned focus areas:
- Strengthening core correctness and numerical stability
- Expanding distribution and inference coverage
- API refinements and stability guarantees
- Improved documentation, diagnostics, and examples
API stability / SemVer policy: Fugue follows Cargo's pre-1.0 SemVer convention: any 0.x.y -> 0.(x+1).0 bump may contain breaking changes, and 0.x.y -> 0.x.(y+1) is additive/non-breaking. There is no 1.0 stability commitment yet; always pin an exact version and read the CHANGELOG before upgrading the minor version.
π€ Contributing
Contributions welcome! See our contributing guidelines.
&&
π License
Licensed under the MIT License.
π Citation
If you use Fugue in your research, please cite:
Or refer to the "Internal" collection in Zotero to generate a bibliography.