A Python Package offering geometric kernels in NumPy, TensorFlow, PyTorch, and Jax.
Project description
GeometricKernels
GeometricKernels is a library that implements kernels — most importantly, heat and Matérn kernels — on non-Euclidean spaces such as Riemannian manifolds, graphs and meshes. This enables kernel methods — in particular Gaussian process models — to be deployed on such spaces.
Installation
-
[Optionally] create and activate a new virtual environment.
You can use uv
uv venvor conda
conda create -n [env_name] python=3.[version] conda activate [env_name]
or virtualenv
virtualenv [env_name] source [env_name]/bin/activate
-
Install the library in the active environment by running
pip install geometric_kernels
NOTE: If you use
uv, swappipwithuv pipeverywhere. If you initialized a project withuv init, useuv addinstead.If you want to install specific GitHub branch called
[branch], runpip install "git+https://github.com/geometric-kernels/GeometricKernels@[branch]"
-
Install a backend of your choice
We use LAB to support multiple backends (e.g., TensorFlow, Jax, PyTorch). However, you are not required to install all of them on your system to use the GeometricKernels package. Simply install the backend (and (optionally) a GP package) of your choice. For example,
-
pip install tensorflow tensorflow-probabilityOptionally, you can install the Tensorflow-based Gaussian processes library GPflow, for which we provide a frontend.
pip install gpflow -
pip install torchOptionally, you can install the PyTorch-based Gaussian processes library GPyTorch, for which we provide a frontend.
pip install gpytorch -
JAX (the cpu version)—the gpu and tpu versions can be installed similarly.
pip install "jax[cpu]"Optionally, you can install the JAX-based Gaussian processes library GPJax, for which we provide a frontend.
pip install gpjax
-
A basic example
This example shows how to compute a 3x3 kernel matrix for the Matern52 kernel on the standard two-dimensional sphere. It relies on the numpy-based backend. Look up the information on how to use other backends in the documentation.
# Import a backend.
import numpy as np
# Import the geometric_kernels backend.
import geometric_kernels
# Import a space and an appropriate kernel.
from geometric_kernels.spaces import Hypersphere
from geometric_kernels.kernels import MaternGeometricKernel
# Create a manifold (2-dim sphere).
hypersphere = Hypersphere(dim=2)
# Define 3 points on the sphere.
xs = np.array([[0., 0., 1.], [0., 1., 0.], [1., 0., 0.]])
# Initialize kernel.
kernel = MaternGeometricKernel(hypersphere)
params = kernel.init_params()
params["nu"] = np.array([5/2])
params["lengthscale"] = np.array([1.])
# Compute and print out the 3x3 kernel matrix.
print(np.around(kernel.K(params, xs), 2))
This should output
[[1. 0.36 0.36]
[0.36 1. 0.36]
[0.36 0.36 1. ]]
Notebooks
You can find numerous example notebooks for GeometricKernels here in the docs or here in the tree. These cover every space (e.g., sphere, graph), backend (e.g., Torch, JAX), frontend (e.g., GPyTorch, GPflow), and more.
Application Examples
Looking for practical use cases of GeometricKernels? Check out
-
PeMS Regression: A benchmark suite for graph node regression with uncertainty. This project employs GeometricKernels among other tools, and offers processed data, baseline models, and an example notebook for experiments on graph-structured data. Notably, in this benchmark, geometric Gaussian processes built with GeometricKernels have been shown to outperform various alternative methods, including ensembles of graph neural networks and Bayesian graph neural networks.
-
Bayesian optimization demonstration: A minimal notebook illustrating the use of GeometricKernels with the
botorchlibrary for Bayesian optimization. This is a simple, self-contained example designed to demonstrate core concepts rather than to reflect a real-world scenario.
Documentation
The documentation for GeometricKernels is available on a separate website.
For development and running the tests
If you want to contribute to the library, thank you! Here you can find a good example of a pull request to GeometricKernels.
You can follow the instructions bellow to set up the environment and run the tests and the code formatting.
Initialize the virtual environment.
make venv
You can change the python version and the venv directory like this:
make venv UV_PYTHON=3.11 VENV_DIR=.venv
NOTE: We use uv for development. It is not strictly necessary, and if you don't want to use it, you can still run make lint and make test if you set UV_RUN= to be empty. You will need to set up the environment yourself.
Install all backends and the dev requirements (Pytest, black, etc.). This will install all the backends.
make install
NOTE: If not using uv, you can still install the dev requirements via pip install -e .[dev].
Run the style checks
make lint
Run the tests
make test
If you want to run Jupyter with your uv development environment, check out this page.
Example: If you want to learn how to implement your own space or kernel component, checkout the CustomSpacesAndKernels.ipynb notebook.
If you have a question
Post it in issues using the "How do I do ..." and other issues template and the "question" label.
This link chooses the right template and label for you.
Citation
If you are using GeometricKernels, please cite the following paper:
@article{JMLR:v26:24-1185,
author = {Peter Mostowsky and Vincent Dutordoir and Iskander Azangulov and No{\'e}mie Jaquier and Michael John Hutchinson and Aditya Ravuri and Leonel Rozo and Alexander Terenin and Viacheslav Borovitskiy},
title = {The GeometricKernels Package: Heat and Mat{\'e}rn Kernels for Geometric Learning on Manifolds, Meshes, and Graphs},
journal = {Journal of Machine Learning Research},
year = {2025},
volume = {26},
number = {276},
pages = {1--14},
url = {http://jmlr.org/papers/v26/24-1185.html}
}
Furthermore, please consider citing the theoretical papers the package is based on. You can find the relevant references for any space in
- the docstring of the respective space class,
- at the end of the respective tutorial notebook.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geometric_kernels-1.0.0.tar.gz.
File metadata
- Download URL: geometric_kernels-1.0.0.tar.gz
- Upload date:
- Size: 7.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c77adc9bf363181b9731202122a6e41fdd7e324fd8c092216d7ff26a8d5ed315
|
|
| MD5 |
dfd3a357f3656c0cd2631948883c9869
|
|
| BLAKE2b-256 |
e266402e1f43b0955d54bfa767cd05e24b86442641d328b8aa647c1f6bb81007
|
File details
Details for the file geometric_kernels-1.0.0-py3-none-any.whl.
File metadata
- Download URL: geometric_kernels-1.0.0-py3-none-any.whl
- Upload date:
- Size: 174.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b81abaa48bcea427fb6c72ad7e7c0c89b78e901b5747b2b1be42d71f2f9076a3
|
|
| MD5 |
76ebf1e12ae764cbe23eb0502d12ee26
|
|
| BLAKE2b-256 |
35aeb489ca47a64d7fcac72004e1b3d993ab14cf5ca57551731335a5e3fc67c8
|