Skip to content

Commit

Permalink
Fix pathwise sampler bug (#2337)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #2337

`_draw_matheron_paths_ExactGP` calls `_gaussian_update_ExactGP` (as the update_strategy argument). It was passing an incorrect argument `train_targets` in place of `target_values`. This led the `Y` values to being silently ignored.

Reviewed By: saitcakmak

Differential Revision: D57175013

fbshipit-source-id: f3a1c304ee221d1460284b51f423af894c7c6a9f
  • Loading branch information
esantorella authored and facebook-github-bot committed May 9, 2024
1 parent 07f12b7 commit 6600655
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion botorch/sampling/pathwise/posterior_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _draw_matheron_paths_ExactGP(
update_paths = update_strategy(
model=model,
sample_values=sample_values,
train_targets=train_Y,
target_values=train_Y,
)

return MatheronPath(
Expand Down
1 change: 0 additions & 1 deletion botorch/sampling/pathwise/update_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def _gaussian_update_ExactGP(
points: Optional[Tensor] = None,
noise_covariance: Optional[Union[Tensor, LinearOperator]] = None,
scale_tril: Optional[Union[Tensor, LinearOperator]] = None,
**ignore: Any,
) -> GeneralizedLinearPath:
if points is None:
(points,) = get_train_inputs(model, transformed=True)
Expand Down
18 changes: 18 additions & 0 deletions test/sampling/pathwise/test_update_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from botorch.utils.testing import BotorchTestCase
from gpytorch.kernels import MaternKernel, RBFKernel, ScaleKernel
from gpytorch.likelihoods import BernoulliLikelihood
from gpytorch.models import ExactGP
from linear_operator.operators import ZeroLinearOperator
from linear_operator.utils.cholesky import psd_safe_cholesky
from torch import Size
Expand Down Expand Up @@ -204,3 +205,20 @@ def _test_gaussian_updates(self, model):
with patch.object(model, "likelihood", new=BernoulliLikelihood()):
with self.assertRaises(NotImplementedError):
gaussian_update(model=model, sample_values=sample_values)

with self.subTest("Exact models with `None` target_values"):
assert isinstance(model, ExactGP)
torch.manual_seed(0)
path_none_target_values = gaussian_update(
model=model,
sample_values=sample_values,
)
torch.manual_seed(0)
path_with_target_values = gaussian_update(
model=model,
sample_values=sample_values,
target_values=get_train_targets(model, transformed=True),
)
self.assertAllClose(
path_none_target_values.weight, path_with_target_values.weight
)

0 comments on commit 6600655

Please sign in to comment.