All Projects → dflemin3 → approxposterior

dflemin3 / approxposterior

Licence: MIT license
A Python package for approximate Bayesian inference and optimization using Gaussian processes

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to approxposterior

Stheno.jl
Probabilistic Programming with Gaussian processes in Julia
Stars: ✭ 318 (+783.33%)
Mutual labels:  bayesian-inference, gaussian-processes, approximate-inference
Gpstuff
GPstuff - Gaussian process models for Bayesian analysis
Stars: ✭ 106 (+194.44%)
Mutual labels:  bayesian-inference, gaussian-processes, bayesian-optimization
Bcpd
Bayesian Coherent Point Drift (BCPD/BCPD++); Source Code Available
Stars: ✭ 116 (+222.22%)
Mutual labels:  bayesian-inference, gaussian-processes
Exoplanet
Fast & scalable MCMC for all your exoplanet needs!
Stars: ✭ 122 (+238.89%)
Mutual labels:  bayesian-inference, gaussian-processes
pyrff
pyrff: Python implementation of random fourier feature approximations for gaussian processes
Stars: ✭ 24 (-33.33%)
Mutual labels:  gaussian-processes, bayesian-optimization
Neural Tangents
Fast and Easy Infinite Neural Networks in Python
Stars: ✭ 1,357 (+3669.44%)
Mutual labels:  bayesian-inference, gaussian-processes
Numpy Ml
Machine learning, in numpy
Stars: ✭ 11,100 (+30733.33%)
Mutual labels:  bayesian-inference, gaussian-processes
TemporalGPs.jl
Fast inference for Gaussian processes in problems involving time. Partly built on results from https://proceedings.mlr.press/v161/tebbutt21a.html
Stars: ✭ 89 (+147.22%)
Mutual labels:  bayesian-inference, gaussian-processes
FBNN
Code for "Functional variational Bayesian neural networks" (https://arxiv.org/abs/1903.05779)
Stars: ✭ 67 (+86.11%)
Mutual labels:  bayesian-inference, gaussian-processes
Stheno.jl
Probabilistic Programming with Gaussian processes in Julia
Stars: ✭ 233 (+547.22%)
Mutual labels:  bayesian-inference, gaussian-processes
Survival Analysis Using Deep Learning
This repository contains morden baysian statistics and deep learning based research articles , software for survival analysis
Stars: ✭ 139 (+286.11%)
Mutual labels:  bayesian-inference, gaussian-processes
ReactiveMP.jl
Julia package for automatic Bayesian inference on a factor graph with reactive message passing
Stars: ✭ 58 (+61.11%)
Mutual labels:  inference, bayesian-inference
Ipynotebook machinelearning
This contains a number of IP[y]: Notebooks that hopefully give a light to areas of bayesian machine learning.
Stars: ✭ 27 (-25%)
Mutual labels:  bayesian-inference, gaussian-processes
Bopp
BOPP: Bayesian Optimization for Probabilistic Programs
Stars: ✭ 112 (+211.11%)
Mutual labels:  bayesian-inference, bayesian-optimization
models
Forecasting 🇫🇷 elections with Bayesian statistics 🥳
Stars: ✭ 24 (-33.33%)
Mutual labels:  bayesian-inference, gaussian-processes
Vbmc
Variational Bayesian Monte Carlo (VBMC) algorithm for posterior and model inference in MATLAB
Stars: ✭ 123 (+241.67%)
Mutual labels:  bayesian-inference, gaussian-processes
Gpmp2
Gaussian Process Motion Planner 2
Stars: ✭ 161 (+347.22%)
Mutual labels:  inference, gaussian-processes
lgpr
R-package for interpretable nonparametric modeling of longitudinal data using additive Gaussian processes. Contains functionality for inferring covariate effects and assessing covariate relevances. Various models can be specified using a convenient formula syntax.
Stars: ✭ 22 (-38.89%)
Mutual labels:  bayesian-inference, gaussian-processes
Aboleth
A bare-bones TensorFlow framework for Bayesian deep learning and Gaussian process approximation
Stars: ✭ 127 (+252.78%)
Mutual labels:  bayesian-inference, gaussian-processes
noisy-networks-measurements
Noisy network measurement with stan
Stars: ✭ 42 (+16.67%)
Mutual labels:  inference, bayesian-inference

approxposterior

A Python package for approximate Bayesian inference with computationally-expensive models

Overview

approxposterior is a Python package for efficient approximate Bayesian inference and Bayesian optimization of computationally-expensive models. approxposterior trains a Gaussian process (GP) surrogate for the computationally-expensive model and employs an active learning approach to iteratively improve the GPs predictive performance while minimizing the number of calls to the expensive model required to generate the GP's training set.

approxposterior implements both the Bayesian Active Learning for Posterior Estimation (BAPE, Kandasamy et al. (2017)) and Adaptive Gaussian process approximation for Bayesian inference with expensive likelihood functions (AGP, Wang & Li (2018)) algorithms for estimating posterior probability distributions for use with inference problems with computationally-expensive models. In such situations, the 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 by Kandasamy et al. (2017) and the AGP paper by Wang & Li (2018) for in-depth descriptions of the respective algorithms.

Documentation

Check out the documentation at https://dflemin3.github.io/approxposterior/ for a more in-depth explanation about the code, detailed API notes, numerous examples with figures.

Installation

Using conda:

conda install -c conda-forge approxposterior

Using pip:

pip install approxposterior

This step can fail if george (the Python Gaussian Process package) is not properly installed and compiled. To install george, run

conda install -c conda-forge george

From source:

git clone https://github.com/dflemin3/approxposterior.git
cd approxposterior
python setup.py install

A simple example

Below is a simple application of approxposterior based on the Wang & Li (2017) example.

from approxposterior import approx, gpUtils, likelihood as lh, utility as ut
import numpy as np

# Define algorithm parameters
m0 = 50                           # Initial size of training set
m = 20                            # Number of new points to find each iteration
nmax = 2                          # Maximum number of iterations
bounds = [(-5,5), (-5,5)]         # Prior bounds
algorithm = "bape"                # Use the Kandasamy et al. (2017) formalism
seed = 57                         # RNG seed
np.random.seed(seed)

# emcee MCMC parameters
samplerKwargs = {"nwalkers" : 20}        # emcee.EnsembleSampler parameters
mcmcKwargs = {"iterations" : int(2.0e4)} # emcee.EnsembleSampler.run_mcmc parameters

# Sample design points from prior
theta = lh.rosenbrockSample(m0)

# Evaluate forward model log likelihood + lnprior for each theta
y = np.zeros(len(theta))
for ii in range(len(theta)):
    y[ii] = lh.rosenbrockLnlike(theta[ii]) + lh.rosenbrockLnprior(theta[ii])

# Default GP with an ExpSquaredKernel
gp = gpUtils.defaultGP(theta, y, white_noise=-12)

# Initialize object using the Wang & Li (2018) Rosenbrock function example
ap = approx.ApproxPosterior(theta=theta,
                            y=y,
                            gp=gp,
                            lnprior=lh.rosenbrockLnprior,
                            lnlike=lh.rosenbrockLnlike,
                            priorSample=lh.rosenbrockSample,
                            bounds=bounds,
                            algorithm=algorithm)

# Run!
ap.run(m=m, nmax=nmax, estBurnin=True, nGPRestarts=3, mcmcKwargs=mcmcKwargs,
       cache=False, samplerKwargs=samplerKwargs, verbose=True, thinChains=False,
       onlyLastMCMC=True)

# Check out the final posterior distribution!
import corner

# Load in chain from last iteration
samples = ap.sampler.get_chain(discard=ap.iburns[-1], flat=True, thin=ap.ithins[-1])

# Corner plot!
fig = corner.corner(samples, quantiles=[0.16, 0.5, 0.84], show_titles=True,
                    scale_hist=True, plot_contours=True)

# Plot where forward model was evaluated - uncomment to plot!
fig.axes[2].scatter(ap.theta[m0:,0], ap.theta[m0:,1], s=10, color="red", zorder=20)

# Save figure
fig.savefig("finalPosterior.png", bbox_inches="tight")

The final distribution will look something like this:

finalPosterior

The red points were selected by approxposterior by maximizing the BAPE utility function. At each red point, approxposterior ran the forward model to evaluate the true likelihood and added this input-likelihood pair to the GP's training set. We retrain the GP each time to improve its predictive ability. Note how the points are selected in regions of high posterior density, precisely where we would want to maximize the GP's predictive ability! By using the BAPE point selection scheme, approxposterior does not waste computational resources by evaluating the forward model in low likelihood regions.

Check out the examples directory for Jupyter Notebook examples and explanations. Check out the full documentation for a more in-depth explanation of classes, methods, variables, and how to use the code.

Contribution

If you would like to contribute to this code, please feel free to fork the repository, make some edits, and open a pull request. If you find a bug, have a suggestion, etc, please open up an issue!

Citation

If you use this code, please cite the following:

Fleming and VanderPlas (2018):

@ARTICLE{Fleming2018,
   author = {{Fleming}, D.~P. and {VanderPlas}, J.},
    title = "{approxposterior: Approximate Posterior Distributions in Python}",
  journal = {The Journal of Open Source Software},
     year = 2018,
    month = sep,
   volume = 3,
    pages = {781},
      doi = {10.21105/joss.00781},
   adsurl = {http://adsabs.harvard.edu/abs/2018JOSS....3..781P},
  adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}

Kandasamy et al. (2017):

@article{Kandasamy2017,
title = "Query efficient posterior estimation in scientific experiments via Bayesian active learning",
journal = "Artificial Intelligence",
volume = "243",
pages = "45 - 56",
year = "2017",
issn = "0004-3702",
doi = "https://doi.org/10.1016/j.artint.2016.11.002",
url = "http://www.sciencedirect.com/science/article/pii/S0004370216301394",
author = "Kirthevasan Kandasamy and Jeff Schneider and Barnabás Póczos",
keywords = "Posterior estimation, Active learning, Gaussian processes"}

Wang & Li (2018):

@article{Wang2018,
author = {Wang, Hongqiao and Li, Jinglai},
title = {Adaptive Gaussian Process Approximation for Bayesian Inference with Expensive Likelihood Functions},
journal = {Neural Computation},
volume = {30},
number = {11},
pages = {3072-3094},
year = {2018},
doi = {10.1162/neco\_a\_01127},
URL = { https://doi.org/10.1162/neco_a_01127},
eprint = {https://doi.org/10.1162/neco_a_01127}}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].