From 5c8b8ae9296395d13a3df37ff8da0aa53bd7bdd9 Mon Sep 17 00:00:00 2001 From: Vitaly Zankin Date: Fri, 10 May 2024 08:19:26 -0700 Subject: [PATCH] Remove correlation between the step size and the step direction (#2156) (#2290) Summary: ## Motivation This is a quick fix of https://github.com/pytorch/botorch/issues/2156. In the ```botorch.utils.sampling.sample_polytope()```, both the step size ```rands``` and direction ```Rs``` are currently sampled using the same seed value. This can lead to strong correlation and induce sampling bias, particularly with a small number of steps (e.g., ```n=1```), as illustrated in https://github.com/pytorch/botorch/issues/2156. Adding ```+1``` to the seed value for ```Rs``` helps to avoid such behaviour. ### Have you read the [Contributing Guidelines on pull requests](https://github.com/pytorch/botorch/blob/main/CONTRIBUTING.md#pull-requests)? Yes. Pull Request resolved: https://github.com/pytorch/botorch/pull/2290 Test Plan: Not sure if any unit tests needed for that change. Reviewed By: esantorella Differential Revision: D57208858 Pulled By: Balandat fbshipit-source-id: 0653e751f4351a8f9ad2cf2625c93a3a5de7de63 --- botorch/utils/sampling.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/botorch/utils/sampling.py b/botorch/utils/sampling.py index 6dcf7eac8e..ce6a4de6b6 100644 --- a/botorch/utils/sampling.py +++ b/botorch/utils/sampling.py @@ -249,8 +249,9 @@ def sample_polytope( # pre-sample samples from hypersphere d = x0.size(0) # uniform samples from unit ball in d dims + # increment seed by +1 to avoid correlation with step size, see #2156 for details Rs = sample_hypersphere( - d=d, n=n_tot, dtype=A.dtype, device=A.device, seed=seed + d=d, n=n_tot, dtype=A.dtype, device=A.device, seed=seed + 1 ).unsqueeze(-1) # compute matprods in batch