SheffieldML / GPy

Gaussian processes framework in python
BSD 3-Clause "New" or "Revised" License
2.01k stars 557 forks source link

SVI-GP don't work with the example from the tutorial, seems to be a climin problem #721

Open Alaya-in-Matrix opened 5 years ago

Alaya-in-Matrix commented 5 years ago

I am trying to learn SVI-GP using the example given from GPy tutorial

import GPy
import numpy as np
import climin

N  = 5000
X  = np.random.rand(N)[:, None]
Y1 = np.sin(6*X) + 0.1*np.random.randn(N,1)
Y2 = np.sin(3*X) + 0.1*np.random.randn(N,1)
Y  = np.hstack((Y1, Y2))

Z         = np.random.rand(20,1)
batchsize = 10
m         = GPy.core.SVGP(X, Y, Z, GPy.kern.RBF(1) + GPy.kern.White(1), GPy.likelihoods.Gaussian(), batchsize=batchsize)

However, the above code crashed when running using python 3.6, with the following error message:

Traceback (most recent call last):
  File "debug.py", line 73, in <module>
    m         = GPy.core.SVGP(X, Y, Z, GPy.kern.RBF(1) + GPy.kern.White(1), GPy.likelihoods.Gaussian(), batchsize=batchsize)
  File "/home/alaya/anaconda3/lib/python3.6/site-packages/paramz/parameterized.py", line 48, in __call__
    self = super(ParametersChangedMeta, self).__call__(*args, **kw)
  File "/home/alaya/anaconda3/lib/python3.6/site-packages/GPy/core/svgp.py", line 36, in __init__
    X_batch, Y_batch = self.new_batch()
  File "/home/alaya/anaconda3/lib/python3.6/site-packages/GPy/core/svgp.py", line 92, in new_batch
    i = next(self.slicer)
  File "/home/alaya/anaconda3/lib/python3.6/site-packages/climin/util.py", line 92, in draw_mini_slices
    random.shuffle(idxs)
  File "/home/alaya/anaconda3/lib/python3.6/random.py", line 275, in shuffle
    x[i], x[j] = x[j], x[i]
TypeError: 'range' object does not support item assignment
sgoodlett commented 3 years ago

This issue has to do with how SVGP selects new batches. Climin seems to have not been updated to Python3.x so some of its functions are deprecated. By revising the new_batch method in SVGP, this issue can be fixed. For instance, I used numpy to select random elements from my test set with np.random.choice. This doesn't seem to raise any issues further down the road (I am not a developer) so I am happy with it and it does what I need.

sgoodlett commented 3 years ago

Also, see https://github.com/SheffieldML/GPy/issues/327#issue-139852177