Giter Club home page Giter Club logo

gpax's Introduction

GPax

build notebooks codecov Documentation Status PyPI version

GPax is a small Python package for physics-based Gaussian processes (GPs) built on top of NumPyro and JAX. Its purpose is to take advantage of prior physical knowledge and different data modalities when using GPs for data reconstruction and active learning. It is a work in progress, and more models will be added in the near future.

GPax_logo

How to use

Simple GP

1D Example

Open In Colab

The code snippet below shows how to use vanilla GP in a fully Bayesian mode. First, we infer GP model parameters from the available training data

import gpax

# Get random number generator keys for training and prediction
rng_key, rng_key_predict = gpax.utils.get_keys()
# Initialize model
gp_model = gpax.ExactGP(1, kernel='RBF')
# Run Hamiltonian Monte Carlo to obtain posterior samples for the GP model parameters
gp_model.fit(rng_key, X, y)  # X and y are numpy arrays with dimensions (n, d) and (n,)

In the fully Bayesian mode, we get a pair of predictive mean and covariance for each Hamiltonian Monte Carlo sample containing the GP parameters (in this case, the RBF kernel hyperparameters and model noise). Hence, a prediction on new inputs with a trained GP model returns the center of the mass of all the predictive means (posterior_mean) and samples from multivariate normal distributions for all the pairs of predictive means and covariances (f_samples).

posterior_mean, f_samples = gp_model.predict(rng_key_predict, X_test)

For 1-dimensional data, we can plot the GP prediction using the standard approach where the uncertainty in predictions - represented by a standard deviation in y_sampled - is depicted as a shaded area around the mean value.

See the full example, including specification of custom GP kernel priors, here.

Sparse Image Reconstruction

Open In Colab

One can also use GP for sparse image reconstruction. The fully Bayesian GP is typically too slow for this purpose and it makes sense to use a stochastic variational inference approximation (viGP) instead. Code-wise, the usage of viGP in GPax is almost the same as that of the fully Bayesian GP. One difference is that instead of num_samples we have num_steps. We can also control the learning rate by specifying a step_size.

# Get training inputs/targets and full image indices from sparse image data
X_train, y_train, X_full = gpax.utils.preprocess_sparse_image(sparse_img) # sparse_img is a 2D numpy array

# Initialize and train a variational inference GP model
gp_model = gpax.viGP(2, kernel='Matern', guide='delta')
gp_model.fit(rng_key, X_train, y_train, num_steps=250, step_size=0.05)

When we run the .predict() method, the output is predictive mean and variance computed from a learned single estimate of the GP model parameters:

y_pred, y_var = gp_model.predict(rng_key_predict, X_full)

viGP

Finally, for larger images or hyperspecteral data, one can use the inducing inputs approximation to GP, which is also available in GPax. See the full example here.

Structured GP

Open In Colab

The limitation of the standard GP is that it does not usually allow for the incorporation of prior domain knowledge and can be biased toward a trivial interpolative solution. Recently, we introduced a structured Gaussian Process (sGP), where a classical GP is augmented by a structured probabilistic model of the expected system’s behavior. This approach allows us to balance the flexibility of the non-parametric GP approach with a rigid structure of prior (physical) knowledge encoded into the parametric model. Implementation-wise, we substitute a constant/zero prior mean function in GP with a probabilistic model of the expected system's behavior.

For example, if we have prior knowledge that our objective function has a discontinuous 'phase transition', and a power law-like behavior before and after this transition, we may express it using a simple piecewise function

import jax.numpy as jnp

def piecewise(x: jnp.ndarray, params: Dict[str, float]) -> jnp.ndarray:
    """Power-law behavior before and after the transition"""
    return jnp.piecewise(
        x, [x < params["t"], x >= params["t"]],
        [lambda x: x**params["beta1"], lambda x: x**params["beta2"]])

where jnp corresponds to jax.numpy module. This function is deterministic. To make it probabilistic, we put priors over its parameters with the help of NumPyro

import numpyro
from numpyro import distributions

