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 want to fit a Deep GP on step data, so I am using the method shown in GPflux tutorial on the motorcycle dataset. But the fit is not as expected, as shown in Prof.Neil Lawerence's blog. I can fit using PyDeepGP. I have attached the code used by me in GPflux and PyDeepGP
try:
importdeepgpexceptModuleNotFoundError:
%pipinstallgit+https://github.com/SheffieldML/PyDeepGP.gitimportdeepgptry:
importGPyexceptModuleNotFoundError:
%pipinstall -qqGPyimportGPytry:
importtinygpexceptModuleNotFoundError:
%pipinstall -qtinygpimporttinygpimportseabornassnsimportjaximportjax.numpyasjnpimportmatplotlib.pyplotaspltfromtinygpimportkernels,GaussianProcessfromjax.configimportconfigimportnumpyasnptry:
importjaxoptexceptModuleNotFoundError:
%pipinstalljaxoptimportjaxoptconfig.update("jax_enable_x64",True)num_low=25num_high=25gap= -0.1noise=0.0001x=jnp.vstack((jnp.linspace(-1, -gap / 2.0,num_low)[:,jnp.newaxis],jnp.linspace(gap / 2.0,1,num_high)[:,jnp.newaxis])).reshape(
-1,)y=jnp.vstack((jnp.zeros((num_low,1)),jnp.ones((num_high,1))))scale=jnp.sqrt(y.var())offset=y.mean()yhat=((y - offset) / scale).reshape(
-1,)xnew=jnp.vstack((jnp.linspace(-2, -gap / 2.0,25)[:,jnp.newaxis],jnp.linspace(gap / 2.0,2,25)[:,jnp.newaxis])).reshape(
-1,)num_hidden=3latent_dim=1kernels=[*[GPy.kern.RBF(latent_dim,ARD=True)] * num_hidden]# hidden kernelskernels.append(GPy.kern.RBF(np.array(x.reshape(-1,1)).shape[1]))# we append a kernel for the input layerm=deepgp.DeepGP([y.reshape(-1,1).shape[1], *[latent_dim] * num_hidden,x.reshape(-1,1).shape[1]],X=np.array(x.reshape(-1,1)),# training inputY=np.array(y.reshape(-1,1)),# training outoutinits=[*["PCA"] * num_hidden,"PCA"],# initialise layerskernels=kernels,num_inducing=x.shape[0],back_constraint=False,)m.initialize_parameter()defoptimise_dgp(model,messages=True):
"""Utility function for optimising deep GP by first reinitiailising the Gaussian noise at each layer (for reasons pertaining to stability) """model.initialize_parameter()forlayerinmodel.layers:
layer.likelihood.variance.constrain_positive(warning=False)layer.likelihood.variance=1.0# small variance may cause collapsemodel.optimize(messages=messages,max_iters=10000)optimise_dgp(m,messages=True)mu_dgp,var_dgp=m.predict(xnew.reshape(-1,1))plt.figure()latexify(width_scale_factor=2,fig_height=1.75)plt.plot(xnew,mu_dgp,"blue")plt.scatter(x,y,c="r",s=marksize)plt.fill_between(xnew.flatten(),mu_dgp.flatten() - 1.96 * jnp.sqrt(var_dgp.flatten()),mu_dgp.flatten() + 1.96 * jnp.sqrt(var_dgp.flatten()),alpha=0.3,color="C1",)sns.despine()legendsize=4.5ifis_latexify_enabled()else9plt.legend(labels=["Mean","Data","Confidence"],loc=2,prop={"size": legendsize},frameon=False)plt.xlabel("$x$")plt.ylabel("$y$")sns.despine()plt.show()
Plot obtained from above code
System information
OS: Ubuntu 20.04.2 LTS
Python version: 3.10.4
GPflux version: 0.3.0
TensorFlow version: 2.8.2
GPflow version: 2.5.2
The text was updated successfully, but these errors were encountered:
This is actually a difference in the models - the DGP model used in PyDeepGP is from Damianou and Lawrence (2013) and uses latent variables in the intermediate layers, whereas the model we follow is from Salimbeni and Deisenroth (2017), and doesn't use latent variables. This means that the fits will be different. However, you should be able to get similar fits (but not exactly the same) using GPflux by following the tutorial https://secondmind-labs.github.io/GPflux/notebooks/deep_cde.html
Describe the bug
I want to fit a Deep GP on step data, so I am using the method shown in GPflux tutorial on the motorcycle dataset. But the fit is not as expected, as shown in Prof.Neil Lawerence's blog. I can fit using PyDeepGP. I have attached the code used by me in GPflux and PyDeepGP
To reproduce
Steps to reproduce the behaviour:
GPflux Implementation
```Plot obtained as a result of the above code:
Expected behaviour
PyDeepGP Implementation
```Plot obtained from above code
System information
The text was updated successfully, but these errors were encountered: