|
37 | 37 |
|
38 | 38 |
|
39 | 39 | class TestSingleTaskGP(BotorchTestCase): |
| 40 | + model_class = SingleTaskGP |
| 41 | + |
40 | 42 | def _get_model_and_data( |
41 | 43 | self, |
42 | 44 | batch_shape, |
@@ -372,8 +374,33 @@ def test_set_transformed_inputs(self): |
372 | 374 | tf_X = intf(X) |
373 | 375 | self.assertEqual(X.shape, tf_X.shape) |
374 | 376 |
|
| 377 | + def test_empty_inputs(self): |
| 378 | + empty_inputs = torch.ones(0, 2) |
| 379 | + kwargs = { |
| 380 | + "train_X": empty_inputs, |
| 381 | + "train_Y": empty_inputs, |
| 382 | + } |
| 383 | + if self.model_class is not SingleTaskGP: |
| 384 | + kwargs["train_Yvar"] = empty_inputs |
| 385 | + model = self.model_class(**kwargs) |
| 386 | + mll = ExactMarginalLogLikelihood(model.likelihood, model) |
| 387 | + fit_gpytorch_model(mll) |
| 388 | + X_prediction = torch.rand(3, 4, 2) |
| 389 | + with torch.no_grad(): |
| 390 | + posterior = model.posterior(X_prediction) |
| 391 | + samples = posterior.rsample(sample_shape=torch.Size([5])) |
| 392 | + self.assertEqual(samples.shape, torch.Size([5, 3, 4, 2])) |
| 393 | + expected_mean = torch.zeros_like(posterior.mean) |
| 394 | + expected_var = torch.full_like( |
| 395 | + posterior.variance, fill_value=model.covar_module.outputscale[0].detach() |
| 396 | + ) |
| 397 | + assert torch.equal(posterior.mean, expected_mean) |
| 398 | + assert torch.equal(posterior.variance, expected_var) |
| 399 | + |
375 | 400 |
|
376 | 401 | class TestFixedNoiseGP(TestSingleTaskGP): |
| 402 | + model_class = FixedNoiseGP |
| 403 | + |
377 | 404 | def _get_model_and_data( |
378 | 405 | self, |
379 | 406 | batch_shape, |
@@ -436,6 +463,8 @@ def test_construct_inputs(self): |
436 | 463 |
|
437 | 464 |
|
438 | 465 | class TestHeteroskedasticSingleTaskGP(TestSingleTaskGP): |
| 466 | + model_class = HeteroskedasticSingleTaskGP |
| 467 | + |
439 | 468 | def _get_model_and_data( |
440 | 469 | self, batch_shape, m, outcome_transform=None, input_transform=None, **tkwargs |
441 | 470 | ): |
|
0 commit comments