27 lines
788 B
Python
27 lines
788 B
Python
import torch
|
|
from botorch.models import SingleTaskGP
|
|
from botorch.fit import fit_gpytorch_mll
|
|
from botorch.utils import standardize
|
|
from gpytorch.mlls import ExactMarginalLogLikelihood
|
|
|
|
from botorch.acquisition import UpperConfidenceBound
|
|
from botorch.optim import optimize_acqf
|
|
|
|
|
|
train_X = torch.rand(10, 2, dtype=torch.double)
|
|
Y = 1 - torch.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)
|
|
mll = ExactMarginalLogLikelihood(gp.likelihood, gp)
|
|
fit_gpytorch_mll(mll)
|
|
|
|
UCB = UpperConfidenceBound(gp, beta=0.1)
|
|
|
|
bounds = torch.stack([torch.zeros(2), torch.ones(2)])
|
|
candidate, acq_value = optimize_acqf(
|
|
UCB, bounds=bounds, q=1, num_restarts=5, raw_samples=20,
|
|
)
|
|
print(candidate)
|