Skip to content

Commit

Permalink
Merge 992b5b2 into d81a674
Browse files Browse the repository at this point in the history
  • Loading branch information
qingfeng10 authored Oct 26, 2023
2 parents d81a674 + 992b5b2 commit c56488a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions botorch/acquisition/penalized.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ def forward(self, samples: Tensor, X: Optional[Tensor] = None) -> Tensor:
if self.expand_dim is not None:
# reshape penalty_obj to match the dim
penalty_obj = penalty_obj.unsqueeze(self.expand_dim)
# this happens when samples is a `q x m`-dim tensor and X is a `q x d`-dim
# tensor; obj returned from GenericMCObjective is a `q`-dim tensor and
# penalty_obj is a `1 x q`-dim tensor.
if obj.ndim == 1:
assert penalty_obj.shape == torch.Size([1, samples.shape[-2]])
penalty_obj = penalty_obj.squeeze(dim=0)
return obj - self.regularization_parameter * penalty_obj


Expand Down
2 changes: 1 addition & 1 deletion test/acquisition/test_penalized.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def test_penalized_mc_objective(self):
samples = torch.randn(4, 3, device=self.device, dtype=dtype)
X = torch.randn(4, 5, device=self.device, dtype=dtype)
penalized_obj = generic_obj(samples) - 0.1 * l1_penalty_obj(X)
self.assertTrue(torch.equal(obj(samples, X), penalized_obj))
self.assertTrue(torch.equal(obj(samples, X), penalized_obj.squeeze(0)))
# test 'q x d' Tensor X
samples = torch.randn(4, 2, 3, device=self.device, dtype=dtype)
X = torch.randn(2, 5, device=self.device, dtype=dtype)
Expand Down

0 comments on commit c56488a

Please sign in to comment.