Skip to content

Commit 435a648

Browse files
Carl Hvarfnerfacebook-github-bot
authored andcommitted
Use HadamardGaussianLikelihood in HeterogeneousMTGP for inferred noise (#3176)
Summary: Backlog task: T201650561 (kind of, homogenizing the TL stack) Remove the custom likelihood override in HeterogeneousMTGP so that the parent MultiTaskGP's default HadamardGaussianLikelihood is used when noise variance is not provided. This enables per-task noise inference. Reviewed By: sdaulton Differential Revision: D92836693
1 parent 6e0a265 commit 435a648

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

botorch/models/heterogeneous_mtgp.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
from botorch.models.multitask import MultiTaskGP
2828
from botorch.models.transforms.input import InputTransform
2929
from botorch.models.transforms.outcome import OutcomeTransform
30-
from botorch.models.utils.gpytorch_modules import (
31-
get_gaussian_likelihood_with_gamma_prior,
32-
)
3330
from botorch.posteriors.gpytorch import GPyTorchPosterior
3431
from botorch.posteriors.transformed import TransformedPosterior
3532
from botorch.utils.datasets import MultiTaskDataset
@@ -127,11 +124,7 @@ def __init__(
127124
# The features that are forward passed through the kernel should include
128125
# the task dim
129126
covar_module.active_dims = torch.arange(full_feature_dim + 1)
130-
likelihood = (
131-
None # Constructed in MultiTaskGP.
132-
if full_Yvar is not None
133-
else get_gaussian_likelihood_with_gamma_prior()
134-
)
127+
likelihood = None # Constructed in MultiTaskGP.
135128
super().__init__(
136129
train_X=full_X,
137130
train_Y=full_Y,

test/models/test_heterogeneous_mtgp.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from botorch.utils.testing import BotorchTestCase
1414
from gpytorch.distributions.multivariate_normal import MultivariateNormal
1515
from gpytorch.kernels import IndexKernel, ProductKernel
16+
from gpytorch.likelihoods.gaussian_likelihood import FixedNoiseGaussianLikelihood
17+
from gpytorch.likelihoods.hadamard_gaussian_likelihood import HadamardGaussianLikelihood
1618

1719

1820
class TestHeterogeneousMTGP(BotorchTestCase):
@@ -96,7 +98,7 @@ def test_input_constructor(self) -> None:
9698
self.assertIsNone(model_inputs["rank"])
9799

98100
def test_standard_heterogeneous_mtgp(self) -> None:
99-
# Construct the model.
101+
# Construct the model (inferred noise: train_Yvars is None).
100102
model_inputs = HeterogeneousMTGP.construct_inputs(training_data=self.mtds)
101103
model = HeterogeneousMTGP(**model_inputs)
102104
self.assertEqual(model.train_inputs[0].shape, torch.Size([10, 6]))
@@ -113,6 +115,13 @@ def test_standard_heterogeneous_mtgp(self) -> None:
113115
data_covar_module.binary_map, [[1, 1, 0], [1, 0, 0], [1, 0, 1]]
114116
)
115117

118+
with self.subTest("inferred_noise_uses_hadamard_likelihood"):
119+
self.assertIsInstance(model.likelihood, HadamardGaussianLikelihood)
120+
# HadamardGaussianLikelihood should have per-task noise parameters.
121+
self.assertEqual(
122+
model.likelihood.noise_covar.noise.shape[-1], model.num_tasks
123+
)
124+
116125
# Evaluate the posterior.
117126
with self.assertRaisesRegex(UnsupportedError, "output_indices"):
118127
model.posterior(self.ds1.X, output_indices=[0, 1])
@@ -147,6 +156,25 @@ def test_standard_heterogeneous_mtgp(self) -> None:
147156
self.assertIsInstance(posterior.distribution, MultivariateNormal)
148157
self.assertEqual(posterior.mean.shape, torch.Size([5, 1]))
149158

159+
def test_fixed_noise_likelihood(self) -> None:
160+
datasets = [
161+
SupervisedDataset(
162+
X=ds.X,
163+
Y=ds.Y,
164+
Yvar=torch.full_like(ds.Y, 0.1 * (i + 1)),
165+
feature_names=ds.feature_names,
166+
outcome_names=ds.outcome_names,
167+
)
168+
for i, ds in enumerate([self.ds1, self.ds2, self.ds3])
169+
]
170+
mtds = MultiTaskDataset(
171+
datasets=datasets, target_outcome_name="task0", task_feature_index=-1
172+
)
173+
model = HeterogeneousMTGP(
174+
**HeterogeneousMTGP.construct_inputs(training_data=mtds)
175+
)
176+
self.assertIsInstance(model.likelihood, FixedNoiseGaussianLikelihood)
177+
150178
def test_identical_search_space(self) -> None:
151179
# Check that the model works fine with identical search spaces.
152180
mtds = MultiTaskDataset(

0 commit comments

Comments
 (0)