Likelihood Functions

likelihood.py - Example Likelihood Functions

This file contains routines for simple test, likelihood, prior, and sampling functions for cases like the Wang & Li (2017) Rosenbrock function example.

approxposterior.likelihood.rosenbrockLnlike(theta)[source]

Rosenbrock function as a loglikelihood following Wang & Li (2017)

Parameters

theta (array) –

Returns

l – likelihood

Return type

float

approxposterior.likelihood.rosenbrockLnprior(theta)[source]

Uniform log prior for the 2D Rosenbrock likelihood following Wang & Li (2017) where the prior pi(x) is a uniform distribution over [-5, 5] x [-5, 5] x … for however many dimensions (dim = x.shape[-1])

Parameters

theta (array) –

Returns

l – log prior

Return type

float

approxposterior.likelihood.rosenbrockSample(n=1, dim=2)[source]

Sample N points from the prior pi(x) is a uniform distribution over [-5, 5] x [-5, 5]

Parameters
  • n (int, optional) – Number of samples. Defaults to 1.

  • dim (int, optional) – Dimensionality. Defaults to 2.

Returns

sample – n x 2 array of floats samples from the prior

Return type

floats

approxposterior.likelihood.rosenbrockLnprob(theta)[source]

Compute the log probability (log posterior) as likelihood * prior

Parameters

theta (array) –

Returns

l – log probability

Return type

float

approxposterior.likelihood.testBOFn(theta)[source]

Simple 1D test Bayesian optimization function adapted from https://krasserm.github.io/2018/03/21/bayesian-optimization/

approxposterior.likelihood.testBOFnSample(n=1)[source]

Sample N points from the prior pi(x) is a uniform distribution over [-2, 1]

Parameters

n (int, optional) – Number of samples. Defaults to 1.

Returns

sample – n x 1 array of floats samples from the prior

Return type

floats

approxposterior.likelihood.testBOFnLnPrior(theta)[source]

Log prior distribution for the test Bayesian Optimization function. This prior is a simple uniform function over [-2, 1]

Parameters

theta (float/array) –

Returns

l – log prior

Return type

float

approxposterior.likelihood.sphereLnlike(theta)[source]

Sphere test 2D optimization function. Note: This is actually the negative of the sphere function and it’s just a 0 mean, unit std Gaussian. Taken from: https://en.wikipedia.org/wiki/Test_functions_for_optimization

Parameters

theta (array) –

Returns

val – Function value at theta

Return type

float

approxposterior.likelihood.sphereSample(n=1)[source]

Sample N points from the prior pi(theta) is a uniform distribution over [-2, 2]

Parameters

n (int, optional) – Number of samples. Defaults to 1.

Returns

sample – n x 1 array of floats samples from the prior

Return type

floats

approxposterior.likelihood.sphereLnprior(theta)[source]

Log prior distribution for the sphere test optimization function. This prior is a simple uniform function over [-2, 2] for each dimension.

Parameters

theta (float/array) –

Returns

l – log prior

Return type

float