GithubHelp home page GithubHelp logo

online_vargp's Introduction

Conditioning Sparse Variational Gaussian Processes for Online Decision-making

This repository contains a PyTorch and GPyTorch implementation of the paper "Conditioning Sparse Variational Gaussian Processes for Online Decision-making."

Introduction

Online variational conditioning (OVC) provides closed form conditioning (e.g. updating a model's posterior predictive distribution after having observed new data points) for stochastic variational Gaussian processes. OVC enables the development of ``fantasization" (predicting on data and then conditioning on a random posterior sample) for variational GPs, thereby enabling SVGPs to be used for the first time in advanced, look-ahead acquisitions such as the batch knowledge gradient, entropy search, and look-ahead Thompson sampling (which we introduce).

In this repo, we provide an implementation of a SVGP model with OVC hooked up as the get_fantasy_model function, allowing it to be natively used with any advanced acquisition function in BoTorch (see the experiments in the experiments/std_bayesopt folder).

Installation

python setup.py develop

See requirements.txt for our setup. We require Pytorch >= 1.8.0 and used the master versions of GPyTorch and BoTorch installed from source.

File Structure

.
+-- volatilitygp/
|   +-- likelihoods/
|   |   +-- _one_dimensional_likelihood.py (Implementation of Newton iteration and the base class for the others)
|   |   +-- bernoulli_likelihood.py
|   |   +-- binomial_likelihood.py
|   |   +-- fixed_noise_gaussian_likelihood.py
|   |   +-- multivariate_normal_likelihood.py
|   |   +-- poisson_likelihood.py
|   |   +-- volatility_likelihood.py
|   +-- mlls/
|   |   +-- patched_variational_elbo.py (patched version of elbo to allow sumMLL training)
|   +-- models/
|   |   +-- model_list_gp.py (patched version of ModelListGP to allow for SVGP models)
|   |   +-- single_task_variational_gp.py (Our basic model class for SVGPs)
|   +-- utils/
|   |   +-- pivoted_cholesky.py (our pivoted cholesky implementation for inducing point init)
+-- experiments/
|   +-- active_learning/ (malaria experiment)
|   |   +-- qnIPV_experiment.py (main script)
|   +-- highd_bo/ (rover experiments)
|   |   +-- run_trbo.py (turbo script)
|   |   +-- run_gibbon.py (global model script, Fig 10c)
|   |   +-- rover_conditioning_experiment.ipynb (Fig 10b)
|   |   +-- trbo.py (turbo implementation)
|   +-- hotspots/ (schistomiasis experiment)
|   |   +-- hotspots.py (main script)
|   +-- mujoco/ (mujoco experiments on swimmer and hopper)
|   |   +-- functions/ (mujoco functions)
|   |   +-- lamcts/ (LA-MCTS implementation)
|   |   +-- turbo_1/ (TurBO implementation)
|   |   run.py (main script)
|   +-- pref_learning/ (preference learning experiment)
|   |   +-- run_pref_learning_exp.py (main script)
|   +-- std_bayesopt/ (bayes opt experiments)
|   |   +-- hartmann6.py (constrained hartmann6)
|   |   +-- lcls_optimization.py (laser)
|   |   +-- poisson_hartmann6.py (poisson constrained hartmann6)
|   |   +-- utils.py (model definition helpers)
|   |   +-- weighted_gp_benchmark/ (python 3 version of WOGP)
|   |   |   +-- lcls_opt_script.py (main script)
+-- tests/ (assorted unit tests for the volatilitygp package)

Commands

Please see each experiment folder for the larger scale experiments.

The understanding experiments can be found in:

  • Figure 1a-b: notebooks/svgp_fantasization_plotting.ipynb
  • Figure 1c: notebooks/SABR_vol_plotting.ipynb
  • Figure 2b-d: experiments/std_bayesopt/knowledge_gradient_branin_plotting.ipynb
  • Figure 6: notebooks/ssgp_port.ipynb
  • Figure 7: notebooks/ssgp_time_series_testing_pivcholesky.ipynb
  • Figure 8: notebooks/streaming_bananas_plots.ipynb
  • Figure 10b: experiments/highd_bo/rover_conditioning_experiment.ipynb

Code Credits and References

  • BoTorch (https://botorch.org). Throughout, many examples were inspired by assorted BoTorch tutorials, while we directly compare to Botorch single task GPs.
  • GPyTorch (https://gpytorch.ai). Our implementation of SVGPs rests on this implementation.
  • LA-MCTS code comes from here
  • laser WOGP code comes from here
  • hotspots data comes from here
  • malaria active learning script comes from here. Data can be downloaded from here.

online_vargp's People

Contributors

prakharverma avatar st-- avatar wjmaddox 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

Watchers

 avatar

online_vargp's Issues

Cannot reproduce active_learning.py with svgp model

When running
python qnIPV_experiment.py --model=svgp

  File "..\online_vargp-main\experiments\active_learning\qnIPV_experiment.py", line 302, in <module>
    main(args)
  File "..\online_vargp-main\experiments\active_learning\qnIPV_experiment.py", line 229, in main
    candidates, acq_value = optimize_acqf(
                            ^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\botorch\optim\optimize.py", line 562, in optimize_acqf
    return _optimize_acqf(opt_acqf_inputs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\botorch\optim\optimize.py", line 583, in _optimize_acqf
    return _optimize_acqf_batch(opt_inputs=opt_inputs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\botorch\optim\optimize.py", line 274, in _optimize_acqf_batch
    batch_initial_conditions = opt_inputs.get_ic_generator()(
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\botorch\optim\initializers.py", line 418, in gen_batch_initial_conditions
    Y_rnd_curr = acq_function(
                 ^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\torch\nn\modules\module.py", line 1532, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\torch\nn\modules\module.py", line 1541, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\botorch\utils\transforms.py", line 334, in decorated
    return method(cls, X, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\botorch\utils\transforms.py", line 288, in decorated
    output = method(acqf, X, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\botorch\acquisition\active_learning.py", line 96, in forward
    fantasy_model = self.model.fantasize(
                    ^^^^^^^^^^^^^^^^^^^^
  File "..\.conda\envs\env01\Lib\site-packages\torch\nn\modules\module.py", line 1709, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'FixedNoiseVariationalGP' object has no attribute 'fantasize'

But it was successful with exact model. Sorry for bothering but I how can I deal with?

Cannot reproduce `active_learning` experiment

When running

python qnIPV_experiment.py --num_init=10 --model=svgp --num_steps=250 --seed=1 --output=malaria_nipv_svgp_1.pt

as given in the README.md, I get the following exception:

Traceback (most recent call last):
  File "qnIPV_experiment.py", line 301, in <module>
    main(args)
  File "qnIPV_experiment.py", line 228, in main
    candidates, acq_value = optimize_acqf(
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/optim/optimize.py", line 150, in optimize_acqf
    batch_initial_conditions = ic_gen(
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/optim/initializers.py", line 112, in gen_batch_initial_conditions
    Y_rnd_curr = acq_function(
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/utils/transforms.py", line 255, in decorated
    return method(cls, X, **kwargs)
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/utils/transforms.py", line 214, in decorated
    output = method(acqf, X, *args, **kwargs)
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/acquisition/active_learning.py", line 92, in forward
    fantasy_model = self.model.fantasize(
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/models/model.py", line 140, in fantasize
    return self.condition_on_observations(X=X, Y=Y_fantasized, **kwargs)
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/models/gpytorch.py", line 196, in condition_on_observations
    return self.get_fantasy_model(inputs=X, targets=Y, **kwargs)
  File ".../online_vargp/volatilitygp/models/single_task_variational_gp.py", line 513, in get_fantasy_model
    return super().get_fantasy_model(
  File ".../online_vargp/volatilitygp/models/single_task_variational_gp.py", line 361, in get_fantasy_model
    fantasy_model = inducing_exact_model.condition_on_observations(
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/models/gpytorch.py", line 394, in condition_on_observations
    self._validate_tensor_args(X=X, Y=Y, Yvar=noise, strict=False)
  File ".../anaconda3/envs/onlinet/lib/python3.8/site-packages/botorch/models/gpytorch.py", line 94, in _validate_tensor_args
    raise BotorchTensorDimensionError(
botorch.exceptions.errors.BotorchTensorDimensionError: An explicit output dimension is required for observation noise. Expected Yvar with shape: torch.Size([6, 1]) (got torch.Size([5, 6])).

Calling the experiment script with --random, or running --model=exact (with or without --random) runs fine.

Might this have something to do with the svgp model getting init_y.view(-1) whereas the other models get init_y.view(-1, 1) (similarly for init_y_var)?

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.