Skip to content

Commit 8b32670

Browse files
brunzemafacebook-github-bot
authored andcommitted
add initial objective values to initial state for sample efficiency (#2365)
Summary: <!-- Thank you for sending the PR! We appreciate you spending the time to make BoTorch better. Help us understand your motivation by explaining why you decided to make this change. You can learn more about contributing to BoTorch here: https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md --> ## Motivation Thank you for providing TuRBO as a small tutorial! In the notebook, however, the initial Y values are ignored in the TurboState which seems data inefficient. As this notebook is the starting point for multiple people if they want to compare against or use TuRBO, I believe this should be fixed. I document my change below as the diff with notebooks is not super readable. :) Old implementation (from https://botorch.org/tutorials/turbo_1): ```python X_turbo = get_initial_points(dim, n_init) Y_turbo = torch.tensor( [eval_objective(x) for x in X_turbo], dtype=dtype, device=device ).unsqueeze(-1) state = TurboState(dim, batch_size=batch_size) ``` Crucially, when updating the `TurboState`, only the most recent Y values (`Y_next`) are considered and, therefore, the initial points are discarded: ```python def update_state(state, Y_next): ... state.best_value = max(state.best_value, max(Y_next).item()) ``` Long story short: I changed the initialization of the state to also include the initial Y values: ```python X_turbo = get_initial_points(dim, n_init) Y_turbo = torch.tensor( [eval_objective(x) for x in X_turbo], dtype=dtype, device=device ).unsqueeze(-1) state = TurboState(dim, batch_size=batch_size, best_value=max(Y_turbo).item()) ``` Interestingly, this also (ever so slightly :D ) improves the final performance of TuRBO :) **OLD**: <img width="906" alt="image" src="https://github.com/pytorch/botorch/assets/49341051/d8798eef-567e-4dd7-90ab-4ce9eb69a266"> **NEW**: <img width="904" alt="image" src="https://github.com/pytorch/botorch/assets/49341051/ccead966-8b51-4980-91e6-14430ac3e743"> --- I also added warning supression to the imports to hide my path--I hope that this is ok (I think I also saw this in other notebooks), but I can of course also change this back Old first code cell: ```python import os import math from dataclasses import dataclass import torch from botorch.acquisition import qExpectedImprovement, qLogExpectedImprovement from botorch.fit import fit_gpytorch_mll from botorch.generation import MaxPosteriorSampling from botorch.models import SingleTaskGP from botorch.optim import optimize_acqf from botorch.test_functions import Ackley from botorch.utils.transforms import unnormalize from torch.quasirandom import SobolEngine import gpytorch from gpytorch.constraints import Interval from gpytorch.kernels import MaternKernel, ScaleKernel from gpytorch.likelihoods import GaussianLikelihood from gpytorch.mlls import ExactMarginalLogLikelihood from gpytorch.priors import HorseshoePrior device = torch.device("cuda" if torch.cuda.is_available() else "cpu") dtype = torch.double SMOKE_TEST = os.environ.get("SMOKE_TEST") ``` New: ```python import os import math import warnings from dataclasses import dataclass import torch from botorch.acquisition import qExpectedImprovement, qLogExpectedImprovement from botorch.exceptions import BadInitialCandidatesWarning from botorch.fit import fit_gpytorch_mll from botorch.generation import MaxPosteriorSampling from botorch.models import SingleTaskGP from botorch.optim import optimize_acqf from botorch.test_functions import Ackley from botorch.utils.transforms import unnormalize from torch.quasirandom import SobolEngine import gpytorch from gpytorch.constraints import Interval from gpytorch.kernels import MaternKernel, ScaleKernel from gpytorch.likelihoods import GaussianLikelihood from gpytorch.mlls import ExactMarginalLogLikelihood warnings.filterwarnings("ignore", category=BadInitialCandidatesWarning) warnings.filterwarnings("ignore", category=RuntimeWarning) device = torch.device("cuda" if torch.cuda.is_available() else "cpu") dtype = torch.double SMOKE_TEST = os.environ.get("SMOKE_TEST") ``` ### Have you read the [Contributing Guidelines on pull requests](https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md#pull-requests)? Yes. Pull Request resolved: #2365 Test Plan: I believe this minor change does not need a test plan. ## Related PRs PR does not change functionality. Reviewed By: saitcakmak Differential Revision: D58377054 Pulled By: sdaulton fbshipit-source-id: 2243ac3941ae789b7babb7daf9e3ac816e36cafd
1 parent 8f25f5b commit 8b32670

File tree

1 file changed

+544
-2130
lines changed

1 file changed

+544
-2130
lines changed

0 commit comments

Comments
 (0)