gptools: Performant Gaussian Processes in Stan

Gaussian processes (GPs) are powerful distributions for modeling functional data, but using them is computationally challenging except for small datasets. gptools implements two methods for performant GP inference in Stan.
- A sparse approximation of the likelihood. This approach includes nearest neighbor Gaussian processes but also supports more general dependence structures, e.g., for periodic kernels.
- An exact likelihood evaluation for data on regularly spaced lattices using fast Fourier transforms.
The implementation follows Stan’s design and exposes performant inference through a familiar interface. We provide interfaces in Python and R. See the accompanying publication Scalable Gaussian Process Inference with Stan for details of the implementation. The comprehensive documentation includes many examples.
You can use the gptools package by including it the functions
block of your Stan program, e.g.,
functions {
// Include utility functions, such as real fast Fourier transforms.
#include gptools/util.stan
// Include functions to evaluate GP likelihoods with Fourier methods.
#include gptools/fft.stan
}
See here for the list of all include options. You can download the Stan files and use them with your favorite interface or use the provided Python and R interfaces.
- Install cmdstanpy and cmdstan if you haven't already (see here for details).
- Install gptools from PyPI by running
pip install gptools-stan
from the command line. - Compile your first model.
from cmdstanpy import CmdStanModel
from gptools.stan import get_include
model = CmdStanModel(
stan_file="path/to/your/model.stan",
stanc_options={"include-paths": get_include()},
)
For an end-to-end example, see this notebook.
- Install cmdstanr and cmdstan if you haven't already (see here for details).
- Install gptools from CRAN by running
install.packages("gptoolsStan")
. - Compile your first model.
library(cmdstanr)
library(gptoolsStan)
model <- cmdstan_model(
stan_file="path/to/your/model.stan",
include_paths=gptools_include_path(),
)
Note
Unfortunately, Rstan is not supported because it does not provide an option to specify include paths.
For an end-to-end example, see this vignette.
Contributions to the package are always welcome! The repository structure is as follows:
stan/gptools
contains the core implementation of gptools.python/stan
contains the Python wrapper for gptools.R
contains the R wrapper for gptools.docs
contains the documentation hosted at https://gptools-stan.readthedocs.io.
To replicate the results presented in the accompanying publication Scalable Gaussian Process Inference with Stan, please see the dedicated repository of replication materials.