ordofp_bayes - Probabilistic Programming for OrdoFP
"Probabilitas est ratio incertitudinis." — Probability is the measure of uncertainty. (Modern)
This crate provides Bayesian inference algorithms for probabilistic programming,
using functional abstractions, as part of the OrdoFP ecosystem.
Adapted third-party algorithms are inventoried in ORIGINAL_SOURCE.md
in this crate and the repo-root THIRD_PARTY_NOTICES.md.
Features
- Sequential Monte Carlo (SMC)
- Metropolis-Hastings (MCMC)
- Importance Sampling
- Parallel particle generation via Rayon (
rayonfeature)
Performance
Weight calculations are written as tight slice loops that LLVM
auto-vectorizes; there is no explicit SIMD (std::simd) code in this
crate.
Example
use Normal;
use ;
use SeedableRng;
use StdRng;
use ;
// Give every closure call its own seed, so the 1000 draws below are
// genuinely independent samples rather than 1000 copies of one number.
static SEED: AtomicU64 = new;
// Define a simple model: sample once from a prior distribution.
let mut rng = seed_from_u64;
// Note: `MetropolisHastings::infer` draws `iterations` independent
// samples via resampling rather than running an MCMC chain, so
// `burn_in` (the `100` below) has no effect on this code path — it
// only matters for `infer_traceable`'s trace-based chain.
let mh = new;
// Run inference
let samples: = mh.infer;
assert_eq!;
// Real sampling variation: 1000 draws from a continuous Normal are not
// all identical (this cannot flake — the odds of a false failure are
// astronomically small).
assert!;