{"id":32175871,"url":"https://github.com/dflemin3/approxposterior","last_synced_at":"2025-10-21T19:50:39.834Z","repository":{"id":57411125,"uuid":"111036095","full_name":"dflemin3/approxposterior","owner":"dflemin3","description":"A Python package for approximate Bayesian inference and optimization using Gaussian processes","archived":false,"fork":false,"pushed_at":"2023-11-05T20:37:46.000Z","size":52499,"stargazers_count":42,"open_issues_count":5,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-10-09T19:03:29.056Z","etag":null,"topics":["approximate-inference","bayesian-inference","bayesian-optimization","gaussian-processes","inference","python"],"latest_commit_sha":null,"homepage":"https://dflemin3.github.io/approxposterior/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dflemin3.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null}},"created_at":"2017-11-17T00:03:06.000Z","updated_at":"2024-11-10T11:19:05.000Z","dependencies_parsed_at":"2025-04-11T11:50:06.725Z","dependency_job_id":null,"html_url":"https://github.com/dflemin3/approxposterior","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/dflemin3/approxposterior","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemin3%2Fapproxposterior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemin3%2Fapproxposterior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemin3%2Fapproxposterior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemin3%2Fapproxposterior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dflemin3","download_url":"https://codeload.github.com/dflemin3/approxposterior/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflemin3%2Fapproxposterior/sbom","scorecard":{"id":339052,"data":{"date":"2025-08-11","repo":{"name":"github.com/dflemin3/approxposterior","commit":"06f39df55c91cef68a6831bce18952965a404b81"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":3,"reason":"Found 3/10 approved changesets -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 28 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T05:22:09.011Z","repository_id":57411125,"created_at":"2025-08-18T05:22:09.011Z","updated_at":"2025-08-18T05:22:09.011Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005032,"owners_count":26083827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["approximate-inference","bayesian-inference","bayesian-optimization","gaussian-processes","inference","python"],"created_at":"2025-10-21T19:50:37.337Z","updated_at":"2025-10-21T19:50:39.828Z","avatar_url":"https://github.com/dflemin3.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"**approxposterior**\n===================\n\n***A Python package for approximate Bayesian inference with computationally-expensive models***\n\n\u003cp\u003e\n\u003ca href=\"https://github.com/dflemin3/approxposterior\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/GitHub-dflemin3%2Fapproxposterior-blue.svg?style=flat\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/dflemin3/approxposterior/blob/master/LICENSE\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg?style=flat\"\u003e\u003c/a\u003e\n\u003ca href=\"https://travis-ci.org/dflemin3/approxposterior\"\u003e\n\u003cimg src=\"http://img.shields.io/travis/dflemin3/approxposterior/master.svg?style=flat\"\u003e\u003c/a\u003e\n\u003ca href=\"https://doi.org/10.21105/joss.00781\"\u003e\n\u003cimg src=\"http://joss.theoj.org/papers/10.21105/joss.00781/status.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.python.org/pypi/approxposterior/\"\u003e\n\u003cimg src=\"https://img.shields.io/pypi/pyversions/approxposterior.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://conda.anaconda.org/conda-forge\"\u003e\n\u003cimg src=\"https://anaconda.org/conda-forge/approxposterior/badges/installer/conda.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://anaconda.org/conda-forge/approxposterior\"\u003e\n\u003cimg src=\"https://anaconda.org/conda-forge/approxposterior/badges/downloads.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://coveralls.io/github/dflemin3/approxposterior?branch=master\"\u003e\n\u003cimg src=\"https://coveralls.io/repos/github/dflemin3/approxposterior/badge.svg?branch=master\"\u003e\u003c/a\u003e\n\u003ca href=\"https://dflemin3.github.io/approxposterior/\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Docs-Read%20the%20docs-blue\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nOverview\n========\n\n`approxposterior` is a Python package for efficient approximate Bayesian\ninference and Bayesian optimization of computationally-expensive models. `approxposterior`\ntrains a Gaussian process (GP) surrogate for the computationally-expensive model\nand employs an active learning approach to iteratively improve the GPs predictive\nperformance while minimizing the number of calls to the expensive model required\nto generate the GP's training set.\n\n`approxposterior` implements both the [Bayesian Active Learning for Posterior Estimation (BAPE, Kandasamy et al. (2017))](https://www.sciencedirect.com/science/article/abs/pii/S0004370216301394) and [Adaptive Gaussian process approximation for Bayesian inference with expensive likelihood functions (AGP, Wang \u0026 Li (2018))](https://www.semanticscholar.org/paper/Adaptive-Gaussian-Process-Approximation-for-with-Wang-Li/a11e3a4144898920835ccff7ef0ed0b159b94bc6) algorithms for estimating posterior probability distributions for use with inference problems with computationally-expensive models. In such situations,\nthe goal is to infer posterior probability distributions for model parameters, given some data, with the additional constraint of minimizing the number of forward model evaluations given the model's assumed large computational cost.  `approxposterior` trains a Gaussian Process (GP) surrogate model for the likelihood evaluation by modeling the covariances in logprobability (logprior + loglikelihood) space. `approxposterior` then uses this GP within an MCMC sampler for each likelihood evaluation to perform the inference. `approxposterior` iteratively improves the GP's predictive performance by leveraging the inherent uncertainty in the GP's predictions to identify high-likelihood regions in parameter space where the GP is uncertain.  `approxposterior` then evaluates the forward model at these points to expand the training set in relevant regions of parameter space, re-training the GP to maximize its predictive ability while minimizing the size of the training set.  Check out [the BAPE paper](https://www.sciencedirect.com/science/article/abs/pii/S0004370216301394) by Kandasamy et al. (2017) and [the AGP paper](https://www.semanticscholar.org/paper/Adaptive-Gaussian-Process-Approximation-for-with-Wang-Li/a11e3a4144898920835ccff7ef0ed0b159b94bc6) by Wang \u0026 Li (2018) for in-depth descriptions of the respective algorithms.\n\nDocumentation\n=============\n\nCheck out the documentation at [https://dflemin3.github.io/approxposterior/](https://dflemin3.github.io/approxposterior/) for a more in-depth explanation about the code, detailed API notes, numerous examples with figures.\n\nInstallation\n============\n\nUsing conda:\n\n```bash\nconda install -c conda-forge approxposterior\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\nconda install -c conda-forge george\n```\n\nFrom source:\n\n```bash\ngit clone https://github.com/dflemin3/approxposterior.git\ncd approxposterior\npython setup.py install\n```\n\nA simple example\n================\n\nBelow is a simple application of `approxposterior` based on the Wang \u0026 Li (2017) example.\n\n```python\nfrom approxposterior import approx, gpUtils, likelihood as lh, utility as ut\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 = 2                          # Maximum number of iterations\nbounds = [(-5,5), (-5,5)]         # Prior bounds\nalgorithm = \"bape\"                # Use the Kandasamy et al. (2017) formalism\nseed = 57                         # RNG seed\nnp.random.seed(seed)\n\n# emcee MCMC parameters\nsamplerKwargs = {\"nwalkers\" : 20}        # emcee.EnsembleSampler parameters\nmcmcKwargs = {\"iterations\" : int(2.0e4)} # emcee.EnsembleSampler.run_mcmc parameters\n\n# Sample design points from prior\ntheta = 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# Default GP with an ExpSquaredKernel\ngp = gpUtils.defaultGP(theta, y, white_noise=-12)\n\n# Initialize object using the Wang \u0026 Li (2018) 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                            bounds=bounds,\n                            algorithm=algorithm)\n\n# Run!\nap.run(m=m, nmax=nmax, estBurnin=True, nGPRestarts=3, mcmcKwargs=mcmcKwargs,\n       cache=False, samplerKwargs=samplerKwargs, verbose=True, thinChains=False,\n       onlyLastMCMC=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# Plot where forward model was evaluated - uncomment to plot!\nfig.axes[2].scatter(ap.theta[m0:,0], ap.theta[m0:,1], s=10, color=\"red\", zorder=20)\n\n# Save figure\nfig.savefig(\"finalPosterior.png\", bbox_inches=\"tight\")\n```\n\nThe final distribution will look something like this:\n\n![finalPosterior](doc/_figures/finalPosterior.png)\n\nThe red points were selected by `approxposterior` by maximizing the BAPE utility function.\nAt each red point, `approxposterior` ran the forward model to evaluate the true likelihood\nand added this input-likelihood pair to the GP's training set. We retrain the GP each time\nto improve its predictive ability. Note how the points are selected in regions of\nhigh posterior density, precisely where we would want to maximize the GP's predictive ability! By using the\nBAPE point selection scheme, `approxposterior` does not waste computational resources by\nevaluating the forward model in low likelihood regions.\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\nCitation\n========\n\nIf you use this code, please cite the following:\n\nFleming and VanderPlas (2018):\n\n```bash\n@ARTICLE{Fleming2018,\n   author = {{Fleming}, D.~P. and {VanderPlas}, J.},\n    title = \"{approxposterior: Approximate Posterior Distributions in Python}\",\n  journal = {The Journal of Open Source Software},\n     year = 2018,\n    month = sep,\n   volume = 3,\n    pages = {781},\n      doi = {10.21105/joss.00781},\n   adsurl = {http://adsabs.harvard.edu/abs/2018JOSS....3..781P},\n  adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n}\n```\n\nKandasamy et al. (2017):\n\n```bash\n@article{Kandasamy2017,\ntitle = \"Query efficient posterior estimation in scientific experiments via Bayesian active learning\",\njournal = \"Artificial Intelligence\",\nvolume = \"243\",\npages = \"45 - 56\",\nyear = \"2017\",\nissn = \"0004-3702\",\ndoi = \"https://doi.org/10.1016/j.artint.2016.11.002\",\nurl = \"http://www.sciencedirect.com/science/article/pii/S0004370216301394\",\nauthor = \"Kirthevasan Kandasamy and Jeff Schneider and Barnabás Póczos\",\nkeywords = \"Posterior estimation, Active learning, Gaussian processes\"}\n```\n\nWang \u0026 Li (2018):\n\n```bash\n@article{Wang2018,\nauthor = {Wang, Hongqiao and Li, Jinglai},\ntitle = {Adaptive Gaussian Process Approximation for Bayesian Inference with Expensive Likelihood Functions},\njournal = {Neural Computation},\nvolume = {30},\nnumber = {11},\npages = {3072-3094},\nyear = {2018},\ndoi = {10.1162/neco\\_a\\_01127},\nURL = { https://doi.org/10.1162/neco_a_01127},\neprint = {https://doi.org/10.1162/neco_a_01127}}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflemin3%2Fapproxposterior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdflemin3%2Fapproxposterior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflemin3%2Fapproxposterior/lists"}