API#

Main Class#

class gptide.gpscipy.GPtideScipy(xd, xm, sd, cov_func, cov_params, **kwargs)#

Gaussian Process regression class

Uses scipy to do the heavy lifting

Parameters:
xd: numpy.ndarray [N, D]

Input data locations

xm: numpy.ndarray [M, D]

Output/target point locations

sd: float

Data noise parameter

cov_func: callable function

Function used to compute the covariance matrices

cov_params: tuple

Parameters passed to cov_func

Other Parameters:
P: int (default=1)

number of output dimensions

cov_kwargs: dictionary, optional

keyword arguments passed to cov_func

mean_func: callable function

Returns the mean function

mean_params: tuple

parameters passed to the mean function

mean_kwargs: dict

kwargs passed to the mean function

Attributes:
mean_func

Methods

__call__(yd)

Predict the GP posterior mean given data

conditional(yd[, samples])

Sample from the conidtional distribution

log_marg_likelihood(yd)

Compute the log of the marginal likelihood

prior([samples, noise])

Sample from the prior distribution

update_xm(xm)

Update the output locations and the covariance kernel

__call__(yd)#

Predict the GP posterior mean given data

Parameters:
yd: numpy.ndarray [N,1]

Observed data

Returns:
numpy.ndarray

Prediction

__init__(xd, xm, sd, cov_func, cov_params, **kwargs)#

Initialise GP object and evaluate mean and covatiance functions.

conditional(yd, samples=1)#

Sample from the conidtional distribution

Parameters:
yd: numpy.ndarray [N,1]

Observed data

samples: int, optional (default=1)

number of samples

Returns:
conditional_sample: numpy.ndarray [N,samples]

output array

log_marg_likelihood(yd)#

Compute the log of the marginal likelihood

prior(samples=1, noise=0.0)#

Sample from the prior distribution

Parameters:
samples: int, optional (default=1)

number of samples

Returns:
prior_sample: numpy.ndarray [N,samples]

array of output samples

update_xm(xm)#

Update the output locations and the covariance kernel

Parent Class#

Classes for Gaussian Process regression

class gptide.gp.GPtide(xd, xm, sd, cov_func, cov_params, **kwargs)#

Gaussian Process base class

Intended as a placeholder for classes built with other libraries (scipy, jax)

Attributes:
mean_func

Methods

__call__(yd)

Placeholder

conditional(yd[, samples])

Placeholder

log_marg_likelihood(yd)

Placeholder

prior([samples])

Placeholder

update_xm(xm)

Update the output locations and the covariance kernel

conditional(yd, samples=1)#

Placeholder

log_marg_likelihood(yd)#

Placeholder

prior(samples=1)#

Placeholder

update_xm(xm)#

Update the output locations and the covariance kernel

Covariance functions#

Covariance functions for optimal interpolation

gptide.cov.cosine(x, xpr, l)#

Cosine base function

gptide.cov.cosine_rw06(x, xpr, l)#

Cosine base function

gptide.cov.expquad(x, xpr, l)#

Exponential quadration base function/Squared exponential/RBF

gptide.cov.matern12(x, xpr, l)#

Matern 1/2 base function

gptide.cov.matern32(x, xpr, l)#

Matern 3/2 base function

gptide.cov.matern32_matrix(d, l)#

Non scaled [var 1] Matern 3/2 that takes a distance martrix as an input (i.e. not a vector of coordinates as above)

Parameters:
l: Matern length scale
d: distance matrix
gptide.cov.matern52(x, xpr, l)#

Matern 5/2 base function

gptide.cov.matern_general(dx, eta, nu, l)#

General Matern base function

gptide.cov.matern_spectra(f, eta, nu, l, n=1)#

Helper routine to compute the power spectral density of a general Matern function

gptide.cov.periodic(x, xpr, l, p)#

Periodic base function

Inference#

MCMC parameter estimation using emcee

