Skip to content

[Question] Setting a constraint for the ConstantMean() #2074

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

Closed
vr308 opened this issue Jul 21, 2022 · 2 comments · Fixed by #2082
Closed

[Question] Setting a constraint for the ConstantMean() #2074

vr308 opened this issue Jul 21, 2022 · 2 comments · Fixed by #2082

Comments

@vr308
Copy link
Contributor

vr308 commented Jul 21, 2022

Hi - I am trying to set a GreaterThan() constraint for the constant of the mean_module -- which I thought is trival following the examples from the docs, but unfortunately, the training doesn't seem to obey it.

class ExactGPModel(gpytorch.models.ExactGP):
    
    def __init__(self, train_x, train_y, likelihood, kernel):
        super(ExactGPModel, self).__init__(train_x, train_y, likelihood)
        self.mean_module = gpytorch.means.ConstantMean(constant_constraint=gpytorch.constraints.GreaterThan(0.5))
        self.covar_module = kernel

    def forward(self, x):
        mean_x = self.mean_module(x)
        covar_x = self.covar_module(x)
        return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)
   model = ExactGPModel(train_x, train_y, likelihood, kernel).double().cuda()
   model.mean_module.register_constraint('constant', gpytorch.constraints.GreaterThan(0.5))
  

Anything missing here?

Upon some digging, I noticed that the constant mean is slightly different to the other hyperparameters which are tensors while the constant mean is a Parameter -- could that be it?

model.likelihood.noise
tensor([0.2515], device='cuda:0', dtype=torch.float64, grad_fn=<AddBackward0>)
model.mean_module.constant
Parameter containing:
tensor([0.0770], device='cuda:0', dtype=torch.float64, requires_grad=True)


@gpleiss
Copy link
Member

gpleiss commented Jul 26, 2022

Hmm this is unexpected... I'll dig into that.

gpleiss added a commit that referenced this issue Jul 27, 2022
@gpleiss
Copy link
Member

gpleiss commented Jul 27, 2022

Turns out ConstantMean never supported constraints, but I'll put up a PR to fix that!

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

Successfully merging a pull request may close this issue.

2 participants