{"action":"opened","issue":{"url":"https://api.github.com/repos/GPflow/GPflow/issues/421","repository_url":"https://api.github.com/repos/GPflow/GPflow","labels_url":"https://api.github.com/repos/GPflow/GPflow/issues/421/labels{/name}","comments_url":"https://api.github.com/repos/GPflow/GPflow/issues/421/comments","events_url":"https://api.github.com/repos/GPflow/GPflow/issues/421/events","html_url":"https://github.com/GPflow/GPflow/issues/421","id":232221301,"number":421,"title":"NaNs in predictions with Matern52 and Matern32 kernels","user":{"login":"rm4216","id":23243458,"avatar_url":"https://avatars2.githubusercontent.com/u/23243458?v=3","gravatar_id":"","url":"https://api.github.com/users/rm4216","html_url":"https://github.com/rm4216","followers_url":"https://api.github.com/users/rm4216/followers","following_url":"https://api.github.com/users/rm4216/following{/other_user}","gists_url":"https://api.github.com/users/rm4216/gists{/gist_id}","starred_url":"https://api.github.com/users/rm4216/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rm4216/subscriptions","organizations_url":"https://api.github.com/users/rm4216/orgs","repos_url":"https://api.github.com/users/rm4216/repos","events_url":"https://api.github.com/users/rm4216/events{/privacy}","received_events_url":"https://api.github.com/users/rm4216/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-05-30T11:24:39Z","updated_at":"2017-05-30T11:24:39Z","closed_at":null,"body":"Dear all\r\n\r\nI have been using the GPR regression model to make posterior predictions with Gaussian likelihood using Matern52, and Matern32 kernels. However, with a particular set of 3-dimensional pints and a particular choice of lengthscales I obtained all NaNs on posterior mean and variance, both for isotropic and ARD version of each kernel. Here is the code that should reproduce the issue. (I also modified the Matern52 kernel to be able to obtain numerical values of the covariance matrix \"npK52_iso\" and \"npK52_ARD\", I did not apply any modification to Matern32)\r\n# Dataset\r\n```pythonscript\r\nimport numpy as np\r\nimport tensorflow as tf\r\nimport GPflow\r\n\r\nfull_dim = 3\r\n# Five data points in 3 dimensions\r\nD_X = np.array([\r\n [31.55437035,  31.55437038,  32.36345678],\r\n [31.55437037,  31.55437037,  32.36345679],\r\n [31.55437037,  31.55437037,  32.36345679],\r\n [28.31802469,  21.84533348, -29.12711068],\r\n [28.31802469,  21.84533348, -29.12711111],\r\n])\r\n# Trying with different dataset does not show any problem\r\n# D_X = np.random.uniform(-32, 32, 5*full_dim).reshape(-1, full_dim)\r\n\r\nY = np.random.uniform(2, 7, D_X.shape[0]).reshape(-1, 1)    # any random choice\r\nX_test = np.random.uniform(-32, 32, 10*full_dim).reshape(-1, full_dim)  # random test set\r\n```\r\n# Matern52 tests\r\n```pythonscript\r\n# Matern52 test isotropic\r\nkernel52_iso = GPflow.kernels.Matern52(input_dim=3, ARD=False)\r\nkernel52_iso.lengthscales._array = np.array([0.01095283])     # critical lengthscale\r\n\r\nGPmodel = GPflow.gpr.GPR(D_X, Y, kernel52_iso)\r\nmean52_iso, vars52_iso = GPmodel.predict_f(X_test)  # posterior mean is all nan\r\n\r\nK52_iso = kernel52_iso.K(D_X)\r\ngg = K52_iso.graph\r\nsess = tf.InteractiveSession(graph=gg)\r\nnpK52_iso = K52_iso.eval(session=sess)  # Covariance matrix contains nan\r\n\r\n# Matern52 test ARD\r\nkernel52_ARD = GPflow.kernels.Matern52(input_dim=3, ARD=True)\r\nkernel52_ARD.lengthscales._array = np.array([0.01095283, 0.01095283, 0.01095283])     # critical lengthscales\r\n\r\nGPmodel = GPflow.gpr.GPR(D_X, Y, kernel52_ARD)\r\nmean52_ARD, vars52_ARD = GPmodel.predict_f(X_test)\r\n\r\nK52_ARD = kernel52_ARD.K(D_X)\r\ngg = K52_ARD.graph\r\nsess = tf.InteractiveSession(graph=gg)\r\nnpK52_ARD = K52_ARD.eval(session=sess)\r\n```\r\n# Matern32 tests\r\n```pythonscript\r\n# Matern32 test isotropic\r\nkernel32_iso = GPflow.kernels.Matern32(input_dim=3, ARD=False)\r\nkernel32_iso.lengthscales._array = np.array([0.01095283])\r\n\r\nGPmodel = GPflow.gpr.GPR(D_X, Y, kernel32_iso)\r\nmean32_iso, vars32_iso = GPmodel.predict_f(X_test)\r\n\r\n# Matern32 test ARD\r\nkernel32_ARD = GPflow.kernels.Matern32(input_dim=3, ARD=True)\r\nkernel32_ARD.lengthscales._array = np.array([0.01095283, 0.01095283, 0.01095283])\r\n\r\nGPmodel = GPflow.gpr.GPR(D_X, Y, kernel32_ARD)\r\nmean32_ARD, vars32_ARD = GPmodel.predict_f(X_test)\r\n```\r\nIf I try with a slightly different dataset or different lengthscales, NaNs do not appear, and predictions return normal numerical values. I could not understand what may be going wrong with these predictions. The only thing I noticed is that the numerical covariance matrices \"npK52_iso\", and \"npK52_ARD\" contain NaNs outside the diagonal, and that, using RBF kernel, predictions return numerical values.\r\n\r\nCan you reproduce this problem? Am I missing something in the implementation?\r\n\r\nThank you!\r\n"}}
{"actor":{"display_login":"rm4216"}}