def piecewise_priors():
    # Sample model parameters
    t = numpyro.sample("t", distributions.Uniform(0.5, 2.5))
    beta1 = numpyro.sample("beta1", distributions.Normal(3, 1))
    beta2 = numpyro.sample("beta2", distributions.Normal(3, 1))
    # Return sampled parameters as a dictionary
    return {"t": t, "beta1": beta1, "beta2": beta2}

Finally, we train the sGP model and make predictions on new data in the almost exact same way we did for vanilla GP. The only difference is that we pass our structured probabilistic model as two new arguments (the piecewise function and the corresponding priors over its parameters) when initializing GP.

# Get random number generator keys
rng_key, rng_key_predict = gpax.utils.get_keys()
# initialize structured GP model
sgp_model = gpax.ExactGP(1, kernel='Matern', mean_fn=piecewise, mean_fn_prior=piecewise_priors)
# Run MCMC to obtain posterior samples
sgp_model.fit(rng_key, X, y)
# Get GP prediction on new/test data
posterior_mean, f_samples = sgp_model.predict(rng_key_predict, X_test)

GP_vs_sGP2

Structured GP is usually better at extrapolation and provides more reasonable uncertainty estimates. The probabilistic model in structured GP reflects our prior knowledge about the system, but it does not have to be precise, that is, the model can have a different functional form, as long as it captures general or partial trends in the data. The full example including the active learning part is available here.

Active learning and Bayesian optimization

Open In Colab

Both GP and sGP can be used for active learning to reconstruct the entire data distribution from sparse observations or to localize regions of the parameter space where a particular physical behavior is maximized or minimized with as few measurements as possible (the latter is usually referred to as Bayesian optimization).

# Train a GP model (it can be sGP or vanilla GP)
gp_model.fit(rng_key, X_measured, y_measured)  # A

# Compute the upper confidence bound (UCB) acquisition function to derive the next measurement point
acq = gpax.acquisition.UCB(rng_key_predict, gp_model, X_unmeasured, beta=4, maximize=False, noiseless=True)  # B
next_point_idx = acq.argmax()  # C
next_point = X_unmeasured[next_point_idx]  # D

# Perform measurement in next_point, update measured & unmeasured data arrays, and re-run steps A-D.

In the figure below we illustrate the connection between the (s)GP posterior predictive distribution and the acquisition function used to derive the next measurement points. Here, the posterior mean values indicate that the minimum of a "black box" function describing a behavior of interest is around $x=0.7$. At the same time, there is a large dispersion in the samples from the posterior predictive distribution between $x=-0.5$ and $x=0.5$, resulting in high uncertainty in that region. The acquisition function is computed as a function of both predictive mean and uncertainty and its maximum corresponds to the next measurement point in the active learning and Bayesian optimization. Here, after taking into account the uncertainty in the prediction, the UCB acquisition function suggests exploring a point at x≈0 where potentially a true minimum is located. See full example here.

Theory-informed data reconstruction and Bayesian optimization

Open In Colab

Sometimes when theoretical simulations are available before the experiment, they can be used to guide the measurements or simply reconstruct sparse data via a multi-task/fidelity Gaussian process. This can be used as an alternative solution to a structured Gaussian process in situations where a mean function is too costly to compute at each step or it is expressed through some complex program that is not fully differentiable. The overall scheme is the same, but now our GP model is a MultitaskGP:

key1, key2 = gpax.utils.get_keys(1)

gp_model = gpax.MultiTaskGP(
    input_dim=1, data_kernel='Matern',  # standard GP parameters
    shared_input_space=False,  # different tasks/fidelities have different numbers of observations
    num_latents=2, rank=2,  # parameters of multi-task GP
)

model.fit(key1, X, y, num_warmup=500, num_samples=500)

Note that X has (N, D+1) dimensions where the last column contains task/fidelity indices for each observation. We can then use the trained model to make a prediction for partially observed data:

# Create a set of inputs for the task/fidelity 2
X_unmeasured2 = np.column_stack((X_full_range, np.ones_like(X_full_range)))

# Make a prediction with the trained model
posterior_mean2, f_samples2  = model.predict(key2, X_unmeasured2, noiseless=True)

GP_vs_MTGP The full example including Bayesian optimization is available here

Hypothesis learning

Open In Colab

