question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue when calling gp.predictive_gradients()

See original GitHub issue

I am running Python v2.7.12 using Anaconda 64bit on Windows 7. I installed GPy using ‘pip install GPy’ to get version 1.5.6 which I have been using for a while on small problems without any issues. More, recently I have wanted to make use of the predictive_gradients() function but I have run into some issues.

Firstly, when I import GPy I get the following warning: “warning in stationary: failed to import cython module: falling back to numpy” which I have not thought too much of in the past since everything else seemed to work okay. Secondly, when I try and run the following code,

import numpy as np
import GPy as gp

k = gp.kern.RBF(input_dim=1, variance=1., lengthscale=1.)

X = np.random.uniform(-3.,3., (20,1))
Y = np.sin(X) + np.random.randn(20,1)*0.05

m = gp.models.GPRegression(X, Y, kernel=k)

grad = m.predictive_gradients(X)

I get the following error,

NameError                                 Traceback (most recent call last)
<ipython-input-10-964a0d158030> in <module>()
----> 1 m.predictive_gradients(X)

C:\Program Files\Anaconda2\lib\site-packages\GPy\core\gp.pyc in predictive_gradi
ents(self, Xnew, kern)
    335
    336         for i in range(self.output_dim):
--> 337             mean_jac[:,:,i] = kern.gradients_X(self.posterior.woodbury_v
ector[:,i:i+1].T, Xnew, self._predictive_variable)
    338
    339         # gradients wrt the diagonal part k_{xx}

C:\Program Files\Anaconda2\lib\site-packages\GPy\kern\src\kernel_slice_operation
s.pyc in wrap(self, dL_dK, X, X2)
    116     def wrap(self, dL_dK, X, X2=None):
    117         with _Slice_wrap(self, X, X2) as s:
--> 118             ret = s.handle_return_array(f(self, dL_dK, s.X, s.X2))
    119         return ret
    120     return wrap

C:\Program Files\Anaconda2\lib\site-packages\GPy\kern\src\stationary.pyc in grad
ients_X(self, dL_dK, X, X2)
    234         """
    235         if config.getboolean('cython', 'working'):
--> 236             return self._gradients_X_cython(dL_dK, X, X2)
    237         else:
    238             return self._gradients_X_pure(dL_dK, X, X2)

C:\Program Files\Anaconda2\lib\site-packages\GPy\kern\src\stationary.pyc in _gra
dients_X_cython(self, dL_dK, X, X2)
    321         X, X2 = np.ascontiguousarray(X), np.ascontiguousarray(X2)
    322         grad = np.zeros(X.shape)
--> 323         stationary_cython.grad_X(X.shape[0], X.shape[1], X2.shape[0], X,
 X2, tmp, grad)
    324         return grad/self.lengthscale**2
    325

NameError: global name 'stationary_cython' is not defined

If I use a linear kernel I do not get the above error.

I wondered if this was related to the documented issues on using cython code with anaconda on Windows 64bit due to bundling with mingw64 (see: https://github.com/ContinuumIO/anaconda-issues/issues/175) but I am now using TDM-GCC and the issue persists.

Has this been documented before? Is there anything I have missed that I can try to get this to work?

Many thanks for your help.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
mzwiesselecommented, Nov 23, 2016

On the contrary, thanks for reporting and using GPy!

On 23 Nov 2016, at 09:54, JM notifications@github.com wrote:

I provided cython working = False but that didn’t help. This morning I uninstalled 64bit Anaconda and installed 32bit Anaconda and everything now works fine. It must be a 64bit compiler issue as I mentioned in the first post. I am not sure whether I am being naive or whether there is a bug with respect to the cython working = False as that seems to not have the desired effect on my machine. Either way, I now have a work around and at least this issue Anaconda 64bit on windows is documented here in case anyone else comes across it. Thanks for your time and help with this.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

0reactions
isaacmashercommented, Nov 26, 2019

I was still getting the “unable to load cython” error now (Nov 2019), with GPy installed on python 2.7 from pip. I can run everything fine, but runtime seems excessively slow. I suspect that this is due to using the numpy rather than cython version of things.

I solved this by installing the Microsoft Visual C++ redistributable 2008 SP1 (example here). My guess is that the cythonized files in the GPy package were compiled with this version of MSVC. This is kind of an old version, and newer Windows machines (e.g. fresh install of Windows 10) do not come with all of the redistributables for older MSVC++. The “side-by-side configuration error” is caused by not having the correct version of the MSVC++ redistributables on your system (or windows being unable to find them).

To the maintainers: I would suggest including this (i.e. the required MSVC++ redistributable version) in the error message when the cython libraries fail to load due to a side-by-side configuration error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

gp models predictive_gradients with mean function · Issue #643
Hi,. I found that when calling predictive_gradients for a gp model with non trivial mean, the gradient returned for mean does not include ......
Read more >
Chapter 5 Gaussian Process Regression | Surrogates
Our aim is to understand the Gaussian process (GP) as a prior over random ... which one might more simply call a predictive...
Read more >
10.3 Fitting a Gaussian Process | Stan User's Guide
Predictive Inference with a Gaussian Process​​ Suppose for a given sequence of inputs x that the corresponding outputs y are observed. Given a...
Read more >
Parametric Gaussian Process Regressors - arXiv
In this work we propose two simple methods for scalable GP regression that address this issue and thus yield substantially improved predictive uncertainties....
Read more >
Gaussian Process Regression in TensorFlow Probability
In this colab, we explore Gaussian process regression using TensorFlow and TensorFlow Probability. We generate some noisy observations from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found