modppl 0.3.1

a experimental library for probabilistic programming in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::Real;
use rand::{rngs::ThreadRng, Rng};

/// Sample a random variable uniformly in the interval [0., 1.].
pub fn u01(rng: &mut ThreadRng) -> Real {
    rng.sample(rand::distributions::Uniform::new(0., 1.))
}

/// Trait for sampling distributions with an analytically calculable probability density function (pdf).
pub trait Distribution<T, U> {
    /// Return the `log[p(x; params)]`.
    fn logpdf(&self, x: &T, params: U) -> Real;

    /// Sample a random value `x ~ p(. ; params)`.
    fn random(&self, rng: &mut ThreadRng, params: U) -> T;
}