tpt-sci-ppl
Probabilistic programming for the tpt-science pillar: a small model/DSL
layer and a from-scratch NUTS (No-U-Turn Sampler) Hamiltonian Monte Carlo
backend.
The original spec.txt planned to wrap nuts-rs; per the project's "build our
own internals" direction this crate implements NUTS directly on top of the
tpt-math substrate — reverse-mode gradients come from tpt-math-autodiff-rev
and randomness from tpt-math-prob — so there is no external sampler
dependency to audit or license-check.
Priors are expressed as reverse-mode differentiable closures (so the NUTS
gradient is exact). They can be written directly with the parameter autodiff
variable, or derived from a typed distribution in tpt-math-prob-bayes
(Gaussian, Beta, Gamma).
For a black-box log density whose gradient the caller supplies, use
gradient::fit_with_gradient (fit_with_gradient_parallel needs the rayon
feature).
Depends on tpt-math-prob-bayes, tpt-math-prob-core, tpt-math-autodiff-rev
(all published).
Example
use ModelBuilder;
use SplitMix64;
// mu ~ N(0, 5), data | mu ~ N(mu, 1)
let data = ;
let mut m = new;
m.gaussian_parameter;
m.set_data;
m.likelihood;
let model = m.build.unwrap;
let mut rng = seed_from_u64;
let trace = model.fit.unwrap;
let samples = trace.combined_samples;
let mean: f64 = samples.iter.map. / samples.len as f64;
assert!;
License
Licensed under either of MIT or Apache-2.0 at your option.