-
Notifications
You must be signed in to change notification settings - Fork 563
[Docs] Implementing Custom mean function documentation #674
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
Comments
You can find some examples here: https://github.com/cornellius-gp/gpytorch/tree/5411c905b778280122e2524fc4aafd13cdc7270d/gpytorch/means. Basically you just need to define how to initialize the |
Something like this
would learn a different affine mean for each batch dimension. |
Thanks, Alex. Worth noting: just doing a matmul between n x d input x and d x 1 weight matrix w would also work -- the einsum seems overkill here, since matmul will broadcast over any batch dimensions just fine :-). If there's still some confusion about this let us know and I'll try to give a few other examples. |
I am still a little confused as to how to use gpytorch means. I want to implement a constant mean of 5, but I don't understand how to specify that in the Constant Mean or if I have to implement a custom mean for that. |
@dtort For that just use the constant mean, initialize the constant to self.mean_module = ConstantMean()
self.mean_module.initialize(constant=5.)
self.mean_module.constant.requires_grad = False |
I would like to use neural network as the mean function, is this a valid implementation of mean function? class MLPMean(gp.means.Mean):
def __init__(self, dim):
super(MLPMean, self).__init__()
self.mlp = nn.Sequential(
nn.Linear(dim, 32),
nn.ReLU(),
nn.Linear(32, 1))
count = 0
for n, p in self.mlp.named_parameters():
self.register_parameter(name = 'mlp' + str(count), parameter = p)
count += 1
def forward(self, x):
m = self.mlp(x)
return m.squeeze() Is the |
@Alaya-in-Matrix Yep, that's valid. No need for the register_parameter -- that's how you register parameters to Modules in PyTorch. |
closing for now - reopen if there's still questions :) |
Hello, I apologize for the basic question, but I am sort of new to both GP’s and Torch, so would appreciate any help you can provide. Basically I have a 2D surface I’d like to fit but if it is easier, we can pretend it’s 1D. The challenge I have is that I have strong prior belief in the basic shape of this function and that the noise varies (in this case decreases as both axes grow). Ideally I’d like to specify a grid of values as priors and some noise around each point that is also custom. This is the only thread I’ve been able to define that shows anything about specifying the mean function and I’m about out of ideas. Can anyone help me? Thank you in advance, |
Hi @tniggs84 To encode a prior about the basic shape of the function, I might recommend taking your grid of points and fitting some interpolating model to the grid of points and using that as a mean function. If your function is well modeled by a kernel method (e.g., a GP) you might even consider kernel regression (e.g., first take your grid of points, fit a GP to them and use the mean prediction as a prior mean). To encode the noises that you know, try using a
This takes a If you have more questions about this, please open another issue so that it's easier to track. |
Thank you for your help @jacobrgardner! I did follow your directions and created a new issue (#1073 ). Can you please look at that as I still have some outstanding questions. Thank you! |
hello |
@Jahnvi99 can you please open up a discussion topic with your question? |
Sure, as u suggested I opened a discussion topic with my question! |
Hello, all. While Gaussian Processes are often described as not needing a mean (or only a zero, or constant one), that is not true, and being able to implement custom means would be incredibly useful.
I see in the docs that
gpytorch.means.Mean
seems to be set aside for this specific purpose, but there exists no explanation (or examples) demonstrating how to use it.Is there an obvious method of defining simple, custom means that I am not seeing? If not, I think a couple of basic examples would be helpful.
The text was updated successfully, but these errors were encountered: