Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fbshipit-source-id: 436d6dd4434140b6b24f9476b71ec3b4e1b095c2
- Loading branch information
0 parents
commit 0afd603
Showing
50 changed files
with
2,831 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[flake8] | ||
|
||
# E704: the linter doesn't parse types properly | ||
# T499, T484: We don't need to run pyre and mypy | ||
# W503: black and flake8 disagree on how to place operators) | ||
ignore = T484, T499, W503, E704 | ||
# Black really wants lines to be 88 chars.... | ||
max-line-length = 88 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# watchman | ||
.watchmanconfig | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# Atom plugin files and ctags | ||
.ftpconfig | ||
.ftpconfig.cson | ||
.ftpignore | ||
*.tags | ||
*.tags1 | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# vim | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# botorch design guide [WIP] | ||
|
||
This document provides guidance on botorch's internal design. | ||
|
||
## design philosophy | ||
|
||
botorch follows a modular, low-overhead “unframework” design philosophy, which | ||
provides building blocks and abstractions, but does not force the user to do | ||
things in any one particular way. This empowers the user to easily prototype and | ||
test new approaches. | ||
|
||
|
||
## acquisition functions | ||
|
||
botorch supports batch acquisition functions (e.g. q-EI, q-UCB, etc.) that | ||
assign a joint utility to a set of q design points in the parameter space. | ||
|
||
Unfortunately, this batch nomenclature gets easily conflated with the pytorch | ||
notion of batch-evaluation. To avoid confusion in that respect, we adopt the | ||
convention of referring to batches in the batch-acquisition sense as "q-batches", | ||
and to batches in the torch batch-evaluation sense as "t-batches". | ||
|
||
Internally, q-batch acquisition functions operate on input tensors of shape | ||
`b x q x d`, where `b` is the number of t-batches, `q` is the number of design | ||
points, and `d` is the dimension of the parameter space. Their output is a | ||
one-dimensional tensor with `b` elements, with the `i`-th element corresponding | ||
to the `i`-th t-batch. | ||
|
||
To simplify the user-facing API, if provided with an input tensor of shape `q x d`, | ||
a t-batch size of 1 is inferred, and the result is returned as a torch scalar. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018-present, Facebook, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# botorch (pre-alpha) [WIP] | ||
|
||
botorch is a library for Bayesian Optimization in pytorch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from . import acquisition, optim, test_functions | ||
from .fit import fit_model | ||
from .gen import gen_candidates | ||
from .utils import manual_seed | ||
|
||
|
||
__all__ = [ | ||
acquisition, | ||
fit_model, | ||
gen_candidates, | ||
optim, | ||
manual_seed, | ||
test_functions, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from .batch_modules import ( | ||
qExpectedImprovement, | ||
qProbabilityOfImprovement, | ||
qUpperConfidenceBound, | ||
) | ||
from .modules import ( | ||
AcquisitionFunction, | ||
ExpectedImprovement, | ||
PosteriorMean, | ||
ProbabilityOfImprovement, | ||
UpperConfidenceBound, | ||
) | ||
|
||
|
||
__all__ = [ | ||
AcquisitionFunction, | ||
ExpectedImprovement, | ||
PosteriorMean, | ||
ProbabilityOfImprovement, | ||
UpperConfidenceBound, | ||
qExpectedImprovement, | ||
qProbabilityOfImprovement, | ||
qUpperConfidenceBound, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from typing import Callable, List, Optional | ||
|
||
import torch | ||
from gpytorch import Module | ||
|
||
from .functional import ( | ||
batch_expected_improvement, | ||
batch_probability_of_improvement, | ||
batch_simple_regret, | ||
batch_upper_confidence_bound, | ||
) | ||
from .modules import AcquisitionFunction | ||
|
||
|
||
""" | ||
Wraps the batch acquisition functions defined in botorch.acquisition.functional | ||
into BatchAcquisitionFunction gpytorch modules. | ||
""" | ||
|
||
|
||
class BatchAcquisitionFunction(AcquisitionFunction): | ||
def forward(self, candidate_set: torch.Tensor) -> torch.Tensor: | ||
"""Takes in a `b x q x d` candidate_set Tensor of `b` t-batches with `q` | ||
`d`-dimensional design points each, and returns a one-dimensional Tensor | ||
with `b` elements.""" | ||
raise NotImplementedError("BatchAcquisitionFunction cannot be used directly") | ||
|
||
|
||
class qExpectedImprovement(BatchAcquisitionFunction): | ||
"""TODO""" | ||
|
||
def __init__( | ||
self, | ||
model: Module, | ||
best_f: float, | ||
objective: Callable[[torch.Tensor], torch.Tensor] = lambda Y: Y, | ||
constraints: Optional[List[Callable[[torch.Tensor], torch.Tensor]]] = None, | ||
mc_samples: int = 5000, | ||
) -> None: | ||
super(qExpectedImprovement, self).__init__(model) | ||
self.best_f = best_f | ||
self.objective = objective | ||
self.constraints = constraints | ||
self.mc_samples = mc_samples | ||
|
||
def forward(self, candidate_set: torch.Tensor) -> torch.Tensor: | ||
return batch_expected_improvement( | ||
X=candidate_set, | ||
model=self.model, | ||
best_f=self.best_f, | ||
objective=self.objective, | ||
constraints=self.constraints, | ||
mc_samples=self.mc_samples, | ||
) | ||
|
||
|
||
class qProbabilityOfImprovement(BatchAcquisitionFunction): | ||
"""TODO""" | ||
|
||
def __init__(self, model: Module, best_f: float, mc_samples: int = 5000) -> None: | ||
super(qProbabilityOfImprovement, self).__init__(model) | ||
self.best_f = best_f | ||
self.mc_samples = mc_samples | ||
|
||
def forward(self, candidate_set: torch.Tensor) -> torch.Tensor: | ||
return batch_probability_of_improvement( | ||
X=candidate_set, | ||
model=self.model, | ||
best_f=self.best_f, | ||
mc_samples=self.mc_samples, | ||
) | ||
|
||
|
||
class qUpperConfidenceBound(BatchAcquisitionFunction): | ||
"""TODO""" | ||
|
||
def __init__(self, model: Module, beta: float, mc_samples: int = 5000) -> None: | ||
super(qUpperConfidenceBound, self).__init__(model) | ||
self.beta = beta | ||
self.mc_samples = mc_samples | ||
|
||
def forward(self, candidate_set: torch.Tensor) -> torch.Tensor: | ||
return batch_upper_confidence_bound( | ||
X=candidate_set, | ||
model=self.model, | ||
beta=self.beta, | ||
mc_samples=self.mc_samples, | ||
) | ||
|
||
|
||
class qSimpleRegret(BatchAcquisitionFunction): | ||
"""TODO""" | ||
|
||
def __init__(self, model: Module, mc_samples: int = 5000) -> None: | ||
super(qSimpleRegret, self).__init__(model) | ||
self.mc_samples = mc_samples | ||
|
||
def forward(self, candidate_set: torch.Tensor) -> torch.Tensor: | ||
return batch_simple_regret( | ||
X=candidate_set, model=self.model, mc_samples=self.mc_samples | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from .acquisition import ( | ||
expected_improvement, | ||
max_value_entropy_search, | ||
posterior_mean, | ||
probability_of_improvement, | ||
upper_confidence_bound, | ||
) | ||
|
||
from .batch_acquisition import ( | ||
batch_expected_improvement, | ||
batch_knowledge_gradient, | ||
batch_noisy_expected_improvement, | ||
batch_probability_of_improvement, | ||
batch_upper_confidence_bound, | ||
batch_simple_regret, | ||
) | ||
|
||
__all__ = [ | ||
expected_improvement, | ||
max_value_entropy_search, | ||
posterior_mean, | ||
probability_of_improvement, | ||
upper_confidence_bound, | ||
batch_expected_improvement, | ||
batch_knowledge_gradient, | ||
batch_noisy_expected_improvement, | ||
batch_probability_of_improvement, | ||
batch_upper_confidence_bound, | ||
batch_simple_regret, | ||
] |
Oops, something went wrong.