Package: gptools-stan
Gaussian processes (GPs) are flexible distributions to model functional data. Whilst theoretically appealing, they are computationally cumbersome except for small datasets. This package implements two methods for scaling GP inference inStan:asparse-approximationof the likelihood that is generally applicable.an exact method for regularly spaced data modeled by stationary kernels using fastFourier-methods.The implementation followsStan’s design and exposes performant inference through a familiar interface.Getting StartedThe library is loaded withStan’s#includestatement, and methods to evaluate or approximate the likelihood of a GP use the declarative~sampling syntax. The following brief example usesFourier-methodsto sample GP realizations.You can learn more by following thedocs/examplesor delving into thedocs/interface. Thedocs/backgroundsection offers a deeper explanation of the methods used to evaluate likelihoods and the pros and cons of different parameterizations. See theaccompanying publication “Scalable Gaussian process inference with Stan”for further details.InstallationIf you have a recent python installation, the library can be installed by runningpipinstallgptools-stanfrom the command line. The library exposes a functiongptools.stan.compile_modelfor compilingcmdstanpy.CmdStanModels with the correct include paths. For example, the example above can be compiled using the following snippet.>>> from gptools.stan import compile_model
>>>
>>> # stan_file = path/to/getting_started.stan
>>> model = compile_model(stan_file=stan_file)
>>> model.name
'getting_started'If you usecmdstanror anotherStaninterface, you can download thelibrary files from GitHub. Then add the library location to the compilerinclude_pathsasdescribed in the manual(seeherefor cmdstanr instructions).Reproducing results from the accompanying publicationTheaccompanying publication “Scalable Gaussian process inference with Stan”provides theoretical background and a technical description of the methods. All results and figures can be reproduced using one of the approaches below.Docker runtimeDockercan run software in isolated containers. If you have docker installed, you can reproduce the results by runningdockerrun--rmtillahoffmann/gptools-v/path/to/output/directory:/workspacedoit--db-file=/workspace/.doit.dbresults:stanThis command will download a prebuilt docker image and execute the steps required to generate all figures in the publication. Results will be placed in the specified output directory; make sure the directory exists before executing the command and that the specified path is an absolute, e.g.,/path/to/...instead of../path/to/.... You do not need to install any other software or download the source code. Intermediate results are cached if the process is interrupted, and the process can pick up where it left off when invoked using the same command. Your timing results are likely to differ from the results reported in the publication because runtimes vary substantially between different machines. All results reported in the manuscript were obtained on a 2020 Macbook Pro with M1 Apple Silicon chip and 16 GB of memory. Cross-architecture images are built followingthis guide.Reproducing the results can be time intensive, especially to generate the data for the profiling figure. You can add the-e CI=1flag to the above command. This will reduce the number of samples drawn per run and decrease timeouts to speed up the process although at the cost of more noisy and possibly incomplete figures.If you would rather build the docker image from scratch, rundocker build -t my-image-name .from the root directory of this repository. You can then reproduce the results using the command above, replacingtillahoffmann/gptoolswithmy-image-name. Optionally, rundocker run --rm gptools doit tests:stanto ensure the image runs as expected; this takes about ten to fifteen minutes on a Macbook.Local runtimeYou can reproduce the results using your local computing environment (rather than an isolated container runtime) as follows.Ensure a recent python version (3.8 or later) is installed. The code was tested with python 3.8-3.11 on Ubuntu 22.04.2 and python 3.10 on macOS 13.2.1.Install all dependencies by runningpip install -r dev_requirements.txt.Installcmdstanby runninginstall_cmdstan --version=2.31.0.Optionally, rundoit tests:stanto test the installation.Optionally, launch aJupyter notebookand open thedocs/logistic_regression/logistic_regressionnotebook to get familiar with the package. The notebook illustrates fitting a univariate latent Gaussian process to binary observations. TheMyST markdownnotebook is located atdocs/logistic_regression/logistic_regression.mdin this repository.Run the commanddoit results:stanto reproduce the results.