预处理蒙特卡洛
项目描述
pocoMC 是用于加速贝叶斯推理的预处理蒙特卡罗方法的 Python 实现
入门
简单的介绍
pocoMC使用归一化流通过消除其参数之间的任何相关性来预处理目标分布。然后,该代码使用强大的自适应序列蒙特卡罗算法生成可用于参数估计的后验样本,该算法表现出的采样效率可以比没有前置条件时高几个数量级。此外,还提供了可用于贝叶斯模型比较任务的模型证据pocoMC的无偏估计。
文档
阅读pocomc.readthedocs.io上的文档以获取更多信息、示例和教程。
安装
pocomc使用pip运行安装:
pip install pocomc
或者,从源代码安装:
git clone https://github.com/minaskar/pocomc.git
cd pocomc
python setup.py install
基本示例
例如,如果您想从具有均匀先验的 10 维 Rosenbrock 分布中抽取样本,您可以执行以下操作:
import pocomc as pc
import numpy as np
n_dim = 10 # Number of dimensions
def log_prior(x):
if np.any((x < -10.0) | (x > 10.0)): # If any dimension is out of bounds, the log prior is -infinity
return -np.inf
else:
return -const
def log_likelihood(x):
return -np.sum(10.0*(x[:,::2]**2.0 - x[:,1::2])**2.0 \
+ (x[:,::2] - 1.0)**2.0, axis=1)
n_particles = 1000
prior_samples = np.random.uniform(size=(nwalkers, ndim), low=-10.0, high=10.0)
sampler = pc.Sampler(n_particles,
n_dim,
log_likelihood,
log_prior,
vectorize_likelihood=True,
bounds=(-10.0, 10.0)
)
sampler.run(prior_samples)
results = sampler.results # Dictionary with results
署名和引文
如果您发现此代码对您的研究有用,请引用以下论文:
@article{karamanis2022accelerating,
title={Accelerating astronomical and cosmological inference with Preconditioned Monte Carlo},
author={Karamanis, Minas and Beutler, Florian and Peacock, John A and Nabergoj, David and Seljak, Uros},
journal={arXiv preprint arXiv:2207.05652},
year={2022}
}
@article{karamanis2022pocomc,
title={pocoMC: A Python package for accelerated Bayesian inference in astronomy and cosmology},
author={Karamanis, Minas and Nabergoj, David and Beutler, Florian and Peacock, John A and Seljak, Uros},
journal={arXiv preprint arXiv:2207.05660},
year={2022}
}
执照
版权所有 2022-Now Minas Karamanis 和贡献者。
pocoMC是根据 GPL-3.0 许可提供的免费软件。有关详细信息,请参阅LICENSE文件。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
pocomc-0.2.2.tar.gz
(41.0 kB
查看哈希)
内置分布
pocomc-0.2.2-py3-none-any.whl
(43.4 kB
查看哈希)