pyemcee


Namepyemcee JSON
Version 0.2.6 PyPI version JSON
download
home_pagehttps://mcfit.github.io/pyemcee/
Summarypyemcee: Python implementation of the affine-invariant MCMC Hammer
upload_time2023-12-22 19:18:34
maintainer
docs_urlNone
authorAshkbiz Danehkar
requires_python
licensehttp://www.gnu.org/licenses/gpl.html
keywords pyemcee mcmc emcee python ensemble sampler hammer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            =======
pyemcee
=======

.. image:: https://img.shields.io/pypi/v/pyemcee.svg?style=flat
    :target: https://pypi.python.org/pypi/pyemcee/
    :alt: PyPI Version
    
.. image:: https://app.travis-ci.com/mcfit/pyemcee.svg?branch=master
    :target: https://app.travis-ci.com/github/mcfit/pyemcee
    :alt: Build Status
    
.. image:: https://ci.appveyor.com/api/projects/status/oqnksaooj338xn4d?svg=true
    :target: https://ci.appveyor.com/project/danehkar/pyemcee
    :alt: Build Status
    
.. image:: https://coveralls.io/repos/github/mcfit/pyemcee/badge.svg?
    :target: https://coveralls.io/github/mcfit/pyemcee?branch=master
    :alt: Coverage Status
    
.. image:: https://img.shields.io/badge/license-GPL-blue.svg
    :target: https://github.com/mcfit/pyemcee/blob/master/LICENSE
    :alt: GitHub license
    
.. image:: https://img.shields.io/conda/vn/conda-forge/pyemcee.svg
    :target: https://anaconda.org/conda-forge/pyemcee
    :alt: Anaconda Cloud
    
.. image:: https://readthedocs.org/projects/pyemcee/badge/?version=latest
    :target: https://pyemcee.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status
    
.. image:: https://img.shields.io/badge/python-2.7%2C%203.5-blue.svg
    :alt: Support Python versions 2.7, 3.4 and 3.5
    
.. image:: https://img.shields.io/badge/DOI-10.5281/zenodo.4495911-blue.svg
    :target: https://doi.org/10.5281/zenodo.4495911
    :alt: Zenodo
    
.. image:: https://mybinder.org/badge_logo.svg
 :target: https://mybinder.org/v2/gh/mcfit/pyemcee/HEAD?labpath=Notebook.ipynb

Description
===========

**pyemcee** is a Python implementation of the *affine-invariant Markov chain Monte Carlo (MCMC) ensemble sampler*, based on `sl_emcee <https://github.com/mcfit/sl_emcee>`_ by `M. A. Nowak <http://space.mit.edu/home/mnowak/isis_vs_xspec/>`_, an S-Lang/`ISIS <http://space.mit.edu/cxc/isis/>`_ implementation of the MCMC Hammer proposed by `Goodman & Weare (2010) <http://dx.doi.org/10.2140/camcos.2010.5.65>`_, and also implemented in Python (`emcee <https://github.com/dfm/emcee>`_) by `Foreman-Mackey et al. (2013) <https://ui.adsabs.harvard.edu/abs/2013PASP..125..306F/abstract>`_. 


Installation
============

To install the last version, all you should need to do is

.. code-block::

    $ python setup.py install

To install the stable version, you can use the preferred installer program (pip):

.. code-block::

    $ pip install pyemcee

or you can install it from the cross-platform package manager *conda*:

.. code-block::

    $ conda install -c conda-forge pyemcee

This package requires the following packages:

    - `NumPy <https://numpy.org/>`_
    - `SciPy <https://scipy.org/scipylib/>`_
    - `Matplotlib <https://matplotlib.org/>`_

How to Use
==========

The Documentation of the functions provides in detail in the *API Documentation* (`mcfit.github.io/pyemcee/doc <https://mcfit.github.io/pyemcee/doc>`_). This Python library creates the MCMC sampling  for given upper and lower uncertainties, and propagates uncertainties of parameters into the function.