gptide.mcmc.mcmc(xd, yd, covfunc, cov_priors, noise_prior, meanfunc=None, mean_priors=[], mean_kwargs={}, GPclass=<class 'gptide.gpscipy.GPtideScipy'>, gp_kwargs={}, nwalkers=None, nwarmup=200, niter=20, nprior=500, parallel=False, verbose=False, progress=True)#

Main MCMC function

Run MCMC using emcee.EnsembleSampler and return posterior samples, log probability of your MCMC chain, samples from your priors and the actual emcee.EnsembleSampler [for testing].

Parameters:
xd: numpy.ndarray [N, D]

Input data locations / predictor variable(s)

yd: numpy.ndarray [N,1]

Observed data

covfunc: function

Covariance function

cov_priors: list of scipy.stats.rv_continuous objects

List containing prior probability distribution for each parameter of the covfunc

noise_priors: scipy.stats.rv_continuous object

Prior for I.I.D. noise

Returns:
samples:

MCMC chains after burn in

log_prob:

Log posterior probability for each sample in the MCMC chain after burn in

p0:

Samples from the prior distributions

sampler: emcee.EnsembleSampler

The actual emcee.EnsembleSampler used

Other Parameters:
meanfunc: function [None]

Mean function

mean_priors: list of scipy.stats.rv_continuous objects

List containing prior probability distribution for each parameter of the meanfunc

mean_kwargs: dict

Key word arguments for the mean function

GPclass: gptide.gp.GPtide class [GPtideScipy]

The GP class used to estimate the log marginal likelihood

gp_kwargs: dict

Key word arguments for the GPclass initialisation

nwalkers: int or None

see emcee.EnsembleSampler. If None it will be 20 times the number of parameters.

nwarmup: int

see emcee.EnsembleSampler

niter: int

see emcee.EnsembleSampler.run_mcmc

nprior: int

number of samples from the prior distributions to output

parallel: bool [False]

Set to true to run parallel

verbose: bool [False]

Set to true for more output

gptide.mle.mle(xd, yd, covfunc, covparams_ic, noise_ic, meanfunc=None, meanparams_ic=[], mean_kwargs={}, GPclass=<class 'gptide.gpscipy.GPtideScipy'>, gp_kwargs={}, priors=None, method='L-BFGS-B', bounds=None, options=None, callback=None, verbose=False)#

Main MLE function

Optimise the GP kernel parameters by minimising the negative log marginal likelihood/probability using scipy.optimize.minimize. If priors are specified the log marginal probability is optimised, otherwise the log marginal likelihood is minimised.

Parameters:
xd: numpy.ndarray [N, D]

Input data locations / predictor variable(s)

yd: numpy.ndarray [N,1]

Observed data

covfunc: function

Covariance function

covparams_ic: numeric

Initial guess for the covariance function parameters

noise_ic: scipy.stats.rv_continuous object

Initial guess for the I.I.D. noise

Returns:
res: OptimizeResult

Result of the scipy.optimize.minimize call

Other Parameters:
meanfunc: function [None]

Mean function

meanparams_ic: scipy.stats.rv_continuous object

Initial guess for the mean function parameters

mean_kwargs: dict

Key word arguments for the mean function

GPclass: gptide.gp.GPtide class [GPtideScipy]

The GP class used to estimate the log marginal likelihood

gp_kwargs: dict

Key word arguments for the GPclass initialisation

priors:

List containing prior probability distribution for each parameter of the noise, covfunc and meanfunc. If specified the log marginal probability is optimised, otherwise the log marginal likelihood is minimised.

verbose: bool [False]

Set to true for more output

method: str [‘L-BFGS-B’]

see scipy.optimize.minimize

bounds: sequence or Bounds, optional [None]

see scipy.optimize.minimize

options: dict, optional [None]

see scipy.optimize.minimize

callback: callable, optional [None]

see scipy.optimize.minimize