1

I am trying to implement GP regression using Poisson likelihood. I followed the example in GPy by doing

poisson_likelihood = GPy.likelihoods.Poisson()
laplace_inf = GPy.inference.latent_function_inference.Laplace()
m = GPy.core.GP(X=X, Y=Y, likelihood=poisson_likelihood, inference_method=laplace_inf, kernel=kernel)
m.optimize()
#for ploting
pred_points = np.linspace(300,800,1000)[:, None]
#Predictive GP for log intensity mean and variance
f_mean, f_var = m._raw_predict(pred_points)
f_upper, f_lower = f_mean + 2*np.sqrt(f_var), f_mean - 2.*np.sqrt(f_var)
pb.figure(figsize=(10, 13))
pb.plot(pred_points, np.exp(f_mean), color='blue', lw=2)
pb.fill_between(pred_points[:,0], np.exp(f_lower[:,0]), np.exp(f_upper[:,0]), color='blue', alpha=.1)
pb.errorbar(Xc.flatten(), Yc.flatten(), dyc, fmt='.', color='k',markersize=8,alpha=1.0, label='Data')

When I tried to do the same using GPflow, I implemented in the following way

poisson_likelihood = gpflow.likelihoods.Poisson()
m = gpflow.models.VGP((X, Y), kernel=k, likelihood=poisson_likelihood, num_latent_gps=1)
opt = gpflow.optimizers.Scipy()
opt_logs = opt.minimize(m.training_loss, m.trainable_variables, options=dict(maxiter=100))
#for ploting
xx = np.linspace(300, 800, 100).reshape(100, 1)
mean, var = m.predict_f(xx)
plt.plot(X, Y, "kx", mew=2)
plt.plot(xx, np.exp(mean), "C0", lw=2)
plt.fill_between(
    xx[:, 0],
    np.exp(mean[:, 0] - 1.96 * np.sqrt(var[:, 0])),
    np.exp(mean[:, 0] + 1.96 * np.sqrt(var[:, 0])),
    color="C0",
    alpha=0.2,
)

When I implemented this using GP flow, the hyper parameters did not move from initialized values. Also, I am getting very different results, am I doing something wrong?

Result with GPflow

Result with GPy

1
  • 1
    It's hard to help figuring out why it might not work as expected without it being a minimal reproducible example. Note that in GPy, you are using Laplace approximation, whereas in GPflow you are using a variational approximation - though I would expect the hyperparameters to move in the latter, too. Commented Feb 28, 2022 at 11:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.