2个不稳定版本
0.2.0 | 2024年1月4日 |
---|---|
0.1.0 | 2024年1月4日 |
#1822 in 算法
11KB
189 行
metromc
使用均匀转移核的独立性Metropolis-Hastings算法进行马尔可夫链蒙特卡洛(MCMC)采样。
使用tinyrand RNG以大约50M样本/秒的速度采样。
支持以下分布
通过提供PDF的实现或包装来自优秀的statrs crate的实现,可以轻松添加更多一元分布。
示例
使用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}");
}
依赖项
~5MB
~97K SLoC