Search code examples
gpflow

Initialize GPFlow model with empty X and Y


I'm using GPFlow for multidimensional regression and want to compare various kernels starting with an empty X and Y set. But it seems that the library needs set containing value pairs. I thought about initializing with a point far away from my input space but that point would be included when optimizing my hyper-parameters. Is there any solution I'm missing or workaround?

Thanks for your help!

This is some standard code to initialize my model:

import gpflow
k = gpflow.kernels.RBF(input_dim=1, lengthscales=1, variance=1)
x_sample = np.array([])
y_sample = np.array([])
model = gpflow.models.GPR(x_sample, y_sample, kern=k)

which leads to the following error:

IndexError: tuple index out of range

And the following snippet leads to:

model = gpflow.models.GPR(kern=k)
TypeError: __init__() missing 2 required positional arguments: 'X' and 'Y'

It would be great if someone had an idea what I could do to initialize my model with an empty set


Solution

  • The library can deal with an empty X and Y set - but you have to respect the required shapes. Both X and Y need to have ndim=2. When writing x_sample = np.array([]), then x_sample.shape == (0,) and x_sample.ndim == 1. Instead, set x_sample = np.empty((0, 2)) (and likewise y_sample = np.empty((0, 2)), then ndim=2 and their shape is (0, 2) as required.

    (Obviously with no data it does not make sense to optimize your hyperparameters, and there isn't anything you can do with the model, really; if you want to just compare kernels you don't need to construct a model to compute the kernel matrices... but that depends more specifically on what you want to achieve!)