AbstractGPs.jl is a package that defines a low-level API for working with Gaussian processes (GPs), and basic functionality for working with them in the simplest cases. As such it is aimed more at developers and researchers who are interested in using it as a building block than end-users of GPs.
using AbstractGPs, KernelFunctions, Random
rng = MersenneTwister(0)
# Construct a zero-mean Gaussian process with a matern-3/2 kernel.
f = GP(Matern32Kernel())
# Specify some input and target locations.
x = randn(rng, 10)
y = randn(rng, 10)
Look at the finite-dimensional projection of f
at x
, under zero-mean observation noise with variance 0.1
.
fx = f(x, 0.1)
y_sampled = rand(rng, fx)
logpdf(fx, y)
f_posterior = posterior(fx, y)
A posterior process follows the AbstractGP
interface, so the same functions which work on the posterior as on the prior.
rand(rng, f_posterior(x))
logpdf(f_posterior(x), y)
Here, z is a set of pseudo-points.
z = randn(rng, 4)
u = f(z)
We provide a ready implentation of elbo w.r.t to the pseudo points. We can perform Variational Inference on pseudo-points by maximizing the ELBO term w.r.t pseudo-points z
and any kernel parameters. For more information, see examples.
elbo(fx, y, u)
The optimal pseudo-points obtained above can be used to create a approximate/sparse posterior. This can be used like a regular posterior in many cases.
f_approx_posterior = approx_posterior(VFE(), fx, y, u)
marginals(f_approx_posterior(x))
Sequential conditioning allows you to compute your posterior in an online fashion. We do this in an efficient manner by updating the cholesky factorisation of the covariance matrix and avoiding recomputing it from original covariance matrix.
# Define GP prior
f = GP(SqExponentialKernel())
# Generate posterior with the first batch of data on the prior f1.
p_fx = posterior(f(x[1:3], 0.1), y[1:3])
# Generate posterior with the second batch of data considering posterior p_fx1 as the prior.
p_p_fx = posterior(p_fx(x[4:10], 0.1), y[4:10])
Z1 = rand(rng, 4)
Z2 = rand(rng, 3)
p_fx = approx_posterior(VFE(), f(x[1:7], 0.1), y[1:7], f(Z))
u_p_fx = update_approx_posterior(p_fx1, f(x[8:10], 0.1), y[8:10])
p_fx1 = approx_posterior(VFE(), f(X, 0.1), y, f(Z1))
u_p_fx1 = update_approx_posterior(p_fx1, f(Z2))