Issue when calling gp.predictive_gradients()
See original GitHub issueI 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:
- Created 7 years ago
- Comments:19 (7 by maintainers)
Top GitHub Comments
On the contrary, thanks for reporting and using GPy!
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.