7 releases

0.3.1 Feb 18, 2022
0.3.0 Feb 18, 2022
0.2.1 Feb 16, 2022
0.1.2 Feb 14, 2022

#2277 in Algorithms

MIT/Apache

22KB
524 lines

probs

Provide definition of domain and basic distribution. Implement various sampler with Iterator.

Basic Usage

Construct a sampler of certain sampling technique

use sampler::Global;
fn test() {
  sampler::univar::Icdf::new()

Sample a distribution with it

    .sample(distribution::univar::normal::<i8>(0.0, 32.0))

Use it like an Iterator as you would

    .enumerate()
    .for_each(|(i, x)| println!("sample#{}: {}", i, x))
}

Arbitrary Distribution

ANY customized distribution can be sampled with provided samplers

sampler::univar::Icdf::new()
  .sample(|x: &u8| (x % 8) as f64)

Multi-dimensional

Gibbs Sampler is used to sample distribution on high dimension

  • Fix-dimensioned domain is represented with ndarray
sampler::univar::Icdf::new()
  .gibbs(nd::Dim([2, 2]), 100) // 2x2 domain; skip first 100 samples
  .sample(|m: &nd::Array2<u8>| m.sum() as f64)

Dependencies

~14MB
~109K SLoC