Gaussian Processes

GP

class pymc3.gp.gp.GP(mean_func=None, cov_func=None, X=None, sigma=0, *args, **kwargs)

Gausian process

Parameters:
  • mean_func (Mean) – Mean function of Gaussian process
  • cov_func (Covariance) – Covariance function of Gaussian process
  • X (array) – Grid of points to evaluate Gaussian process over. Only required if the GP is not an observed variable.
  • sigma (scalar or array) – Observation standard deviation (defaults to zero)
pymc3.gp.gp.sample_gp(trace, gp, X_values, samples=None, obs_noise=True, model=None, random_seed=None, progressbar=True)

Generate samples from a posterior Gaussian process.

Parameters:
  • trace (backend, list, or MultiTrace) – Trace generated from MCMC sampling.
  • gp (Gaussian process object) – The GP variable to sample from.
  • X_values (array) – Grid of values at which to sample GP.
  • samples (int) – Number of posterior predictive samples to generate. Defaults to the length of trace
  • obs_noise (bool) – Flag for including observation noise in sample. Defaults to True.
  • model (Model) – Model used to generate trace. Optional if in with context manager.
  • random_seed (integer > 0) – Random number seed for sampling.
  • progressbar (bool) – Flag for showing progress bar.
Returns:

Array of samples from posterior GP evaluated at Z.

Covariance Functions / Kernels

ExpQuad(input_dim, lengthscales[, active_dims]) The Exponentiated Quadratic kernel.
RatQuad(input_dim, lengthscales, alpha[, ...]) The Rational Quadratic kernel.
Matern32(input_dim, lengthscales[, active_dims]) The Matern kernel with nu = 3/2.
Matern52(input_dim, lengthscales[, active_dims]) The Matern kernel with nu = 5/2.
Exponential(input_dim, lengthscales[, ...]) The Exponential kernel.
Cosine(input_dim, lengthscales[, active_dims]) The Cosine kernel.
Linear(input_dim, c[, active_dims]) The Linear kernel.
Polynomial(input_dim, c, d, offset[, ...]) The Polynomial kernel.
WarpedInput(input_dim, cov_func, warp_func) Warp the inputs of any kernel using an arbitrary function defined using Theano.
Gibbs(input_dim, lengthscale_func[, args, ...]) The Gibbs kernel.
class pymc3.gp.cov.ExpQuad(input_dim, lengthscales, active_dims=None)

The Exponentiated Quadratic kernel. Also refered to as the Squared Exponential, or Radial Basis Function kernel.

\[k(x, x') = \mathrm{exp}\left[ -\frac{(x - x')^2}{2 \ell^2} \right]\]
class pymc3.gp.cov.RatQuad(input_dim, lengthscales, alpha, active_dims=None)

The Rational Quadratic kernel.

\[k(x, x') = \left(1 + \frac{(x - x')^2}{2\alpha\ell^2} \right)^{-\alpha}\]
class pymc3.gp.cov.Exponential(input_dim, lengthscales, active_dims=None)

The Exponential kernel.

\[k(x, x') = \mathrm{exp}\left[ -\frac{||x - x'||}{2\ell^2} \right]\]
class pymc3.gp.cov.Matern52(input_dim, lengthscales, active_dims=None)

The Matern kernel with nu = 5/2.

\[k(x, x') = \left(1 + \frac{\sqrt{5(x - x')^2}}{\ell} + \frac{5(x-x')^2}{3\ell^2}\right) \mathrm{exp}\left[ - \frac{\sqrt{5(x - x')^2}}{\ell} \right]\]
class pymc3.gp.cov.Matern32(input_dim, lengthscales, active_dims=None)

The Matern kernel with nu = 3/2.

\[k(x, x') = \left(1 + \frac{\sqrt{3(x - x')^2}}{\ell}\right)\mathrm{exp}\left[ - \frac{\sqrt{3(x - x')^2}}{\ell} \right]\]
class pymc3.gp.cov.Linear(input_dim, c, active_dims=None)

The Linear kernel.

\[k(x, x') = (x - c)(x' - c)\]
class pymc3.gp.cov.Polynomial(input_dim, c, d, offset, active_dims=None)

The Polynomial kernel.

\[k(x, x') = [(x - c)(x' - c) + \mathrm{offset}]^{d}\]
class pymc3.gp.cov.Cosine(input_dim, lengthscales, active_dims=None)

The Cosine kernel.

\[k(x, x') = \mathrm{cos}\left( \frac{||x - x'||}{ \ell^2} \right)\]
class pymc3.gp.cov.WarpedInput(input_dim, cov_func, warp_func, args=None, active_dims=None)

Warp the inputs of any kernel using an arbitrary function defined using Theano.

\[k(x, x') = k(w(x), w(x'))\]
Parameters:
  • cov_func (Covariance) –
  • warp_func (callable) – Theano function of X and additional optional arguments.
  • args (optional, tuple or list of scalars or PyMC3 variables) – Additional inputs (besides X or Z) to warp_func.
class pymc3.gp.cov.Gibbs(input_dim, lengthscale_func, args=None, active_dims=None)

The Gibbs kernel. Use an arbitrary lengthscale function defined using Theano. Only tested in one dimension.

\[k(x, x') = \sqrt{\frac{2\ell(x)\ell(x')}{\ell^2(x) + \ell^2(x')}} \mathrm{exp}\left[ -\frac{(x - x')^2}{\ell^2(x) + \ell^2(x')} \right]\]
Parameters:
  • lengthscale_func (callable) – Theano function of X and additional optional arguments.
  • args (optional, tuple or list of scalars or PyMC3 variables) – Additional inputs (besides X or Z) to lengthscale_func.