From b09ba93cc6f0dcc3514e46a039f3bc43be8aa16f Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Wed, 2 Nov 2022 17:30:01 +0200 Subject: [PATCH 01/11] Resolve issue that broke tests for returning var in spacetime --- bayesnewton/basemodels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bayesnewton/basemodels.py b/bayesnewton/basemodels.py index 8389fb7..af8d40f 100644 --- a/bayesnewton/basemodels.py +++ b/bayesnewton/basemodels.py @@ -757,7 +757,7 @@ def predict(self, X=None, R=None, pseudo_lik_params=None): # if np.squeeze(test_var).ndim > 2: # deal with spatio-temporal case (discard spatial covariance) if self.spatio_temporal: # deal with spatio-temporal case (discard spatial covariance) - test_var = diag(np.squeeze(test_var)) + test_var = diag(test_var) return np.squeeze(test_mean), np.squeeze(test_var) def filter_energy(self): From 0446e4e7114372bc7ffa02d0537576f635fb7ce7 Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Wed, 2 Nov 2022 17:45:39 +0200 Subject: [PATCH 02/11] Details on setting up the environment --- README.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3a1379a..5859007 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bayes-Newton -Bayes-Newton is a library for approximate inference in Gaussian processes (GPs) in [JAX](https://github.com/google/jax) (with [objax](https://github.com/google/objax)), built and actively maintained by [Will Wilkinson](https://wil-j-wil.github.io/). +Bayes-Newton is a library for approximate inference in Gaussian processes (GPs) in [JAX](https://github.com/google/jax) (with [objax](https://github.com/google/objax)), built and maintained by [Will Wilkinson](https://wil-j-wil.github.io/). Bayes-Newton provides a unifying view of approximate Bayesian inference, and allows for the combination of many models (e.g. GPs, sparse GPs, Markov GPs, sparse Markov GPs) with the inference method of your choice (VI, EP, Laplace, Linearisation). For a full list of the methods implemented scroll down to the bottom of this page. @@ -8,11 +8,43 @@ The methodology is outlined in the following article: * W.J. Wilkinson, S. Särkkä, and A. Solin (2021): **Bayes-Newton Methods for Approximate Bayesian Inference with PSD Guarantees**. [*arXiv preprint arXiv:2111.01721*](https://arxiv.org/abs/2111.01721). ## Installation + +Latest (stable) release from PyPI ```bash pip install bayesnewton ``` -## Example +For *development*, you might want to use the latest source from GitHub: In a check-out of the develop branch of the BayesNewton GitHub repository, run +```bash +pip install -e . +``` + +### Step-by-step: Getting started with the examples + +For running the demos or experiments in this repository or building on top of it, you can follow these steps for creating a virtual enivironment and activating it: +```bash +python3 -m venv venv +source venv/bin/activate +``` + +Installing all required dependencies for the examples: +```bash +python -m pip install -r requirements.txt +python -m pip install -e . +``` + +Running the tests requires additionally +```bash +python -m pip install pytest +python -m pip install gpflow==2.5.2 +``` + +Run tests +```bash +pytest tests +``` + +## Simpe Example Given some inputs `x` and some data `y`, you can construct a Bayes-Newton model as follows, ```python kern = bayesnewton.kernels.Matern52() From f774e17b4ac0aff256202d44d47a313b821f6448 Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Wed, 2 Nov 2022 20:36:22 +0200 Subject: [PATCH 03/11] Add numba --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 8389df4..4c87183 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ jax==0.2.9 jaxlib==0.1.60 objax==1.3.1 +numba numpy matplotlib scipy From 3b6d590cf096700e30bffc29189bbb513d027982 Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Tue, 15 Nov 2022 14:09:23 +0200 Subject: [PATCH 04/11] Fix shutters test issues. --- tests/test_vs_gpflow_shutters.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_vs_gpflow_shutters.py b/tests/test_vs_gpflow_shutters.py index 695b79f..627f00b 100644 --- a/tests/test_vs_gpflow_shutters.py +++ b/tests/test_vs_gpflow_shutters.py @@ -168,9 +168,13 @@ def test_gradient_step(var_f, len_f, var_y): loss_fn = gpflow_model.training_loss_closure(data) adam_vars = gpflow_model.trainable_variables adam_opt.minimize(loss_fn, adam_vars) - gpflow_hypers = np.array([gpflow_model.kernel.lengthscales.numpy()[0], - gpflow_model.kernel.lengthscales.numpy()[1], - gpflow_model.kernel.variance.numpy(), + #gpflow_hypers = np.array([gpflow_model.kernel.lengthscales.numpy()[0], + # gpflow_model.kernel.lengthscales.numpy()[1], + # gpflow_model.kernel.variance.numpy(), + # gpflow_model.likelihood.variance.numpy()]) + gpflow_hypers = np.array([gpflow_model.kernel.parameters[0].numpy(), + gpflow_model.kernel.parameters[2].numpy(), + gpflow_model.kernel.parameters[1].numpy(), gpflow_model.likelihood.variance.numpy()]) print(gpflow_hypers) print(gpflow_grads) From bd7e686dcf87e975204cd53e7c793410c44ffe8c Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Tue, 15 Nov 2022 14:27:01 +0200 Subject: [PATCH 05/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5859007..8a4ead3 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Run tests pytest tests ``` -## Simpe Example +## Simple Example Given some inputs `x` and some data `y`, you can construct a Bayes-Newton model as follows, ```python kern = bayesnewton.kernels.Matern52() From 307d9e01772bc377b90935f756dee584b6f07363 Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Wed, 2 Nov 2022 17:30:01 +0200 Subject: [PATCH 06/11] Resolve issue that broke tests for returning var in spacetime --- bayesnewton/basemodels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bayesnewton/basemodels.py b/bayesnewton/basemodels.py index 4104653..cff2fea 100644 --- a/bayesnewton/basemodels.py +++ b/bayesnewton/basemodels.py @@ -813,7 +813,7 @@ def predict(self, X=None, R=None, pseudo_lik_params=None): # if np.squeeze(test_var).ndim > 2: # deal with spatio-temporal case (discard spatial covariance) if self.spatio_temporal: # deal with spatio-temporal case (discard spatial covariance) - test_var = diag(np.squeeze(test_var)) + test_var = diag(test_var) return np.squeeze(test_mean), np.squeeze(test_var) def filter_energy(self): From 0b609108d1ebb6358c1c89f586485af8ecf9b83f Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Wed, 2 Nov 2022 17:45:39 +0200 Subject: [PATCH 07/11] Details on setting up the environment --- README.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3a1379a..5859007 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Bayes-Newton -Bayes-Newton is a library for approximate inference in Gaussian processes (GPs) in [JAX](https://github.com/google/jax) (with [objax](https://github.com/google/objax)), built and actively maintained by [Will Wilkinson](https://wil-j-wil.github.io/). +Bayes-Newton is a library for approximate inference in Gaussian processes (GPs) in [JAX](https://github.com/google/jax) (with [objax](https://github.com/google/objax)), built and maintained by [Will Wilkinson](https://wil-j-wil.github.io/). Bayes-Newton provides a unifying view of approximate Bayesian inference, and allows for the combination of many models (e.g. GPs, sparse GPs, Markov GPs, sparse Markov GPs) with the inference method of your choice (VI, EP, Laplace, Linearisation). For a full list of the methods implemented scroll down to the bottom of this page. @@ -8,11 +8,43 @@ The methodology is outlined in the following article: * W.J. Wilkinson, S. Särkkä, and A. Solin (2021): **Bayes-Newton Methods for Approximate Bayesian Inference with PSD Guarantees**. [*arXiv preprint arXiv:2111.01721*](https://arxiv.org/abs/2111.01721). ## Installation + +Latest (stable) release from PyPI ```bash pip install bayesnewton ``` -## Example +For *development*, you might want to use the latest source from GitHub: In a check-out of the develop branch of the BayesNewton GitHub repository, run +```bash +pip install -e . +``` + +### Step-by-step: Getting started with the examples + +For running the demos or experiments in this repository or building on top of it, you can follow these steps for creating a virtual enivironment and activating it: +```bash +python3 -m venv venv +source venv/bin/activate +``` + +Installing all required dependencies for the examples: +```bash +python -m pip install -r requirements.txt +python -m pip install -e . +``` + +Running the tests requires additionally +```bash +python -m pip install pytest +python -m pip install gpflow==2.5.2 +``` + +Run tests +```bash +pytest tests +``` + +## Simpe Example Given some inputs `x` and some data `y`, you can construct a Bayes-Newton model as follows, ```python kern = bayesnewton.kernels.Matern52() From 247da3f46246418fd7e3b4ef9a75a4f6dcf9be89 Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Wed, 2 Nov 2022 20:36:22 +0200 Subject: [PATCH 08/11] Add numba --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 8389df4..4c87183 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ jax==0.2.9 jaxlib==0.1.60 objax==1.3.1 +numba numpy matplotlib scipy From 25cbb569f2a9854d6e825e6278c2f54b304f845c Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Tue, 15 Nov 2022 14:09:23 +0200 Subject: [PATCH 09/11] Fix shutters test issues. --- tests/test_vs_gpflow_shutters.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_vs_gpflow_shutters.py b/tests/test_vs_gpflow_shutters.py index 695b79f..627f00b 100644 --- a/tests/test_vs_gpflow_shutters.py +++ b/tests/test_vs_gpflow_shutters.py @@ -168,9 +168,13 @@ def test_gradient_step(var_f, len_f, var_y): loss_fn = gpflow_model.training_loss_closure(data) adam_vars = gpflow_model.trainable_variables adam_opt.minimize(loss_fn, adam_vars) - gpflow_hypers = np.array([gpflow_model.kernel.lengthscales.numpy()[0], - gpflow_model.kernel.lengthscales.numpy()[1], - gpflow_model.kernel.variance.numpy(), + #gpflow_hypers = np.array([gpflow_model.kernel.lengthscales.numpy()[0], + # gpflow_model.kernel.lengthscales.numpy()[1], + # gpflow_model.kernel.variance.numpy(), + # gpflow_model.likelihood.variance.numpy()]) + gpflow_hypers = np.array([gpflow_model.kernel.parameters[0].numpy(), + gpflow_model.kernel.parameters[2].numpy(), + gpflow_model.kernel.parameters[1].numpy(), gpflow_model.likelihood.variance.numpy()]) print(gpflow_hypers) print(gpflow_grads) From cc800066d047525bcab16e402432397922f940cb Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Tue, 15 Nov 2022 14:27:01 +0200 Subject: [PATCH 10/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5859007..8a4ead3 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Run tests pytest tests ``` -## Simpe Example +## Simple Example Given some inputs `x` and some data `y`, you can construct a Bayes-Newton model as follows, ```python kern = bayesnewton.kernels.Matern52() From 96a0dc908d1016ece642c9fe1d86151888aa2d11 Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Fri, 25 Nov 2022 16:49:05 +0200 Subject: [PATCH 11/11] Update README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8a4ead3..dc860f2 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ pip install -e . ### Step-by-step: Getting started with the examples -For running the demos or experiments in this repository or building on top of it, you can follow these steps for creating a virtual enivironment and activating it: +For running the demos or experiments in this repository or building on top of it, you can follow these steps for creating a virtual environment and activating it: ```bash python3 -m venv venv source venv/bin/activate @@ -33,15 +33,15 @@ python -m pip install -r requirements.txt python -m pip install -e . ``` -Running the tests requires additionally +Running the tests requires additionally a specific version of GPflow to test against: ```bash python -m pip install pytest -python -m pip install gpflow==2.5.2 +python -m pip install tensorflow==2.10 tensorflow-probability==0.18.0 gpflow==2.5.2 ``` Run tests ```bash -pytest tests +cd tests; pytest ``` ## Simple Example