Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,35 +150,40 @@ For more details see our [Documentation](https://botorch.org/docs/introduction)
```python
import torch
from botorch.models import SingleTaskGP
from botorch.models.transforms import Normalize, Standardize
from botorch.fit import fit_gpytorch_mll
from gpytorch.mlls import ExactMarginalLogLikelihood

# Double precision is highly recommended for GPs.
# See https://github.com/pytorch/botorch/discussions/1444
train_X = torch.rand(10, 2, dtype=torch.double)
train_X = torch.rand(10, 2, dtype=torch.double) * 2
Y = 1 - (train_X - 0.5).norm(dim=-1, keepdim=True) # explicit output dimension
Y += 0.1 * torch.rand_like(Y)
train_Y = (Y - Y.mean()) / Y.std()

gp = SingleTaskGP(train_X, train_Y)
gp = SingleTaskGP(
train_X=train_X,
train_Y=Y,
input_transform=Normalize(d=2),
outcome_transform=Standardize(m=1),
)
mll = ExactMarginalLogLikelihood(gp.likelihood, gp)
fit_gpytorch_mll(mll)
```

2. Construct an acquisition function
```python
from botorch.acquisition import UpperConfidenceBound
from botorch.acquisition import LogExpectedImprovement

UCB = UpperConfidenceBound(gp, beta=0.1)
logNEI = LogExpectedImprovement(model=gp, best_f=Y.max())
```

3. Optimize the acquisition function
```python
from botorch.optim import optimize_acqf

bounds = torch.stack([torch.zeros(2), torch.ones(2)])
bounds = torch.stack([torch.zeros(2), torch.ones(2)]).to(torch.double)
candidate, acq_value = optimize_acqf(
UCB, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
logNEI, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
)
```

Expand Down
19 changes: 12 additions & 7 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,39 @@ Here's a quick run down of the main components of a Bayesian Optimization loop.
```python
import torch
from botorch.models import SingleTaskGP
from botorch.models.transforms import Normalize, Standardize
from botorch.fit import fit_gpytorch_mll
from gpytorch.mlls import ExactMarginalLogLikelihood
from botorch.models.transforms.outcome import Standardize

train_X = torch.rand(10, 2, dtype=torch.float64)
train_X = torch.rand(10, 2, dtype=torch.double) * 2
# explicit output dimension -- Y is 10 x 1
train_Y = 1 - (train_X - 0.5).norm(dim=-1, keepdim=True)
train_Y += 0.1 * torch.rand_like(train_Y)

gp = SingleTaskGP(train_X, train_Y, outcome_transform=Standardize(m=1))
gp = SingleTaskGP(
train_X=train_X,
train_Y=Y,
input_transform=Normalize(d=2),
outcome_transform=Standardize(m=1),
)
mll = ExactMarginalLogLikelihood(gp.likelihood, gp)
fit_gpytorch_mll(mll)
```

2. Construct an acquisition function
```python
from botorch.acquisition import UpperConfidenceBound
from botorch.acquisition import LogExpectedImprovement

UCB = UpperConfidenceBound(gp, beta=0.1)
logNEI = LogExpectedImprovement(model=gp, best_f=Y.max())
```

3. Optimize the acquisition function
```python
from botorch.optim import optimize_acqf

bounds = torch.stack([torch.zeros(2), torch.ones(2)])
bounds = torch.stack([torch.zeros(2), torch.ones(2)]).to(torch.double)
candidate, acq_value = optimize_acqf(
UCB, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
logNEI, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
)
```

Expand Down
36 changes: 20 additions & 16 deletions website/pages/en/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const bash = (...args) => `~~~bash\n${String.raw(...args)}\n~~~`;

class HomeSplash extends React.Component {
render() {
const {siteConfig, language = ''} = this.props;
const {baseUrl, docsUrl} = siteConfig;
const { siteConfig, language = '' } = this.props;
const { baseUrl, docsUrl } = siteConfig;
const docsPart = `${docsUrl ? `${docsUrl}/` : ''}`;
const langPart = `${language ? `${language}/` : ''}`;
const docUrl = doc => `${baseUrl}${docsPart}${langPart}${doc}`;
Expand Down Expand Up @@ -79,8 +79,8 @@ class HomeSplash extends React.Component {

class Index extends React.Component {
render() {
const {config: siteConfig, language = ''} = this.props;
const {baseUrl} = siteConfig;
const { config: siteConfig, language = '' } = this.props;
const { baseUrl } = siteConfig;

const Block = props => (
<Container
Expand Down Expand Up @@ -114,34 +114,38 @@ class Index extends React.Component {
const modelFitCodeExample = `${pre}python
import torch
from botorch.models import SingleTaskGP
from botorch.models.transforms import Normalize, Standardize
from botorch.fit import fit_gpytorch_mll
from botorch.utils import standardize
from gpytorch.mlls import ExactMarginalLogLikelihood

train_X = torch.rand(10, 2, dtype=torch.double)
train_X = torch.rand(10, 2, dtype=torch.double) * 2
Y = 1 - torch.linalg.norm(train_X - 0.5, dim=-1, keepdim=True)
Y = Y + 0.1 * torch.randn_like(Y) # add some noise
train_Y = standardize(Y)

gp = SingleTaskGP(train_X, train_Y)
gp = SingleTaskGP(
train_X=train_X,
train_Y=Y,
input_transform=Normalize(d=2),
outcome_transform=Standardize(m=1),
)
mll = ExactMarginalLogLikelihood(gp.likelihood, gp)
fit_gpytorch_mll(mll)
`;
// Example for defining an acquisition function
const constrAcqFuncExample = `${pre}python
from botorch.acquisition import UpperConfidenceBound
from botorch.acquisition import LogExpectedImprovement

UCB = UpperConfidenceBound(gp, beta=0.1)
logNEI = LogExpectedImprovement(model=gp, best_f=Y.max())
`;
// Example for optimizing candidates
const optAcqFuncExample = `${pre}python
from botorch.optim import optimize_acqf

bounds = torch.stack([torch.zeros(2), torch.ones(2)])
bounds = torch.stack([torch.zeros(2), torch.ones(2)]).to(torch.double)
candidate, acq_value = optimize_acqf(
UCB, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
logNEI, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
)
candidate # tensor([0.4887, 0.5063])
candidate # tensor([[0.2981, 0.2401]], dtype=torch.float64)
`;
const papertitle = `BoTorch: A Framework for Efficient Monte-Carlo Bayesian Optimization`
const paper_bibtex = `${pre}plaintext
Expand All @@ -158,7 +162,7 @@ candidate # tensor([0.4887, 0.5063])
<div
className="productShowcaseSection"
id="quickstart"
style={{textAlign: 'center'}}>
style={{ textAlign: 'center' }}>
<h2>Get Started</h2>
<Container>
<ol>
Expand Down Expand Up @@ -187,7 +191,7 @@ candidate # tensor([0.4887, 0.5063])
);

const Features = () => (
<div className="productShowcaseSection" style={{textAlign: 'center'}}>
<div className="productShowcaseSection" style={{ textAlign: 'center' }}>
<h2>Key Features</h2>
<Block layout="threeColumn">
{[
Expand Down Expand Up @@ -221,7 +225,7 @@ candidate # tensor([0.4887, 0.5063])
<div
className="productShowcaseSection"
id="reference"
style={{textAlign: 'center'}}>
style={{ textAlign: 'center' }}>
<h2>References</h2>
<Container>
<a href={`https://arxiv.org/abs/1910.06403`}>{papertitle}</a>
Expand Down