See *Jupyter Notebook*: `Notebook.ipynb <https://github.com/mcfit/pyemcee/blob/master/Notebook.ipynb>`_

Run *Jupyter Notebook* on `Binder <https://mybinder.org/v2/gh/mcfit/pyemcee/HEAD?labpath=Notebook.ipynb>`_:

.. image:: https://mybinder.org/badge_logo.svg
 :target: https://mybinder.org/v2/gh/mcfit/pyemcee/HEAD?labpath=Notebook.ipynb

First, you need to load the **pyemcee** library as follows:

.. code-block:: python

    import pyemcee
    import numpy as np

You need to define your function. For example:

.. code-block:: python

    def myfunc21(input1):
       result1 = np.sum(input1)
       result2 = input1[1] ** input1[0]
       return [result1, result2]

Then, specify the upper and lower uncertainties of the prior parameters:

.. code-block:: python

    input1 = np.array([1., 2.])
    input1_err = np.array([0.2, 0.5])
    input1_err_p = input1_err
    input1_err_m = -input1_err
    output1 = myfunc21(input1)
    output1_num = len(output1)

Choose the appropriate uncertainty distribution. For example, for a uniform distribution, use_gaussian=0, and a Gaussian distribution use_gaussian=1. Then, specify the number of walkers and the number of iterations, e.g. walk_num=30 and iteration_num=100. You can then create the MCMC sample and propagate the uncertainties of the input parameters into your defined functions as follows:

.. code-block:: python

    use_gaussian=0 # uniform distribution from min value to max value
    walk_num=30 # number of walkers
    iteration_num=100 # number of samplers
    mcmc_sim = pyemcee.hammer(myfunc21, input1, input1_err_m, 
                              input1_err_p, output1, walk_num, 
                              iteration_num, use_gaussian)

To determine the upper and lower errors of the function outputs, you need to run with the chosen appropriate confidence level. For example, a 1.645-sigma standard deviation can be specified with clevel=0.90. For a 1-sigma standard deviation, we have clevel=0.682:

.. code-block:: python

    clevel=0.68268949 # 1-sigma
    output1_error = pyemcee.find_errors(output1, mcmc_sim, clevel, do_plot=1)
    
which shows the following distribution histograms:

.. image:: https://raw.githubusercontent.com/mcfit/pyemcee/master/examples/images/histogram0.png
    :width: 100

.. image:: https://raw.githubusercontent.com/mcfit/pyemcee/master/examples/images/histogram1.png
    :width: 100

To prevent plotting, you should set do_plot=None. To print the results:

.. code-block:: python

    for i in range(0, output1_num):
       print(output1[i], output1_error[i,:])

which provide the upper and lower limits on each parameter:

.. code-block::

    3.0 [-0.35801017 0.35998471]
    2.0 [-0.37573196 0.36297235]

For other standard deviation, you should use different confidence levels:

.. code-block:: python

    clevel=0.38292492 # 0.5-sigma
    clevel=0.68268949 # 1.0-sigma
    clevel=0.86638560 # 1.5-sigma
    clevel=0.90       # 1.645-sigma
    clevel=0.95       # 1.960-sigma
    clevel=0.95449974 # 2.0-sigma
    clevel=0.98758067 # 2.5-sigma
    clevel=0.99       # 2.575-sigma
    clevel=0.99730020 # 3.0-sigma
    clevel=0.99953474 # 3.5-sigma
    clevel=0.99993666 # 4.0-sigma
    clevel=0.99999320 # 4.5-sigma
    clevel=0.99999943 # 5.0-sigma
    clevel=0.99999996 # 5.5-sigma
    clevel=0.999999998# 6.0-sigma

Documentation
=============

For more information on how to use the API functions from the pyemcee library, please read the `API Documentation  <https://mcfit.github.io/pyemcee/doc>`_ published on `mcfit.github.io/pyemcee <https://mcfit.github.io/pyemcee>`_.


Learn More
==========