The structured GP can also be used for hypothesis learning in automated experiments. The hypothesis learning is based on the idea that in active learning, the correct model of the system’s behavior leads to a faster decrease in the overall Bayesian uncertainty about the system under study. In the hypothesis learning setup, probabilistic models of the possible system’s behaviors (hypotheses) are wrapped into structured GPs, and a basic reinforcement learning policy is used to select a correct model from several competing hypotheses. The example of hypothesis learning on toy data is available here.

Deep kernel learning

Open In Colab

Deep kernel learning (DKL) can be understood as a hybrid of deep neural network (DNN) and GP. The DNN serves as a feature extractor that allows reducing the complex high-dimensional features to low-dimensional descriptors on which a standard GP kernel operates. The parameters of DNN and of GP kernel are inferred jointly in an end-to-end fashion. Practically, the DKL training inputs are usually patches from an (easy-to-acquire) structural image, and training targets represent a physical property of interest derived from the (hard-to-acquire) spectra measured in those patches. The DKL output on the new inputs (image patches for which there are no measured spectra) is the expected property value and associated uncertainty, which can be used to derive the next measurement point in the automated experiment.

GPax package has the fully Bayesian DKL (weights of neural network and GP hyperparameters are inferred using Hamiltonian Monte Carlo) and the Variational Inference approximation of DKL, viDKL. The fully Bayesian DKL can provide an asymptotically exact solution but is too slow for most automated experiments. Hence, for the latter, one may use the viDKL

import gpax

# Get random number generator keys for training and prediction
rng_key, rng_key_predict = gpax.utils.get_keys()

# Obtain/update DKL posterior; input data dimensions are (n, h*w*c)
dkl = gpax.viDKL(input_dim=X.shape[-1], z_dim=2, kernel='RBF')  # A
dkl.fit(rng_key, X_train, y_train, num_steps=100, step_size=0.05)  # B

# Compute UCB acquisition function
obj = gpax.acquisition.UCB(rng_key_predict, dkl, X_unmeasured, maximize=True)  # C
# Select next point to measure (assuming grid data)
next_point_idx = obj.argmax()  # D

# Perform measurement in next_point_idx, update measured & unmeasured data arrays, and re-run steps A-D.

Below we show a result of a simple DKL-based search for regions of the nano-plasmonic array that host edge plasmons. The full example is available here.

Note that in viDKL, we use a simple MLP as a default feature extractor. However, you can easily write a custom DNN using haiku and pass it to the viDKL initializer

import haiku as hk

class ConvNet(hk.Module):
    def __init__(self, embedim=2):
        super().__init__()
        self._embedim = embedim   

    def __call__(self, x):
        x = hk.Conv2D(32, 3)(x)
        x = jax.nn.relu(x)
        x = hk.MaxPool(2, 2, 'SAME')(x)
        x = hk.Conv2D(64, 3)(x)
        x = jax.nn.relu(x)
        x = hk.Flatten()(x)
        x = hk.Linear(self._embedim)(x)
        return x

dkl = gpax.viDKL(X.shape[1:], 2, kernel='RBF', nn=ConvNet)  # input data dimensions are (n,h,w,c)
dkl.fit(rng_key, X_train, y_train, num_steps=100, step_size=0.05)
obj = gpax.acquisition.UCB(rng_key_predict, dkl, X_unmeasured, maximize=True)
next_point_idx = obj.argmax()

Installation

If you would like to utilize a GPU acceleration, follow these instructions to install JAX with a GPU support.

Then, install GPax using pip. We recommend installing the latest stable deployment from PyPI using

pip install gpax

Otherwise, if you are confident in what's on the main branch of GPax, you can also install directly from the GitHub repository:

pip install git+https://github.com/ziatdinovmax/gpax

If you are a Windows user, we recommend to use the Windows Subsystem for Linux (WSL2), which comes free on Windows 10 and 11.

Cite us

If you use GPax in your work, please consider citing our papers:

@article{ziatdinov2021physics,
  title={Physics makes the difference: Bayesian optimization and active learning via augmented Gaussian process},
  author={Ziatdinov, Maxim and Ghosh, Ayana and Kalinin, Sergei V},
  journal={arXiv preprint arXiv:2108.10280},
  year={2021}
}

