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 bug in model list with output indices #1453

Closed
wants to merge 1 commit 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/models/gpytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def posterior(
with gpt_posterior_settings():
# only compute what's necessary
if output_indices is not None:
mvns = [self.forward_i(i, transformed_X[i]) for i in output_indices]
mvns = [self.models[i](transformed_X[i]) for i in output_indices]
if observation_noise is not False:
if torch.is_tensor(observation_noise):
lh_kwargs = [
Expand Down
22 changes: 19 additions & 3 deletions test/models/test_gpytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,25 @@ def test_model_list_gpytorch_model(self):
self.assertIsInstance(posterior, GPyTorchPosterior)
self.assertEqual(posterior.mean.shape, torch.Size([2, 2]))
# test output indices
posterior = model.posterior(test_X, output_indices=[0])
self.assertIsInstance(posterior, GPyTorchPosterior)
self.assertEqual(posterior.mean.shape, torch.Size([2, 1]))
for output_indices in ([0], [1], [0, 1]):
posterior_subset = model.posterior(
test_X, output_indices=output_indices
)
self.assertIsInstance(posterior_subset, GPyTorchPosterior)
self.assertEqual(
posterior_subset.mean.shape, torch.Size([2, len(output_indices)])
)
self.assertTrue(
torch.equal(
posterior_subset.mean, posterior.mean[..., output_indices]
)
)
self.assertTrue(
torch.equal(
posterior_subset.variance,
posterior.variance[..., output_indices],
)
)
# test observation noise
posterior = model.posterior(test_X, observation_noise=True)
self.assertIsInstance(posterior, GPyTorchPosterior)
Expand Down