Closed yzshi5 closed 1 month ago
There is a bug in your reprodicible example:
base_dist = torch.distributions.MultivariateNormal(base_mu.to(device), scale_tril=torch.linalg.cholesky_ex(base_cov.to(device))[0])
You shouldn't have a [0]
after the cholesky factor; that only grabs the first row of the Cholesky factor. If you remove the [0]
your samples will look more identical.
Given that you are computing samples in the domain [0, 1] x [0, 1]
, I would expect the values that GPyTorch produces even with a lengthscale of 0.01. It shouldn't look like white noise until the lengthscale is much smaller. (You can verify this by noticing that the gpytorch covariance matrix - which is identical to the sklearn covariance matrix - is far from the identity and therefore not white noise).
Hi Geoff, thanks for your timely reply, torch.linalg.cholesky_ex(base_cov.to(device))
return a Lower triangle and info
torch.linalg.cholesky_ex(base_cov.to(device))
L=tensor([[1.0000e+00, 0.0000e+00, 0.0000e+00, ..., 0.0000e+00, 0.0000e+00,
0.0000e+00],
[9.6847e-01, 2.4913e-01, 0.0000e+00, ..., 0.0000e+00, 0.0000e+00,
0.0000e+00],
[8.9432e-01, 4.1083e-01, 1.7725e-01, ..., 0.0000e+00, 0.0000e+00,
0.0000e+00],
...,
[8.4983e-10, 7.9180e-10, 7.7648e-10, ..., 9.7107e-02, 0.0000e+00,
0.0000e+00],
[7.0670e-10, 6.6394e-10, 6.5171e-10, ..., 9.4278e-02, 9.7856e-02,
0.0000e+00],
[5.8675e-10, 5.5572e-10, 5.4600e-10, ..., 6.0951e-02, 1.0021e-01,
1.0890e-01]], device='cuda:1'),
info=tensor(0, device='cuda:1', dtype=torch.int32))
so [0]
just extract the L matrix. If we remove [0]
, we will receive errors
The other thing is if we look at the histogram of the pointwise distribution of the generated samples, it shouldn't be bounded to [-1, 1]. and for all matern kernels, if the variance of the kernel is 1, we expect to see the autocovariance at position 0 is 1.
Your bug needs to be more specific. Do you think the issue is with the sampling code, or with computing the covariance matrix? From what I can see, the sklearn and the gpytorch matern kernel functions return identical covariance matrices, so that's not the source of the bug. Please try to make your reproducible example as small as possible.
🐛 Bug
When I worked on creating a Gaussian Process (GP) with a Matern kernel to sample from it, I found it was incorrect. I validated it against the ground truth.
To reproduce
Code snippet to reproduce
Stack trace/error message
Expected Behavior
The autocovariance at position 0 supposed to be 1, when lengthscale is smooth enough, we expect to get the pattern similar to white noise.
System information
Please complete the following information:
Additional context
Add any other context about the problem here.