0

I'm trying to understand how to extract the individual kernels from a GPRegression object similar to how the Birthday problem is approached in BDA3. Using the example from Pyro's documentation:

X = torch.linspace(-5, 5, 100)
y = torch.sin(X * 8) + 2 * X + 4 + 0.2 * torch.rand_like(X)
plt.scatter(X, y)
plt.show()

enter image description here

pyro.clear_param_store()
linear = gp.kernels.Linear(
    input_dim=1,
)
periodic = gp.kernels.Periodic(
    input_dim=1, period=torch.tensor(0.5), lengthscale=torch.tensor(4.0)
)
rbf = gp.kernels.RBF(
    input_dim=1, lengthscale=torch.tensor(0.5), variance=torch.tensor(0.5)
)
k1 = gp.kernels.Product(kern0=rbf, kern1=periodic)

k = gp.kernels.Sum(linear, k1)
model = gp.models.GPRegression(
    X=X,
    y=y,
    kernel=k,
    jitter=2e-3,
)

loss = gp.util.train(model)

So we can verify that our model is fitting correcty.

plt.scatter(X, y, s=50, alpha=0.5)

with torch.no_grad():
    mean, var = model(X)
_ = plt.plot(X, mean, color="C3", lw=2)

enter image description here

Now the question becomes, "How do I extract the periodic kernel alone?" According to BDA3:

enter image description here

But when I try to calculate the Linear Kernel this way, I get back garbage.

linear.forward(X) @ torch.linalg.inv(k.forward(X)) @ torch.tensor(y)

Any ideas?

JBlaz
  • 81
  • 1
  • 4

0 Answers0