Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Unexpected behavior setting kernel priors #2514

Open
ruhanaazam opened this issue Apr 24, 2024 · 1 comment
Open

[Docs] Unexpected behavior setting kernel priors #2514

ruhanaazam opened this issue Apr 24, 2024 · 1 comment

Comments

@ruhanaazam
Copy link

Hi, I'm interested in setting better priors on my GP kernel. I am unsure if I am setting the priors correctly. Below are two ways I have tried to set the kernel priors. I expect both to behave the same but when I fit my GP, I find that cov_module1 works significantly better than covar_module2. Is there a reason for this behavior?

lengthscale_prior = gpytorch.priors.GammaPrior(3.0, 6.0)
outputscale_prior = gpytorch.priors.GammaPrior(2.0, 0.15)

covar_module1 = ScaleKernel(
    MaternKernel(
        nu=nu,
        ard_num_dims=2,
        lengthscale_prior=lengthscale_prior,
    ),
    outputscale_prior=outputscale_prior,
)

covar_module2 = ScaleKernel(
    MaternKernel(
        nu=nu,
        ard_num_dims=2,
    ),
)
covar_module2.base_kernel.lengthscale_prior = lengthscale_prior
covar_module2.outputscale_prior = outputscale_prior

Expected Behavior
cov_module1 and cov_module2 to perform similarly when they are used to fit a SingleTaskGP.

System information
Please complete the following information:
GPyTorch: 1.10
Pytorch: 2.0.1
Ubuntu 20.04
Python: 3.10

Fyi, this is a repeat issue from pytorch/botorch#2307.

@Balandat
Copy link
Collaborator

You can't just assign the attribute for the prior, you need to use the register_prior() method on the GPyTorch module so that gpytorch knows to use this in the computations for the MLL. In your setup for covar_module2 I don't think that prior is ever being used.

See e.g. https://github.com/cornellius-gp/gpytorch/blob/master/gpytorch/kernels/kernel.py#L205-L207 for how this is done in the Kernel.__init__() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants