botorch icon indicating copy to clipboard operation
botorch copied to clipboard

Sobol sampling isn't independent across multiple posteriors

Open pvasu opened this issue 11 months ago • 1 comments

Discussed in https://github.com/pytorch/botorch/discussions/2655

Originally posted by pvasu December 16, 2024

Sobol sampling doesn't work properly on a PosteriorList: sobol base samples are built separately for each posterior, but they aren't independent.

Here's an example:

import matplotlib.pyplot as plt
import torch
from botorch.posteriors import GPyTorchPosterior, PosteriorList
from gpytorch.distributions.multivariate_normal import MultivariateNormal
from botorch.sampling import get_sampler

mvns = [
    MultivariateNormal(torch.tensor([0.0]), torch.tensor([[1.0]])) for _ in range(2)
]
posterior = PosteriorList(*[GPyTorchPosterior(mvn) for mvn in mvns])

sampler = get_sampler(posterior, torch.Size([512]))
samples = sampler(posterior).squeeze()

plt.scatter(samples[:, 0], samples[:, 1])

image

Whereas in an older version of Botorch, 0.6.6, constructing a Sobol sampler on a posterior list works properly:

from botorch.sampling import SobolQMCNormalSampler

sampler = SobolQMCNormalSampler(512)
samples = sampler(posterior).squeeze()

plt.scatter(samples[:, 0], samples[:, 1])

image

As @saitcakmak pointed out in this discussion, the problem boils down to two sobol sequences produced by draw_sobol_normal_samples not being independent.

pvasu avatar Dec 23 '24 21:12 pvasu

Any updates on this? Will it be fixed, or should we look for a workaround?

MrEarle avatar May 18 '25 02:05 MrEarle

Fixed by #2977

saitcakmak avatar Sep 05 '25 18:09 saitcakmak

Not sure #2977 fixes the issue. It does fall back to IID sampling, but removing sobol support for posterior lists.

MrEarle avatar Sep 24 '25 20:09 MrEarle