@article{ziatdinov2021hypothesis,
  title={Hypothesis learning in an automated experiment: application to combinatorial materials libraries},
  author={Ziatdinov, Maxim and Liu, Yongtao and Morozovska, Anna N and Eliseev, Eugene A and Zhang, Xiaohang and Takeuchi, Ichiro and Kalinin, Sergei V},
  journal={arXiv preprint arXiv:2112.06649},
  year={2021}
}

Funding acknowledgment

This work was supported by the U.S. Department of Energy, Office of Science, Basic Energy Sciences Program.

gpax's People

Contributors

aghosh92 avatar arpanbiswas52 avatar matthewcarbone avatar sagarsadhu avatar ziatdinovmax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gpax's Issues

Open discussions?

Suggestion: open the discussions tab (in settings, I think) so I (and others) don't have to spam the issues with questions 😁

Quality-of-life suggestions for release, CI, semantic versioning, etc.

Discussed in #56

Originally posted by matthewcarbone October 4, 2023
@ziatdinovmax I have a couple of suggestions for your consideration:

  • Pool all setup protocol into pyproject.toml. PEP 621 began the transition of Python setup to the "non-python" pyproject file. In GPax, the setup.py file is not necessary. We can pool all build instructions into the pyproject.toml file.
  • CI code can be slightly refactored for clarity.
  • Similarly, I have developed a procedure for on-the-fly semantic versioning from tags, similar to the old versioneer.py method, but my method is a few lines and relies on dunamai to grab the current HEAD's tag. I use this combined with "API-key-free" publishing to PyPI, my CI procedure, and GH environments to securely publish any new tagged release. The environment configuration requires manual confirmation before any release, in case you were worried about over-automation causing unintended things to happen. EDIT: there is a better way to do this using hatchling. See here.
  • Implement dependabot for automatic version bumps, and version-lock all dependencies. I think this is just good practice to ensure your code works even if a dependency releases an update that should be backwards compatible, but isn't. Example of that here.

The most recent example I have of all of this can be found here, with a slightly less recent example here.

I am more than happy to implement these QOL changes.

Is it possible to filter nans for ExactGP.predict inside UCB Acquisition functions calls?

Sometimes the gpax.acquisition.UCB returns Nans. This is may be due to the ExactGP.predict returning nans for some samples?

See the below plot (UCB is not present as the array is full of nans)
Screen Shot 2023-08-23 at 3 34 26 pm

Changing the random seed for data generation:
Screen Shot 2023-08-23 at 3 35 38 pm

Code to reproduce nans

import gpax
import numpy as np
import matplotlib.pyplot as plt
import numpyro

gpax.utils.enable_x64()
SEED = 1
N_OBS = 6
X_RANGE = (-2, 5)

np.random.seed(SEED)


def observations(x, noise_sigma=0.05):
    noise = np.random.normal(0, noise_sigma, len(x))
    f = 1 / (x ** 2 + 1) * np.cos(np.pi * x)
    return f + noise


def generate_data():
    X_measured = np.random.uniform(*X_RANGE, N_OBS)
    X_unmeasured = np.linspace(*X_RANGE, 50)
    y_measured = observations(X_measured)
    y_true = observations(X_unmeasured, noise_sigma=0)
    return X_measured, y_measured, X_unmeasured, y_true


def get_gp_preds(X_measured, y_measured, X_unmeasured):
    rng_key1, rng_key2 = gpax.utils.get_keys(SEED)
    noise_prior = numpyro.distributions.Normal(1)
    gp_model = gpax.ExactGP(1, kernel='RBF', noise_prior_dist=noise_prior)
    gp_model.fit(rng_key1, X_measured, y_measured)

    y_pred, y_sampled = gp_model.predict(rng_key2, X_unmeasured, noiseless=True)
    y_up = np.nanquantile(y_sampled, 0.95, axis=0).ravel()
    y_low = np.nanquantile(y_sampled, 0.05, axis=0).ravel()
    ucb_values = gpax.acquisition.UCB(
        rng_key2, gp_model, X_unmeasured, beta=4,
        maximize=False, noiseless=True)

    return y_pred, y_up, y_low, ucb_values


