GP Utility Functions

gpUtils.py - Gaussian Process Utilities

Gaussian process utility functions for initializing GPs and optimizing their hyperparameters.

approxposterior.gpUtils.defaultHyperPrior(p)[source]

Default prior function for GP hyperparameters. This prior also keeps the hyperparameters within a reasonable huge range, [-20, 20]. Note that george operates on the log hyperparameters, except for the mean function.

Parameters

p (array/iterable) – Array of GP hyperparameters

Returns

prior

Return type

float

approxposterior.gpUtils.defaultGP(theta, y, order=None, white_noise=-12, fitAmp=False)[source]

Basic utility function that initializes a simple GP with an ExpSquaredKernel. This kernel works well in many applications as it effectively enforces a prior on the smoothness of the function and is infinitely differentiable.

Parameters
  • theta (array) – Design points

  • y (array) – Data to condition GP on, e.g. the lnlike + lnprior at each design point, theta.

  • order (int, optional) – Order of PolynomialKernel to add to ExpSquaredKernel. Defaults to None, that is, no PolynomialKernel is added and the GP only uses the ExpSquaredKernel

  • white_noise (float, optional) – From george docs: “A description of the logarithm of the white noise variance added to the diagonal of the covariance matrix”. Defaults to ln(white_noise) = -12. Note: if order is not None, you might need to set the white_noise to a larger value for the computation to be numerically stable, but this, as always, depends on the application.

  • fitAmp (bool, optional) – Whether or not to include an amplitude term. Defaults to False.

Returns

gp – Gaussian process with initialized kernel and factorized covariance matrix.

Return type

george.GP

approxposterior.gpUtils.optimizeGP(gp, theta, y, seed=None, nGPRestarts=1, method='powell', options=None, p0=None, gpHyperPrior=<function defaultHyperPrior>)[source]

Optimize hyperparameters of an arbitrary george Gaussian Process by maximizing the marginal loglikelihood.

Parameters
  • gp (george.GP) –

  • theta (array) –

  • y (array) – data to condition GP on

  • seed (int, optional) – numpy RNG seed. Defaults to None.

  • nGPRestarts (int, optional) – Number of times to restart the optimization. Defaults to 1. Increase this number if the GP isn’t optimized well.

  • method (str, optional) – scipy.optimize.minimize method. Defaults to powell.

  • options (dict, optional) – kwargs for the scipy.optimize.minimize function. Defaults to None.

  • p0 (array, optional) – Initial guess for kernel hyperparameters. If None, defaults to np.random.randn for each parameter

  • gpHyperPrior (str/callable, optional) – Prior function for GP hyperparameters. Defaults to the defaultHyperPrior fn. This function asserts that the mean must be negative and that each log hyperparameter is within the range [-20,20].

Returns

optimizedGP

Return type

george.GP