Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_infeasible_cost for objectives that require X #1721

Closed
wants to merge 4 commits into from
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
2 changes: 1 addition & 1 deletion botorch/acquisition/multi_objective/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def __init__(
from botorch.acquisition.utils import get_infeasible_cost

inf_cost = get_infeasible_cost(
X=X_baseline, model=model, objective=lambda y: y
X=X_baseline, model=model, objective=lambda y, X: y
)[objective_idcs]

def apply_feasibility_weights(
Expand Down
2 changes: 1 addition & 1 deletion botorch/acquisition/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def objective(Y: Tensor, X: Optional[Tensor] = None):
return Y.squeeze(-1)

posterior = model.posterior(X, posterior_transform=posterior_transform)
lb = objective(posterior.mean - 6 * posterior.variance.clamp_min(0).sqrt())
lb = objective(posterior.mean - 6 * posterior.variance.clamp_min(0).sqrt(), X=X)
if lb.ndim < posterior.mean.ndim:
lb = lb.unsqueeze(-1)
# Take outcome-wise min. Looping in to handle batched models.
Expand Down
9 changes: 7 additions & 2 deletions test/acquisition/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class TestGetInfeasibleCost(BotorchTestCase):
def test_get_infeasible_cost(self):
for dtype in (torch.float, torch.double):
tkwargs = {"dtype": dtype, "device": self.device}
X = torch.zeros(5, 1, **tkwargs)
X = torch.ones(5, 1, **tkwargs)
means = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0], **tkwargs).view(-1, 1)
variances = torch.tensor([0.09, 0.25, 0.36, 0.25, 0.09], **tkwargs).view(
-1, 1
Expand All @@ -586,9 +586,14 @@ def test_get_infeasible_cost(self):
# means - 6 * std = [-0.8, -1, -0.6, 1, 3.2]. After applying the
# objective, the minimum becomes -6.0, so 6.0 should be returned.
M = get_infeasible_cost(
X=X, model=mm, objective=lambda Y: Y.squeeze(-1) - 5.0
X=X, model=mm, objective=lambda Y, X: Y.squeeze(-1) - 5.0
)
self.assertAllClose(M, torch.tensor([6.0], **tkwargs))
M = get_infeasible_cost(
X=X, model=mm, objective=lambda Y, X: Y.squeeze(-1) - 5.0 - X[0, 0]
)
self.assertAllClose(M, torch.tensor([7.0], **tkwargs))
# test it with using also X in the objective
# Test default objective (squeeze last dim).
M2 = get_infeasible_cost(X=X, model=mm)
self.assertAllClose(M2, torch.tensor([1.0], **tkwargs))
Expand Down