Skip to main content

Gaussian processes in JAX.

Project description

GPJax's logo

codecov CodeFactor Netlify Status PyPI version DOI Downloads Slack Invite

Quickstart | Install guide | Documentation | Slack Community

GPJax aims to provide a low-level interface to Gaussian process (GP) models in Jax, structured to give researchers maximum flexibility in extending the code to suit their own needs. The idea is that the code should be as close as possible to the maths we write on paper when working with GP models.

Package organisation

Contributions

We would be delighted to receive contributions from interested individuals and groups. To learn how you can get involved, please read our guide for contributing. If you have any questions, we encourage you to open an issue. For broader conversations, such as best GP fitting practices or questions about the mathematics of GPs, we invite you to open a discussion.

Another way you can contribute to GPJax is through issue triaging. This can include reproducing bug reports, asking for vital information such as version numbers and reproduction instructions, or identifying stale issues. If you would like to begin triaging issues, an easy way to get started is to subscribe to GPJax on CodeTriage.

As a contributor to GPJax, you are expected to abide by our code of conduct. If you feel that you have either experienced or witnessed behaviour that violates this standard, then we ask that you report any such behaviours through this form or reach out to one of the project's gardeners.

Feel free to join our Slack Channel, where we can discuss the development of GPJax and broader support for Gaussian process modelling.

Governance

GPJax was founded by Thomas Pinder. Today, the project's gardeners are daniel-dodd@, henrymoss@, st--@, and thomaspinder@, listed in alphabetical order. The full governance structure of GPJax is detailed here. We appreciate all the contributors to GPJax who have helped to shape GPJax into the package it is today.

Supported methods and interfaces

Notebook examples

Guides for customisation

Conversion between .ipynb and .py

Above examples are stored in examples directory in the double percent (py:percent) format. Checkout jupytext using-cli for more info.

  • To convert example.py to example.ipynb, run:
jupytext --to notebook example.py
  • To convert example.ipynb to example.py, run:
jupytext --to py:percent example.ipynb

Simple example

Let us import some dependencies and simulate a toy dataset $\mathcal{D}$.

from jax import config

config.update("jax_enable_x64", True)

import gpjax as gpx
from jax import grad, jit
import jax.numpy as jnp
import jax.random as jr
import optax as ox

key = jr.key(123)

f = lambda x: 10 * jnp.sin(x)

n = 50
x = jr.uniform(key=key, minval=-3.0, maxval=3.0, shape=(n,1)).sort()
y = f(x) + jr.normal(key, shape=(n,1))
D = gpx.Dataset(X=x, y=y)

# Construct the prior
meanf = gpx.mean_functions.Zero()
kernel = gpx.kernels.RBF()
prior = gpx.gps.Prior(mean_function=meanf, kernel = kernel)

# Define a likelihood
likelihood = gpx.likelihoods.Gaussian(num_datapoints = n)

# Construct the posterior
posterior = prior * likelihood

# Define an optimiser
optimiser = ox.adam(learning_rate=1e-2)

# Obtain Type 2 MLEs of the hyperparameters
opt_posterior, history = gpx.fit(
    model=posterior,
    objective=gpx.objectives.conjugate_mll,
    train_data=D,
    optim=optimiser,
    num_iters=500,
    safe=True,
    key=key,
)

# Infer the predictive posterior distribution
xtest = jnp.linspace(-3., 3., 100).reshape(-1, 1)
latent_dist = opt_posterior(xtest, D)
predictive_dist = opt_posterior.likelihood(latent_dist)

# Obtain the predictive mean and standard deviation
pred_mean = predictive_dist.mean()
pred_std = predictive_dist.stddev()

Installation

Stable version

The latest stable version of GPJax can be installed via pip:

pip install gpjax

Note

We recommend you check your installation version:

python -c 'import gpjax; print(gpjax.__version__)'

Development version

Warning

This version is possibly unstable and may contain bugs.

Note

We advise you create virtual environment before installing:

conda create -n gpjax_experimental python=3.10.0
conda activate gpjax_experimental

Clone a copy of the repository to your local machine and run the setup configuration in development mode.

git clone https://github.com/JaxGaussianProcesses/GPJax.git
cd GPJax
hatch env create
hatch shell

We recommend you check your installation passes the supplied unit tests:

hatch run dev:test

Citing GPJax

If you use GPJax in your research, please cite our JOSS paper.

@article{Pinder2022,
  doi = {10.21105/joss.04455},
  url = {https://doi.org/10.21105/joss.04455},
  year = {2022},
  publisher = {The Open Journal},
  volume = {7},
  number = {75},
  pages = {4455},
  author = {Thomas Pinder and Daniel Dodd},
  title = {GPJax: A Gaussian Process Framework in JAX},
  journal = {Journal of Open Source Software}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpjax-0.9.3.tar.gz (9.4 MB view details)

Uploaded Source

Built Distribution

gpjax-0.9.3-py3-none-any.whl (109.5 kB view details)

Uploaded Python 3

File details

Details for the file gpjax-0.9.3.tar.gz.

File metadata

  • Download URL: gpjax-0.9.3.tar.gz
  • Upload date:
  • Size: 9.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for gpjax-0.9.3.tar.gz
Algorithm Hash digest
SHA256 cd08d3f548f7b1fe9d95754a2abef64feb9ea9d1f07e044e6175b279a01765fa
MD5 aed91245a6c60e87a8b08e24531c0210
BLAKE2b-256 29bbf6cd26a76887264027f829d1d34f61c7bc0446eb08f4239bf57fde6e331a

See more details on using hashes here.

File details

Details for the file gpjax-0.9.3-py3-none-any.whl.

File metadata

  • Download URL: gpjax-0.9.3-py3-none-any.whl
  • Upload date:
  • Size: 109.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for gpjax-0.9.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cad082090ed34c3b50347183e1305f4e9b1bfc4e335d329050c9e37303fd0cd0
MD5 5e17a287a0e135580593f110f0f0315b
BLAKE2b-256 f50d7e092182f5381a98cfacb0f4865e19a8a82cb8a056d43459fff38dc72719

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page