You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I try to model a two-output problem using a single ExactGP with two kernel functions. As such, the resulting kernel matrix is the block diagonal matrix of the two individual kernel matrices. This is the corresponding code:
classIndependentModel(gpytorch.models.ExactGP):
""" Class models a multi-output setting with multiple separate kernels with no cross-correlation. As such, the kernel matrix is a block diagonal matrix. """def__init__(self, train_x, train_y, likelihood, num_tasks):
super().__init__(train_x, train_y, likelihood)
self.mean_modules=ModuleList([
gpytorch.means.ZeroMean() for_inrange(num_tasks)
])
self.covar_modules=ModuleList([
gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel()) for_inrange(num_tasks)
])
defforward(self, x, i):
# Order samples by ascending task indexi=i.squeeze() # remove the last dimension added by GPyTorchorder=torch.argsort(i, stable=True)
x_ordered=x[order]
unorder=torch.arange(len(x))[order] # create a reverse mapping# Calculate offsets of task indices in the datanum_tasks=len(self.mean_modules)
task_offsets=torch.cumsum(torch.tensor(
[torch.tensor(0)] + [torch.count_nonzero(torch.eq(i, task)) fortaskinrange(num_tasks)]
), 0)
# Calculate and concatenate meansmean_x=torch.cat([
self.mean_modules[task](x_ordered[task_offsets[task] : task_offsets[task+1]]).to_dense() fortaskinrange(num_tasks)
])[unorder]
# Calculate and concatenate covariancescovar_x=torch.block_diag(*[
self.covar_modules[task](x_ordered[task_offsets[task] : task_offsets[task+1]]).to_dense() fortaskinrange(num_tasks)
])[unorder, :][:, unorder]
# Return final distributionreturnMultivariateNormal(mean_x, linear_operators.to_linear_operator(covar_x))
See here for a full example on a synthetic dataset. Note that the Plotly plots only render if you open the notebook in JupyterLab and not on GitHub. As you can see there, this implementation does not work. If I simultaneously ask for predictions for both tasks, I get different results than if I ask for predictions per task.
I think this is a numerical stability problem caused by the first process not properly converging (cf. plots at the end). However, I cannot find the actual problem that causes this. Maybe one of you can help me with finding the root cause here?
I am aware that I could use the model list implemented in GPyTorch, but as I want to move on to correlated outputs, I first want to get this simple example working.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I try to model a two-output problem using a single
ExactGP
with two kernel functions. As such, the resulting kernel matrix is the block diagonal matrix of the two individual kernel matrices. This is the corresponding code:See here for a full example on a synthetic dataset. Note that the Plotly plots only render if you open the notebook in JupyterLab and not on GitHub. As you can see there, this implementation does not work. If I simultaneously ask for predictions for both tasks, I get different results than if I ask for predictions per task.
I think this is a numerical stability problem caused by the first process not properly converging (cf. plots at the end). However, I cannot find the actual problem that causes this. Maybe one of you can help me with finding the root cause here?
I am aware that I could use the model list implemented in GPyTorch, but as I want to move on to correlated outputs, I first want to get this simple example working.
Beta Was this translation helpful? Give feedback.
All reactions