metromc

Crates.iometromc
lib.rsmetromc
version0.2.0
sourcesrc
created_at2024-01-04 05:42:13.114645
updated_at2024-01-04 06:17:34.986736
descriptionMarkov chain Monte Carlo sampling using the Independence Metropolis-Hastings algorithm.
homepage
repositoryhttps://github.com/obsidiandynamics/mcmc
max_upload_size
id1088194
size35,604
Emil Koutanov (ekoutanov)

documentation

README

metromc

Markov chain Monte Carlo (MCMC) sampling using the Independence Metropolis-Hastings algorithm with uniform transition kernel.

Crates.io docs.rs Build Status

Uses the tinyrand RNG to sample at a rate of ~50M samples/sec.

Supports the following distributions:

It is easy to add more univariate distributions by supplying an implementation of a PDF or wrapping one from the excellent statrs crate.

Example

Draw samples from the Gaussian distribution using MCMC.

use std::ops::RangeInclusive;
use tinyrand::Wyrand;
use metromc::gaussian::Gaussian;
use metromc::sampler::{Config, Sampler};

// sample from Gaussian with µ=0.0 and σ=1.0, in the interval [-5.0, 5.0]
let sampler = Sampler::new(Config {
    rand: Wyrand::default(),
    dist: Gaussian::new(0.0, 1.0),
    range: -5.0..=5.0,
});

// take 1,000 samples after dropping the first 10
for sample in sampler.skip(10).take(1_000) {
    println!("{sample:.6}");
}
Commit count: 0

cargo fmt