==================  =============================================
**Documentation**   https://pyemcee.readthedocs.io/
**Repository**      https://github.com/mcfit/pyemcee
**Issues & Ideas**  https://github.com/mcfit/pyemcee/issues
**Conda-Forge**     https://anaconda.org/conda-forge/pyemcee
**PyPI**            https://pypi.org/project/pyemcee/
**Archive**         `10.5281/zenodo.4495911 <https://doi.org/10.5281/zenodo.4495911>`_
==================  =============================================

            

Raw data

            {
    "_id": null,
    "home_page": "https://mcfit.github.io/pyemcee/",
    "name": "pyemcee",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pyemcee,MCMC,emcee,Python,ensemble sampler,hammer",
    "author": "Ashkbiz Danehkar",
    "author_email": "ashkbiz.danehkar@students.mq.edu.au",
    "download_url": "https://files.pythonhosted.org/packages/a0/13/dbebc939751d62d2a3a489fdab06494dcfcfcf45020eb82aa80fefde0498/pyemcee-0.2.6.tar.gz",
    "platform": "any",
    "description": "=======\npyemcee\n=======\n\n.. image:: https://img.shields.io/pypi/v/pyemcee.svg?style=flat\n    :target: https://pypi.python.org/pypi/pyemcee/\n    :alt: PyPI Version\n    \n.. image:: https://app.travis-ci.com/mcfit/pyemcee.svg?branch=master\n    :target: https://app.travis-ci.com/github/mcfit/pyemcee\n    :alt: Build Status\n    \n.. image:: https://ci.appveyor.com/api/projects/status/oqnksaooj338xn4d?svg=true\n    :target: https://ci.appveyor.com/project/danehkar/pyemcee\n    :alt: Build Status\n    \n.. image:: https://coveralls.io/repos/github/mcfit/pyemcee/badge.svg?\n    :target: https://coveralls.io/github/mcfit/pyemcee?branch=master\n    :alt: Coverage Status\n    \n.. image:: https://img.shields.io/badge/license-GPL-blue.svg\n    :target: https://github.com/mcfit/pyemcee/blob/master/LICENSE\n    :alt: GitHub license\n    \n.. image:: https://img.shields.io/conda/vn/conda-forge/pyemcee.svg\n    :target: https://anaconda.org/conda-forge/pyemcee\n    :alt: Anaconda Cloud\n    \n.. image:: https://readthedocs.org/projects/pyemcee/badge/?version=latest\n    :target: https://pyemcee.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n    \n.. image:: https://img.shields.io/badge/python-2.7%2C%203.5-blue.svg\n    :alt: Support Python versions 2.7, 3.4 and 3.5\n    \n.. image:: https://img.shields.io/badge/DOI-10.5281/zenodo.4495911-blue.svg\n    :target: https://doi.org/10.5281/zenodo.4495911\n    :alt: Zenodo\n    \n.. image:: https://mybinder.org/badge_logo.svg\n :target: https://mybinder.org/v2/gh/mcfit/pyemcee/HEAD?labpath=Notebook.ipynb\n\nDescription\n===========\n\n**pyemcee** is a Python implementation of the *affine-invariant Markov chain Monte Carlo (MCMC) ensemble sampler*, based on `sl_emcee <https://github.com/mcfit/sl_emcee>`_ by `M. A. Nowak <http://space.mit.edu/home/mnowak/isis_vs_xspec/>`_, an S-Lang/`ISIS <http://space.mit.edu/cxc/isis/>`_ implementation of the MCMC Hammer proposed by `Goodman & Weare (2010) <http://dx.doi.org/10.2140/camcos.2010.5.65>`_, and also implemented in Python (`emcee <https://github.com/dfm/emcee>`_) by `Foreman-Mackey et al. (2013) <https://ui.adsabs.harvard.edu/abs/2013PASP..125..306F/abstract>`_. \n\n\nInstallation\n============\n\nTo install the last version, all you should need to do is\n\n.. code-block::\n\n    $ python setup.py install\n\nTo install the stable version, you can use the preferred installer program (pip):\n\n.. code-block::\n\n    $ pip install pyemcee\n\nor you can install it from the cross-platform package manager *conda*:\n\n.. code-block::\n\n    $ conda install -c conda-forge pyemcee\n\nThis package requires the following packages:\n\n    - `NumPy <https://numpy.org/>`_\n    - `SciPy <https://scipy.org/scipylib/>`_\n    - `Matplotlib <https://matplotlib.org/>`_\n\nHow to Use\n==========\n\nThe Documentation of the functions provides in detail in the *API Documentation* (`mcfit.github.io/pyemcee/doc <https://mcfit.github.io/pyemcee/doc>`_). This Python library creates the MCMC sampling  for given upper and lower uncertainties, and propagates uncertainties of parameters into the function.\n\nSee *Jupyter Notebook*: `Notebook.ipynb <https://github.com/mcfit/pyemcee/blob/master/Notebook.ipynb>`_\n\nRun *Jupyter Notebook* on `Binder <https://mybinder.org/v2/gh/mcfit/pyemcee/HEAD?labpath=Notebook.ipynb>`_:\n\n.. image:: https://mybinder.org/badge_logo.svg\n :target: https://mybinder.org/v2/gh/mcfit/pyemcee/HEAD?labpath=Notebook.ipynb\n\nFirst, you need to load the **pyemcee** library as follows:\n\n.. code-block:: python\n\n    import pyemcee\n    import numpy as np\n\nYou need to define your function. For example:\n\n.. code-block:: python\n\n    def myfunc21(input1):\n       result1 = np.sum(input1)\n       result2 = input1[1] ** input1[0]\n       return [result1, result2]\n\nThen, specify the upper and lower uncertainties of the prior parameters:\n\n.. code-block:: python\n\n    input1 = np.array([1., 2.])\n    input1_err = np.array([0.2, 0.5])\n    input1_err_p = input1_err\n    input1_err_m = -input1_err\n    output1 = myfunc21(input1)\n    output1_num = len(output1)\n\nChoose the appropriate uncertainty distribution. For example, for a uniform distribution, use_gaussian=0, and a Gaussian distribution use_gaussian=1. Then, specify the number of walkers and the number of iterations, e.g. walk_num=30 and iteration_num=100. You can then create the MCMC sample and propagate the uncertainties of the input parameters into your defined functions as follows:\n\n.. code-block:: python\n\n    use_gaussian=0 # uniform distribution from min value to max value\n    walk_num=30 # number of walkers\n    iteration_num=100 # number of samplers\n    mcmc_sim = pyemcee.hammer(myfunc21, input1, input1_err_m, \n                              input1_err_p, output1, walk_num, \n                              iteration_num, use_gaussian)\n\nTo determine the upper and lower errors of the function outputs, you need to run with the chosen appropriate confidence level. For example, a 1.645-sigma standard deviation can be specified with clevel=0.90. For a 1-sigma standard deviation, we have clevel=0.682:\n\n.. code-block:: python\n\n    clevel=0.68268949 # 1-sigma\n    output1_error = pyemcee.find_errors(output1, mcmc_sim, clevel, do_plot=1)\n    \nwhich shows the following distribution histograms:\n\n.. image:: https://raw.githubusercontent.com/mcfit/pyemcee/master/examples/images/histogram0.png\n    :width: 100\n\n.. image:: https://raw.githubusercontent.com/mcfit/pyemcee/master/examples/images/histogram1.png\n    :width: 100\n\nTo prevent plotting, you should set do_plot=None. To print the results:\n\n.. code-block:: python\n\n    for i in range(0, output1_num):\n       print(output1[i], output1_error[i,:])\n\nwhich provide the upper and lower limits on each parameter:\n\n.. code-block::\n\n    3.0 [-0.35801017 0.35998471]\n    2.0 [-0.37573196 0.36297235]\n\nFor other standard deviation, you should use different confidence levels:\n\n.. code-block:: python\n\n    clevel=0.38292492 # 0.5-sigma\n    clevel=0.68268949 # 1.0-sigma\n    clevel=0.86638560 # 1.5-sigma\n    clevel=0.90       # 1.645-sigma\n    clevel=0.95       # 1.960-sigma\n    clevel=0.95449974 # 2.0-sigma\n    clevel=0.98758067 # 2.5-sigma\n    clevel=0.99       # 2.575-sigma\n    clevel=0.99730020 # 3.0-sigma\n    clevel=0.99953474 # 3.5-sigma\n    clevel=0.99993666 # 4.0-sigma\n    clevel=0.99999320 # 4.5-sigma\n    clevel=0.99999943 # 5.0-sigma\n    clevel=0.99999996 # 5.5-sigma\n    clevel=0.999999998# 6.0-sigma\n\nDocumentation\n=============\n\nFor more information on how to use the API functions from the pyemcee library, please read the `API Documentation  <https://mcfit.github.io/pyemcee/doc>`_ published on `mcfit.github.io/pyemcee <https://mcfit.github.io/pyemcee>`_.\n\n\nLearn More\n==========\n\n==================  =============================================\n**Documentation**   https://pyemcee.readthedocs.io/\n**Repository**      https://github.com/mcfit/pyemcee\n**Issues & Ideas**  https://github.com/mcfit/pyemcee/issues\n**Conda-Forge**     https://anaconda.org/conda-forge/pyemcee\n**PyPI**            https://pypi.org/project/pyemcee/\n**Archive**         `10.5281/zenodo.4495911 <https://doi.org/10.5281/zenodo.4495911>`_\n==================  =============================================\n",
    "bugtrack_url": null,
    "license": "http://www.gnu.org/licenses/gpl.html",
    "summary": "pyemcee: Python implementation of the affine-invariant MCMC Hammer",
    "version": "0.2.6",
    "project_urls": {
        "Download": "https://github.com/mcfit/pyemcee",
        "Homepage": "https://mcfit.github.io/pyemcee/"
    },
    "split_keywords": [
        "pyemcee",
        "mcmc",
        "emcee",
        "python",
        "ensemble sampler",
        "hammer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3efcbf2f80207fea9409595faac2a52e2a7f00abb5182acda1d51734266f954f",
                "md5": "a4a817cfce1d21fca653b5f1a2e3406e",
                "sha256": "5a44217598be0cbfa774221974a886a104f495a54bc60a6500865df596f62b78"
            },
            "downloads": -1,
            "filename": "pyemcee-0.2.6-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a4a817cfce1d21fca653b5f1a2e3406e",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 33353,
            "upload_time": "2023-12-22T19:18:33",
            "upload_time_iso_8601": "2023-12-22T19:18:33.032188Z",
            "url": "https://files.pythonhosted.org/packages/3e/fc/bf2f80207fea9409595faac2a52e2a7f00abb5182acda1d51734266f954f/pyemcee-0.2.6-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a013dbebc939751d62d2a3a489fdab06494dcfcfcf45020eb82aa80fefde0498",
                "md5": "48a2636ccb9a19af19954e39da1c4c29",
                "sha256": "6277bb06a133a5ab8f4cff1296ff8698ffebbdc41cce600e44b43ff199879721"
            },
            "downloads": -1,
            "filename": "pyemcee-0.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "48a2636ccb9a19af19954e39da1c4c29",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22687,
            "upload_time": "2023-12-22T19:18:34",
            "upload_time_iso_8601": "2023-12-22T19:18:34.210819Z",
            "url": "https://files.pythonhosted.org/packages/a0/13/dbebc939751d62d2a3a489fdab06494dcfcfcf45020eb82aa80fefde0498/pyemcee-0.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-22 19:18:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mcfit",
    "github_project": "pyemcee",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": false,
    "appveyor": true,
    "lcname": "pyemcee"
}
        
Elapsed time: 0.27328s