![logo](logo.png)
**pocoMC is a Python implementation of the Preconditioned Monte Carlo method for accelerated Bayesian inference**
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/minaskar/pocomc/blob/master/LICENSE)
[![Documentation Status](https://readthedocs.org/projects/pocomc/badge/?version=latest)](https://pocomc.readthedocs.io/en/latest/?badge=latest)
# Getting started
## Brief introduction
``pocoMC`` is a Python package for fast Bayesian posterior and model evidence estimation. It leverages
the Preconditioned Monte Carlo (PMC) algorithm, offering significant speed improvements over
traditional methods like MCMC and Nested Sampling. Ideal for large-scale scientific problems
with expensive likelihood evaluations, non-linear correlations, and multimodality, ``pocoMC``
provides efficient and scalable posterior sampling and model evidence estimation. Widely used
in cosmology and astronomy, ``pocoMC`` is user-friendly, flexible, and actively maintained.
## Documentation
Read the docs at [pocomc.readthedocs.io](https://pocomc.readthedocs.io) for more information, examples and tutorials.
## Installation
To install ``pocomc`` using ``pip`` run:
```bash
pip install pocomc
```
or, to install from source:
```bash
git clone https://github.com/minaskar/pocomc.git
cd pocomc
python setup.py install
```
## Basic example
For instance, if you wanted to draw samples from a 10-dimensional Rosenbrock distribution with a uniform prior, you would do something like:
```python
import pocomc as pc
import numpy as np
from scipy.stats import uniform
n_dim = 10 # Number of dimensions
prior = pc.Prior(n_dim*[uniform(-10.0, 20.0)]) # U(-10,10)
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)
sampler = pc.Sampler(
prior=prior,
likelihood=log_likelihood,
vectorize=True,
)
sampler.run()
samples, weights, logl, logp = sampler.posterior() # Weighted posterior samples
logz, logz_err = sampler.evidence() # Bayesian model evidence estimate and uncertainty
```
# Attribution & Citation
Please cite the following papers if you found this code useful in your research:
```bash
@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, Uro{\v{s}}},
journal={Monthly Notices of the Royal Astronomical Society},
volume={516},
number={2},
pages={1644--1653},
year={2022},
publisher={Oxford University Press}
}
@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}
}
```
# Licence
Copyright 2022-Now Minas Karamanis and contributors.
``pocoMC`` is free software made available under the GPL-3.0 License. For details see the `LICENSE` file.
Raw data
{
"_id": null,
"home_page": "https://github.com/minaskar/pocomc",
"name": "pocomc",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Minas Karamanis",
"author_email": "minaskar@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/13/91/b5118f38e75d0a6ef6f6736db1bf1f7af4e84a8f43cb728e15451b92f158/pocomc-1.2.6.tar.gz",
"platform": "any",
"description": "![logo](logo.png)\n\n**pocoMC is a Python implementation of the Preconditioned Monte Carlo method for accelerated Bayesian inference**\n\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://github.com/minaskar/pocomc/blob/master/LICENSE)\n[![Documentation Status](https://readthedocs.org/projects/pocomc/badge/?version=latest)](https://pocomc.readthedocs.io/en/latest/?badge=latest)\n\n\n# Getting started\n\n## Brief introduction\n\n``pocoMC`` is a Python package for fast Bayesian posterior and model evidence estimation. It leverages \nthe Preconditioned Monte Carlo (PMC) algorithm, offering significant speed improvements over \ntraditional methods like MCMC and Nested Sampling. Ideal for large-scale scientific problems \nwith expensive likelihood evaluations, non-linear correlations, and multimodality, ``pocoMC`` \nprovides efficient and scalable posterior sampling and model evidence estimation. Widely used \nin cosmology and astronomy, ``pocoMC`` is user-friendly, flexible, and actively maintained.\n\n## Documentation\n\nRead the docs at [pocomc.readthedocs.io](https://pocomc.readthedocs.io) for more information, examples and tutorials.\n\n## Installation\n\nTo install ``pocomc`` using ``pip`` run:\n\n```bash\npip install pocomc\n```\n\nor, to install from source:\n\n```bash\ngit clone https://github.com/minaskar/pocomc.git\ncd pocomc\npython setup.py install\n```\n\n## Basic example\n\nFor instance, if you wanted to draw samples from a 10-dimensional Rosenbrock distribution with a uniform prior, you would do something like:\n\n```python\nimport pocomc as pc\nimport numpy as np\nfrom scipy.stats import uniform\n\nn_dim = 10 # Number of dimensions\n\nprior = pc.Prior(n_dim*[uniform(-10.0, 20.0)]) # U(-10,10)\n\ndef log_likelihood(x):\n return -np.sum(10.0*(x[:,::2]**2.0 - x[:,1::2])**2.0 \\\n + (x[:,::2] - 1.0)**2.0, axis=1)\n\nsampler = pc.Sampler(\n prior=prior,\n likelihood=log_likelihood,\n vectorize=True,\n)\nsampler.run()\n\nsamples, weights, logl, logp = sampler.posterior() # Weighted posterior samples\n\nlogz, logz_err = sampler.evidence() # Bayesian model evidence estimate and uncertainty\n```\n\n\n# Attribution & Citation\n\nPlease cite the following papers if you found this code useful in your research:\n\n```bash\n@article{karamanis2022accelerating,\n title={Accelerating astronomical and cosmological inference with preconditioned Monte Carlo},\n author={Karamanis, Minas and Beutler, Florian and Peacock, John A and Nabergoj, David and Seljak, Uro{\\v{s}}},\n journal={Monthly Notices of the Royal Astronomical Society},\n volume={516},\n number={2},\n pages={1644--1653},\n year={2022},\n publisher={Oxford University Press}\n}\n\n@article{karamanis2022pocomc,\n title={pocoMC: A Python package for accelerated Bayesian inference in astronomy and cosmology},\n author={Karamanis, Minas and Nabergoj, David and Beutler, Florian and Peacock, John A and Seljak, Uros},\n journal={arXiv preprint arXiv:2207.05660},\n year={2022}\n}\n```\n\n# Licence\n\nCopyright 2022-Now Minas Karamanis and contributors.\n\n``pocoMC`` is free software made available under the GPL-3.0 License. For details see the `LICENSE` file.\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Preconditioned Monte Carlo",
"version": "1.2.6",
"project_urls": {
"Homepage": "https://github.com/minaskar/pocomc"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "db439bcde0d06aefc46856af85e8c495e9026f3374af0e95a0bb396ef8f8c119",
"md5": "fdeeb973593df4eae7760123460dcec0",
"sha256": "fd087841d27cce0a0940697cd4ff95456dc15400d680db8fb82b133fa9945bd7"
},
"downloads": -1,
"filename": "pocomc-1.2.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fdeeb973593df4eae7760123460dcec0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 45985,
"upload_time": "2024-09-20T13:39:24",
"upload_time_iso_8601": "2024-09-20T13:39:24.937916Z",
"url": "https://files.pythonhosted.org/packages/db/43/9bcde0d06aefc46856af85e8c495e9026f3374af0e95a0bb396ef8f8c119/pocomc-1.2.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1391b5118f38e75d0a6ef6f6736db1bf1f7af4e84a8f43cb728e15451b92f158",
"md5": "5b87b241cf2b380f7d12ecd2c525eadd",
"sha256": "c9d28250b379ccd80eee043c1d1b6fbfb68e4fe07cf848f5a8b0af9c42052b31"
},
"downloads": -1,
"filename": "pocomc-1.2.6.tar.gz",
"has_sig": false,
"md5_digest": "5b87b241cf2b380f7d12ecd2c525eadd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 46329,
"upload_time": "2024-09-20T13:39:26",
"upload_time_iso_8601": "2024-09-20T13:39:26.281867Z",
"url": "https://files.pythonhosted.org/packages/13/91/b5118f38e75d0a6ef6f6736db1bf1f7af4e84a8f43cb728e15451b92f158/pocomc-1.2.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-20 13:39:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "minaskar",
"github_project": "pocomc",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": [
[
">=",
"1.20.0"
]
]
},
{
"name": "torch",
"specs": [
[
">=",
"1.12.0"
]
]
},
{
"name": "zuko",
"specs": [
[
">=",
"1.1.0"
]
]
},
{
"name": "tqdm",
"specs": [
[
">=",
"4.60.0"
]
]
},
{
"name": "scipy",
"specs": [
[
">=",
"1.4.0"
]
]
},
{
"name": "dill",
"specs": [
[
">=",
"0.3.8"
]
]
},
{
"name": "multiprocess",
"specs": [
[
">=",
"0.70.15"
]
]
}
],
"lcname": "pocomc"
}