def plot(X_measured, y_measured, X_unmeasured, y_true, y_pred, y_up, y_low, ucb_values):
    fig, ax = plt.subplots(1, 1, figsize=(4, 3))
    ax.plot(X_unmeasured, y_true, lw=3, ls='--', c='k', label='True', alpha=0.1)
    ax.scatter(X_measured, y_measured, c='k', label="Observations")
    ax.plot(X_unmeasured, y_pred, lw=2, c='tab:orange', label='Model')
    ax.fill_between(X_unmeasured, y_low, y_up, color='tab:orange', alpha=0.3)
    ax2 = ax.twinx()
    ax2.plot(X_unmeasured, ucb_values, lw=1.5, color='tab:purple', alpha=0.9, zorder=-100)
    ax.plot([], [], lw=1.5, color='tab:purple', alpha=0.9, zorder=-100, label='UCB')
    ax.legend(frameon=True)
    ax.set_xlim(X_RANGE)
    ax2.set_yticks([])
    fig.show()


def main():
    X_measured, y_measured, X_unmeasured, y_true = generate_data()
    y_pred, y_up, y_low, ucb_values = get_gp_preds(
        X_measured, y_measured, X_unmeasured
    )
    plot(
        X_measured, y_measured, X_unmeasured, y_true,
        y_pred, y_up, y_low, ucb_values
    )

    print(f"X_measured = {X_measured.tolist()}")
    print(f"y_measured = {y_measured.tolist()}")
    print(f"X_unmeasured = {X_unmeasured.tolist()}")


if __name__ == '__main__':
    main()

Data:


X_measured = [0.9191540329180179, 3.042271454095107, -1.9991993762785858, 0.1163280084228786, -0.9727087642802088, -1.3536298366184154]
y_measured = [-0.5510701474083296, -0.150299323805448, 0.24339790464416963, 0.8064144297202153, -0.42470373051379506, -0.19475225108675304]
X_unmeasured = [-2.0, -1.8571428571428572, -1.7142857142857144, -1.5714285714285714, -1.4285714285714286, -1.2857142857142858, -1.1428571428571428, -1.0, -0.8571428571428572, -0.7142857142857144, -0.5714285714285716, -0.4285714285714286, -0.2857142857142858, -0.14285714285714302, 0.0, 0.1428571428571428, 0.2857142857142856, 0.4285714285714284, 0.5714285714285712, 0.714285714285714, 0.8571428571428568, 1.0, 1.1428571428571428, 1.2857142857142856, 1.4285714285714284, 1.5714285714285712, 1.714285714285714, 1.8571428571428568, 2.0, 2.1428571428571423, 2.2857142857142856, 2.428571428571428, 2.571428571428571, 2.7142857142857144, 2.8571428571428568, 3.0, 3.1428571428571423, 3.2857142857142856, 3.428571428571428, 3.571428571428571, 3.7142857142857135, 3.8571428571428568, 4.0, 4.142857142857142, 4.285714285714286, 4.428571428571428, 4.571428571428571, 4.7142857142857135, 4.857142857142857, 5.0]

Move `priors` out of utils

Given the important role that the specification of prior distributions has in GPax, it make sense to move them out of the utils into a separate module.

Add explanation/examples on how to use utils.priors

The utils.priors (code) have beed introduced to streamline the placement of priors over model parameters as well as to simplify the incorporation of prior mean functions. Several examples (in docstrings and/or in a separate notebook) of their usage would be beneficial.

Any suggestions on how to improve acquisition.UCB for active GP example?

I changed the test function in the gpax-GPBO tutorial to the following:

y(x) = 1 / (x ** 2 + 1) * np.cos(np.pi * x)

for x in [-2,5] and obtained the following:

dataset_1

It looks like the acquisition.UCB function keeps getting a maxima in the same region -- even though the posterior mean and variance have shrunk.

Effect of changing the noise prior from

numpyro.distributions.HalfNormal(0.01)

to

numpyro.distributions.Normal(1)

dataset_1

1. Is there an alternative acquisition function that I should be using/some alternative value for beta?

2. Is there a way to add some additional cost for trying to add more points in a densely populated region?

Quality-of-life suggestions for release, CI, semantic versioning, etc.

