{ "info": { "author": "David P. Fleming", "author_email": "dflemin3@uw.edu", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Scientific/Engineering :: Astronomy" ], "description": "***approxposterior***\n\nOverview\n========\n\nGiven a set of observations, often one wishes to infer model parameters given the data. To do so, one\ncan use Bayesian inference to derive a posterior probability distribution\nfor model parameters conditioned on the observed data, with uncertainties. In astronomy, for example, it is common\nto fit for a transiting planet's radius from observations of stellar fluxes as a function of time using the Mandel & Agol (2002)\ntransit model. Typically, one can derive posterior distributions for model parameters using Markov Chain Monte Carlo (MCMC) techniques where each MCMC iteration, one computes the likelihood of the data given the model parameters. To compute the likelihood,\none evaluates the model to make predictions to be compared against the observations, e.g. with a Chi^2 metric. In practice, MCMC analyses can require anywhere from 10,000 to over 1,000,000 likelihood evaluations, depending on the complexity of the model and the dimensionality of the problem. When using a slow model, e.g. one that takes minutes to run, running an MCMC analysis quickly becomes very computationally expensive, an often intractable. In this case, approximate techniques are required to compute Bayesian posterior distributions in a reasonable amount of time by minimizing the number of model evaluations.\n\napproxposterior is a Python implementation of [Bayesian Active Learning for Posterior Estimation](https://www.cs.cmu.edu/~kkandasa/pubs/kandasamyIJCAI15activePostEst.pdf)\nby Kandasamy et al. (2015) and [Adaptive Gaussian process approximation for Bayesian inference with expensive likelihood functions](https://arxiv.org/abs/1703.09930) by Wang & Li (2017).\nThese algorithms allow the user to compute full approximate posterior probability distributions for inference problems with computationally expensive models. These algorithms work by training a Gaussian Process (GP) to effectively become a surrogate model for the likelihood evaluation by modeling the covariances in logprobability space. To improve the GP's own predictive performance, both algorithms leverage the inherent uncertainty in the GP's predictions to identify high-likelihood regions in parameter space where the GP is uncertain. The algorithms then evaluate the model at these points to compute the likelihood and re-trains the GP to maximize the GP's predictive ability while minimizing the number of model evaluations. Check out [Bayesian Active Learning for Posterior Estimation](https://www.cs.cmu.edu/~kkandasa/pubs/kandasamyIJCAI15activePostEst.pdf) by Kandasamy et al. (2015) and [Adaptive Gaussian process approximation for Bayesian inference with expensive likelihood functions](https://arxiv.org/abs/1703.09930) by Wang & Li (2017)\nfor in-depth descriptions of the respective algorithms.\n\nIn practice, we find that approxposterior can derive full approximate joint posterior probability distributions that are accurate\napproximations to the true, underlying distributions with only of order 100s-1000s model evaluations to train the GP, compared to 100,000, often more, required by MCMC methods, depending on the inference problem. The approximate marginal posterior distributions have medians that are all typically within 1-5% of the true values, with similar uncertainties to the true distributions. We have validated approxposterior for 2-5 dimensional problems, while Kandasamy et al. (2015) found in an 9-dimensional case that the BAPE algorithm significantly outperformed MCMC methods in terms of accuracy and speed. See their paper for details and check out the examples for more information and example use cases.\n\nCode Status and Documentation\n=============================\n\napproxposterior runs on Python 3.5+.\n\n[![build status](http://img.shields.io/travis/dflemin3/approxposterior/master.svg?style=flat)](https://travis-ci.org/dflemin3/approxposterior)\n\n[![DOI](http://joss.theoj.org/papers/10.21105/joss.00781/status.svg)](https://doi.org/10.21105/joss.00781)\n\nCheck out the [documentation](https://dflemin3.github.io/approxposterior/) for a more in-depth explanation about the code,\ndetailed API documentation, numerous examples.\n\nInstallation\n============\n\nUsing pip:\n\n```bash\npip install approxposterior\n```\n\nThis step can fail if george (the Python Gaussian Process package) is not properly installed and compiled.\nTo install george, run\n\n```bash\n conda install -c conda-forge george\n```\n\n>From source:\n\n```bash\npython setup.py install\n```\n\nA simple example\n===================\n\nBelow is a simple application of approxposterior based on the Wang & Li (2017) example. Note that\nwe adapted this example and shortened it so that it only takes about 1 minute to run.\n\nTo keep track of the MCMC progress, set ```verbose = True``` in the ```approx.run``` method. This setting\noutputs X/M where M is the total number of MCMC iterations to be evaluated, 5,000 in this example, and x is the current\niteration number. Note that setting ```verbose = True``` also outputs additional diagnostic information, such as when\nthe MCMC finishes, what the estimated burn-in is, and other quantities that are useful for tracking the progress of\nyour code. In this example, we set ```verbose = False``` for simplicity.\n\n```python\nfrom approxposterior import approx, gpUtils, likelihood as lh\nimport numpy as np\n\n# Define algorithm parameters\nm0 = 50 # Initial size of training set\nm = 20 # Number of new points to find each iteration\nnmax = 10 # Maximum number of iterations\nDmax = 0.1 # KL-Divergence convergence limit\nkmax = 5 # Number of iterations for Dmax convergence to kick in\nnKLSamples = 10000 # Number of samples from posterior to use to calculate KL-Divergence\nbounds = ((-5,5), (-5,5)) # Prior bounds\nalgorithm = \"BAPE\" # Use the Kandasamy et al. (2015) formalism\n\n# emcee MCMC parameters\nsamplerKwargs = {\"nwalkers\" : 20} # emcee.EnsembleSampler parameters\nmcmcKwargs = {\"iterations\" : int(2.0e4)} # emcee.EnsembleSampler.run_mcmc parameters\n\n# Randomly sample initial conditions from the prior\ntheta = np.array(lh.rosenbrockSample(m0))\n\n# Evaluate forward model log likelihood + lnprior for each theta\ny = np.zeros(len(theta))\nfor ii in range(len(theta)):\n y[ii] = lh.rosenbrockLnlike(theta[ii]) + lh.rosenbrockLnprior(theta[ii])\n\n# Create the the default GP which uses an ExpSquaredKernel\ngp = gpUtils.defaultGP(theta, y)\n\n# Initialize object using the Wang & Li (2017) Rosenbrock function example\nap = approx.ApproxPosterior(theta=theta,\n y=y,\n gp=gp,\n lnprior=lh.rosenbrockLnprior,\n lnlike=lh.rosenbrockLnlike,\n priorSample=lh.rosenbrockSample,\n algorithm=algorithm)\n\n# Run!\nap.run(m=m, nmax=nmax, Dmax=Dmax, kmax=kmax, bounds=bounds, estBurnin=True,\n nKLSamples=nKLSamples, mcmcKwargs=mcmcKwargs, cache=False,\n samplerKwargs=samplerKwargs, verbose=True)\n\n# Check out the final posterior distribution!\nimport corner\n\n# Load in chain from last iteration\nsamples = ap.sampler.get_chain(discard=ap.iburns[-1], flat=True, thin=ap.ithins[-1])\n\n# Corner plot!\nfig = corner.corner(samples, quantiles=[0.16, 0.5, 0.84], show_titles=True,\n scale_hist=True, plot_contours=True)\n\n#fig.savefig(\"finalPosterior.png\", bbox_inches=\"tight\") # Uncomment to save\n```\n\nThe final distribution will look something like this:\n\n![Final posterior probability distribution for the Wang & Li (2017) example.](paper/final_posterior.png)\n\nCheck out the [examples](https://github.com/dflemin3/approxposterior/tree/master/examples/Notebooks) directory for Jupyter Notebook examples and explanations. Check out the full [documentation](https://dflemin3.github.io/approxposterior/) for a more in-depth explanation of classes, methods, variables, and how to use the code.\n\nContribution\n============\n\nIf you would like to contribute to this code, please feel free to fork the repository, make some edits, and open a pull request.\nIf you find a bug, have a suggestion, etc, please open up an issue!\n\nPlease cite this repository and both Kandasamy et al. (2015) and Wang & Li (2017) if you use this code!\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dflemin3/approxposterior", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "approxposterior", "package_url": "https://pypi.org/project/approxposterior/", "platform": "", "project_url": "https://pypi.org/project/approxposterior/", "project_urls": { "Homepage": "https://github.com/dflemin3/approxposterior" }, "release_url": "https://pypi.org/project/approxposterior/0.2.post1/", "requires_dist": [ "corner", "emcee (==3.0rc2)", "george", "h5py", "matplotlib (>=2.0.0)", "numpy", "pybind11", "pytest", "scipy", "sklearn" ], "requires_python": "", "summary": "Gaussian Process Approximation to Posterior Distributions", "version": "0.2.post1" }, "last_serial": 4817163, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "4b8e8a4bba37ec8442221cc4d9a07346", "sha256": "a064eee231d0d309e347882847e2d57d0fed8b9af0efb09de28f46b009d17f73" }, "downloads": -1, "filename": "approxposterior-0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4b8e8a4bba37ec8442221cc4d9a07346", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 55526, "upload_time": "2018-03-06T21:46:18", "url": "https://files.pythonhosted.org/packages/4c/47/b982d10b68e5f64300f7e6b648f6a16beaa19e81f650056d76d7e0ff76f8/approxposterior-0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afb07c9a5ed907476e71115573f95c7c", "sha256": "83d9559b325ec45765e00b57992c9f6b8378387b45b9455ea22429b6bbce2d1c" }, "downloads": -1, "filename": "approxposterior-0.1.tar.gz", "has_sig": false, "md5_digest": "afb07c9a5ed907476e71115573f95c7c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20670, "upload_time": "2018-03-06T21:46:20", "url": "https://files.pythonhosted.org/packages/00/5d/87d6f31c5d4f20b558d0da68f77480897f5bbc1e0cbc60a322224d0f09b6/approxposterior-0.1.tar.gz" } ], "0.1.post1": [ { "comment_text": "", "digests": { "md5": "eb9715896943f8a405e42b14f540410c", "sha256": "7d39ead04ef7c7dcf32aa414b0888f0e722cd18d8b10c3d8d2fc8391d96f8b8c" }, "downloads": -1, "filename": "approxposterior-0.1.post1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "eb9715896943f8a405e42b14f540410c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 58955, "upload_time": "2018-07-12T01:06:57", "url": "https://files.pythonhosted.org/packages/97/4c/822a623382fbc1b6c611307d713a44f9980ad5f0987a4613113034938c22/approxposterior-0.1.post1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2c5960721eff02a8f8ddfc96c60bda95", "sha256": "11aea99f57c264ed78e12a05e8ecff8a3260768a334703cf673d34c07f9f7e07" }, "downloads": -1, "filename": "approxposterior-0.1.post1.tar.gz", "has_sig": false, "md5_digest": "2c5960721eff02a8f8ddfc96c60bda95", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23154, "upload_time": "2018-07-12T01:06:59", "url": "https://files.pythonhosted.org/packages/e2/1a/04c37e063167efdf8d8c8ce4cd7a252f86a72a6efbb3966a546170e43149/approxposterior-0.1.post1.tar.gz" } ], "0.2.post1": [ { "comment_text": "", "digests": { "md5": "e567cd6c73acf15affd44a3d08e544bf", "sha256": "d410a25cf42a3f5fb5b81a081341e8e6dac845dc86810cc490659d321e03becd" }, "downloads": -1, "filename": "approxposterior-0.2.post1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e567cd6c73acf15affd44a3d08e544bf", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 41431, "upload_time": "2019-02-13T19:36:42", "url": "https://files.pythonhosted.org/packages/d2/65/2f527767f5e0a9fbf2f09562d8c799e2170f104748f362139ceaca1847f1/approxposterior-0.2.post1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7318c752c50137ab6c2f3d964c55966a", "sha256": "2e454bc5836049da21c84dc3ed9ba04f846e4039bf3b495746bc45796ebed38a" }, "downloads": -1, "filename": "approxposterior-0.2.post1.tar.gz", "has_sig": false, "md5_digest": "7318c752c50137ab6c2f3d964c55966a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30647, "upload_time": "2019-02-13T19:36:44", "url": "https://files.pythonhosted.org/packages/79/72/b149c9fffccaed8fafcc940bdb3396a14a329faaaabed451539a73567733/approxposterior-0.2.post1.tar.gz" } ], "0.2rc0": [ { "comment_text": "", "digests": { "md5": "d7059891cf96ccb75a17b4d8f7bc3c47", "sha256": "e47264b7ad38362bbea95f476c4a0072bea29b0cb23b8dbe9f5f2129f80ef329" }, "downloads": -1, "filename": "approxposterior-0.2rc0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d7059891cf96ccb75a17b4d8f7bc3c47", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 83972, "upload_time": "2019-02-12T23:48:54", "url": "https://files.pythonhosted.org/packages/23/df/d96bb13e9ff4c8c901d2788bc06e5d172d7f039f5854a8d20648a2e46f4b/approxposterior-0.2rc0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2af04a14b1fbbdb38b4c08c44751138d", "sha256": "95b88bccf0e8ed6ed02079d2dfe30956ced6b0b88057f1f35adf0a6474477ab6" }, "downloads": -1, "filename": "approxposterior-0.2rc0.tar.gz", "has_sig": false, "md5_digest": "2af04a14b1fbbdb38b4c08c44751138d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30661, "upload_time": "2019-02-12T23:48:56", "url": "https://files.pythonhosted.org/packages/1f/91/a097f2259adb061eb712b99caae6a235806dbeeeccf5f6e9502c0072a6ec/approxposterior-0.2rc0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e567cd6c73acf15affd44a3d08e544bf", "sha256": "d410a25cf42a3f5fb5b81a081341e8e6dac845dc86810cc490659d321e03becd" }, "downloads": -1, "filename": "approxposterior-0.2.post1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e567cd6c73acf15affd44a3d08e544bf", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 41431, "upload_time": "2019-02-13T19:36:42", "url": "https://files.pythonhosted.org/packages/d2/65/2f527767f5e0a9fbf2f09562d8c799e2170f104748f362139ceaca1847f1/approxposterior-0.2.post1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7318c752c50137ab6c2f3d964c55966a", "sha256": "2e454bc5836049da21c84dc3ed9ba04f846e4039bf3b495746bc45796ebed38a" }, "downloads": -1, "filename": "approxposterior-0.2.post1.tar.gz", "has_sig": false, "md5_digest": "7318c752c50137ab6c2f3d964c55966a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 30647, "upload_time": "2019-02-13T19:36:44", "url": "https://files.pythonhosted.org/packages/79/72/b149c9fffccaed8fafcc940bdb3396a14a329faaaabed451539a73567733/approxposterior-0.2.post1.tar.gz" } ] }