@ziatdinovmax I have a couple of suggestions for your consideration:

  • Pool all setup protocol into pyproject.toml. PEP 621 began the transition of Python setup to the "non-python" pyproject file. In GPax, the setup.py file is not necessary. We can pool all build instructions into the pyproject.toml file.
  • CI code can be slightly refactored for clarity.
  • Similarly, I have developed a procedure for on-the-fly semantic versioning from tags, similar to the old versioneer.py method, but my method is a few lines and relies on dunamai to grab the current HEAD's tag. I use this combined with "API-key-free" publishing to PyPI, my CI procedure, and GH environments to securely publish any new tagged release. The environment configuration requires manual confirmation before any release, in case you were worried about over-automation causing unintended things to happen. EDIT: there is a better way to do this using hatchling. See here.
  • Implement dependabot for automatic version bumps, and version-lock all dependencies. I think this is just good practice to ensure your code works even if a dependency releases an update that should be backwards compatible, but isn't. Example of that here.

The most recent example I have of all of this can be found here, with a slightly less recent example here.

I am more than happy to implement these QOL changes.

We consider noisy observations of a discontinuous function...

Hello,
I just read your excellent article and jump to your gpax lib. I already used numpyro for NUTS/SVI and a little practice for GP, and I was looking probably of what you are described in your GP_sGP.ipynb. I would like to be sure that I have understand the use case developed at the end of your nb.

Bellow I have display some data points and I know because of the process under the hood that there is a discontinuity at x close to (but not exactly) 0. Of course 1) I can fit a determinist parametrized function piecewise with an "linear" behaviour for xx0, 2) on a other hand I can use an RBF+noise GP but then I miss the discontinuity.

Do you think that your example is especially designed to keep up this discontinuity problem ?

image

Thanks

Kernels with a different length scale on each axis

Is there any way to use GPax in its current state with kernels of the form e.g.,

$$k(\mathbf{x}, \mathbf{x}') = e^{-\lambda_1(x_1 - x_1')^2} e^{-\lambda_2(x_2 - x_2')^2} e^{-\lambda_3(x_3 - x_3')^2}$$?

Where each dimension gets its own length scale, allowing for greater flexibility. Akin to ard_num_dims in GPyTorch. It shouldn't be too hard, right? Should just boil down to modifying the kernel codes so that params["k_length"] broadcasts correctly.

Implement faster smoke tests of notebooks

@ziatdinovmax referencing your suggestion in #50. The way to do this is to add an environment variable that is detected by the notebook. If, for example, SMOKE_TEST==1, we simply adjust how many iterations things train for, the size of datasets, stuff like this. Again GPyTorch has some good examples of how this can work in practice (they run the tests on their docs but it doesn't matter).

UIGP: Allow for different variance along different input feature dimensions

Currently, the UIGP class extends the standard Gaussian Process model to handle uncertain inputs. However, it assumes that the variance (sigma_x) is the same for all input feature dimension. It would be a good idea to extend it to scenarios where we expect different variance for different input parameters.

Option to use regular NN in viDKL

Currently, we automatically place priors over weights and biases of a neural network in viDKL, effectively turning it into BNN. It may be a good idea to make this optional and allows for using of a regular NN.

ExactGP.predict and viGP.predict produce inconsistent shapes

The predict method on ExactGP and viGP produce results of different shapes.

ExactGP.predict produces a 3-tensor, e.g. (2000, 200, 100).

viGP.predict produces a 1-tensor, e.g. (100,).

Is there any way to standardize the output of these methods? Also, it appears 2000 is the number of samples after warmup, and 200 samples from the posterior. Maybe the output of viGP.predict should be (1, 200, 100) to make it consistent (since there's only a single value for e.g. samples["k_length"]). This should be easy enough to do by just using mean, cov = self.get_mvn_posterior(X_new, samples, noiseless, **kwargs) to draw 200 samples, I think. Let me know if I have this totally wrong.

In addition, it begs the question if a ABC for GPs should really be being used. It would probably be best for the user if, in all cases possible, every core method of each GP produces the same type of object. I see that viGP inherits ExactGP, but it might be best to have ExactGP (or whatever the most base class is) inherit from some ABC.

Unable to use gpu: might be a jax(or jaxlib) issue

When I am running the gpax_vidkl_eels.ipynb I am getting below warning:

An NVIDIA GPU may be present on this machine, but a CUDA-enabled jaxlib is not installed. Falling back to CPU.

How to reproduce:

I created the python env using following steps:
conda create -n gpax_hae python==3.10
conda activate gpax_hae
pip install -e . (inside gpax repository) ------- this install most of the dependencies including jax and jaxlib
pip install jupyter
pip install ipykernel

Suggestion: refactor acquisition.py to a class structure

Currently, every acquisition function in acquisition.py is a function. I think these objects will function better as classes since they take a lot of common arguments and also share a common abstraction. In addition, it will make the campaigning in #33 much more straightforward. For example, while certain acquisition functions require different things (EI requires best_f whereas UCB requires beta), they could all have a common function, maybe update_as_function_of_data_and_observations that calculates best_f for EI and does nothing for UCB, allowing for extension to more complex acquisition functions later.

I will implement this as a backwards-compatible feature for #33 but I definitely think you should consider making this change!

MCMC prediction stability issue - providing NAN values of variance (Issue in Google Colab GPU/HighRam setting)

**This is the issue encountered in Google Colab- under GPU setting T4 and High-RAM

When we run the function- ExactGP.fit()-- it produces NAN values for standard deviation calculation. The error can be repo in all the below modifications
These things I have already tried

  • Normalize the data in fitting the model
  • Tried with all the kernels: RBF, Matern and Periodic
  • Tried with diff prior function: LogNormal, Normal, HalfNormal which are mostly used anyway in GP/BO
  • Tried with diff noise priors
  • Also tried with diff sets of training data

With current workaround it seems with reducing the number of total samples in MCMC setting to num_warmup=500, num_samples=500 (Default is num_warmup=1000, num_samples=3000), it is able to provide reasonable outputs.

Problem with models.sPM?

When using mean, samples = spm.predict(key2, X_unmeasured, take_point_predictions_mean=False), the predictions are calculated over measured points, rather then unmeasured point array that is passed to the .predict

Sparse GP

While this package mostly aims at utilizing Fully Bayesian exact GPs, certain tasks (e.g. image and hyperspectral data reconstruction) may require utilizing sparse approximations with inducing points. There are, of course, multiple approaches to sparse GP. According to this study, a VFE approximation may be a good choice.

Use of viMTDKL

Hi Maxim,

I was trying to test gapx.viMTDKL() on the dummy EELS dataset, but got stuck when preparing the data:

  1. Does the train_test_split() function support preparing dataset for viMTDKL?
  2. I started with a simple case: use a Lorentzian function to fit for the height and position, which are used as the two scalarizers defined on the same input dimensions (please see the last section of this shared notebook: link). However, there is always an error saying the dimension is not correct.
  3. I have followed your steps in this example notebook of "Theory-informed optimization of experiment with multi-task GP" (link), and the code can run without any issue (although super slow for the 3D dataset)
  4. There is a flag called "shared_input_space" in the gapx.viMTDKL(). When all the scalarizers are defined on the same coordinate/grid, should I make this flag true?

Best,
Richard

Set noise prior automatically

We should be setting the noise prior automatically based on the y-range of the provided training data. Currently, the default prior is LogNormal(0, 1), which may not be always optimal, especially when using data with normalized y-range (because it allows for scenarios where the noise is almost one order of magnitude larger than the entire observation range). So instead, we can set it automatically as a HalfNormal(0, v) distribution with a default variance of v = 0.2 * (y_max - y_min). As always, a user will also have an option to pass their own custom prior.

Thoughts? @yongtaoliu, @arpanbiswas52, @SergeiVKalinin, @RichardLiuCoding, @aghosh92?

Extension of kernel='RBF',...

Hi,
Is it possible that the user would provide his/her own kernel? For the moment if I understand correctly
kernel='RBF', 'Periodic', or 'Matern'. But one may can use other kind of kernels and make some add/mult... composition.

Also, why for example in the following code

def MaternKernel(X: jnp.ndarray, Z: jnp.ndarray,
                 params: Dict[str, jnp.ndarray],
                 noise: int = 0, **kwargs: float) -> jnp.ndarray:

noise is an integer?

Thanks

Remove requirements.txt?

I think requirements.txt is deprecated now, and pip install -r requirements.txt can be completely replaced by bash scripts.install.sh, which reads directly from the pyproject.

Suggestion: activate dependabot

Dependabot is awesome and will automatically bump versions of required dependencies, open a PR and trigger a CI loop to test that everything is still working. I use it in my open source projects. @ziatdinovmax what do you think?

Note this is dependent on #107 since we can only have dependencies in either the requirements or pyproject file.

Feature: implement simulated campaigning for "hyper parameter tuning"

@ziatdinovmax as we discussed, I plan on implementing a simulated campaigning loop for tuning the "hyper parameters" of an optimization loop. I first want to learn this library inside and out so it might take some time. But anyways, the executive summary of the tasks at hand look something like this:

  • Develop a Campaign class for storing the state of and running the campaign
  • Parallelize the campaigning (since many simulations will have to be run); might want to consider mpi4py but more likely multiprocessing will be enough
  • Implement a smart checkpoint-restart system for the same reason
  • Write appropriate tests

Feature: allow the user to scale X and y before fitting, predicting, etc.

Scaling features and targets to have "reasonable" values (usually between -1 and 1) is usually a pre-processing step that people who generally use GPs will know to do. However, it would be nice to have this functionality built into the GPs themselves.

So in other words, if a user presented an X with features that were not within the range of -1 to 1, these could be optionally scaled before fitting. Those scaling parameters could then be saved and reapplied during prediction.

Similarly, we could consider scaling the outputs as well. @ziatdinovmax what do you think?

Test the new deployment system on the test PyPI server

repository-url: https://test.pypi.org/legacy/

@ziatdinovmax, just a reminder, I have set the deployment target to the testing PyPI server on purpose so you can play around with the new system without risk of deploying to the real PyPI.

Please let me know if you have any questions on how this works. Essentially, when you push a tagged commit to main, it should trigger an action that will test that commit, build everything, and then hold deployment until you approve through the environment (which you have to setup). That tag should read something like v0.1.9.

Batch acquisition (bototrch style)

Per discussion in #57:
Implement the batch acquisition methods that allow one to set a value for q such that the best combination of q points that jointly optimize the acquisition function are chosen.

Fix documentation building

The documentation builds are failing seemingly because we no longer have __version__.py file.

Running Sphinx v6.2.1

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/envs/latest/lib/python3.9/site-packages/sphinx/config.py", line 354, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/checkouts/latest/docs/source/conf.py", line 28, in <module>
    with open(os.path.join(module_dir, '../../gpax/__version__.py')) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/docs/checkouts/readthedocs.org/user_builds/gpax/checkouts/latest/docs/source/../../gpax/__version__.py'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/envs/latest/lib/python3.9/site-packages/sphinx/cmd/build.py", line 280, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/envs/latest/lib/python3.9/site-packages/sphinx/application.py", line 207, in __init__
    self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/envs/latest/lib/python3.9/site-packages/sphinx/config.py", line 177, in read
    namespace = eval_config_file(filename, tags)
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/envs/latest/lib/python3.9/site-packages/sphinx/config.py", line 367, in eval_config_file
    raise ConfigError(msg % traceback.format_exc()) from exc
sphinx.errors.ConfigError: There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/envs/latest/lib/python3.9/site-packages/sphinx/config.py", line 354, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/checkouts/latest/docs/source/conf.py", line 28, in <module>
    with open(os.path.join(module_dir, '../../gpax/__version__.py')) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/docs/checkouts/readthedocs.org/user_builds/gpax/checkouts/latest/docs/source/../../gpax/__version__.py'


Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/envs/latest/lib/python3.9/site-packages/sphinx/config.py", line 354, in eval_config_file
    exec(code, namespace)  # NoQA: S102
  File "/home/docs/checkouts/readthedocs.org/user_builds/gpax/checkouts/latest/docs/source/conf.py", line 28, in <module>
    with open(os.path.join(module_dir, '../../gpax/__version__.py')) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/home/docs/checkouts/readthedocs.org/user_builds/gpax/checkouts/latest/docs/source/../../gpax/__version__.py'

Should be an easy fix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.