mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-11 13:02:38 +02:00
Merge branch 'master' of github.com:SheffieldML/GPy
This commit is contained in:
commit
ac701df7e1
2 changed files with 61 additions and 3 deletions
|
|
@ -46,7 +46,6 @@ def GPLVM_oil_100():
|
||||||
# create simple GP model
|
# create simple GP model
|
||||||
m = GPy.models.GPLVM(data['X'], 2)
|
m = GPy.models.GPLVM(data['X'], 2)
|
||||||
|
|
||||||
|
|
||||||
# optimize
|
# optimize
|
||||||
m.ensure_default_constraints()
|
m.ensure_default_constraints()
|
||||||
m.optimize()
|
m.optimize()
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from ..core import model
|
||||||
from ..util.linalg import pdinv, PCA
|
from ..util.linalg import pdinv, PCA
|
||||||
from GP import GP
|
from GP import GP
|
||||||
from ..likelihoods import Gaussian
|
from ..likelihoods import Gaussian
|
||||||
|
from .. import util
|
||||||
|
|
||||||
class GPLVM(GP):
|
class GPLVM(GP):
|
||||||
"""
|
"""
|
||||||
|
|
@ -59,5 +60,63 @@ class GPLVM(GP):
|
||||||
mu, var, upper, lower = self.predict(Xnew)
|
mu, var, upper, lower = self.predict(Xnew)
|
||||||
pb.plot(mu[:,0], mu[:,1],'k',linewidth=1.5)
|
pb.plot(mu[:,0], mu[:,1],'k',linewidth=1.5)
|
||||||
|
|
||||||
def plot_latent(self):
|
def plot_latent(self,labels=None, which_indices=None, resolution=50):
|
||||||
raise NotImplementedError
|
"""
|
||||||
|
:param labels: a np.array of size self.N containing labels for the points (can be number, strings, etc)
|
||||||
|
:param resolution: the resolution of the grid on which to evaluate the predictive variance
|
||||||
|
"""
|
||||||
|
|
||||||
|
if labels is None:
|
||||||
|
labels = np.ones(self.N)
|
||||||
|
if which_indices is None:
|
||||||
|
if self.Q==1:
|
||||||
|
input_1 = 0
|
||||||
|
input_2 = None
|
||||||
|
if self.Q==2:
|
||||||
|
input_1, input_2 = 0,1
|
||||||
|
else:
|
||||||
|
#try to find a linear of RBF kern in the kernel
|
||||||
|
k = [p for p in self.kern.parts if p.name in ['rbf','linear']]
|
||||||
|
if (not len(k)==1) or (not k[0].ARD):
|
||||||
|
raise ValueError, "cannot Atomatically determine which dimensions to plot, please pass 'which_indices'"
|
||||||
|
k = k[0]
|
||||||
|
if k.name=='rbf':
|
||||||
|
input_1, input_2 = np.argsort(k.lengthscales)[:2]
|
||||||
|
elif k.name=='linear':
|
||||||
|
input_1, input_2 = np.argsort(k.variances)[::-1][:2]
|
||||||
|
|
||||||
|
#first, plot the output variance as a function of the latent space
|
||||||
|
Xtest, xx,yy,xmin,xmax = util.plot.x_frame2D(self.X[:,[input_1, input_2]],resolution=resolution)
|
||||||
|
mu, var, low, up = self.predict(Xtest)
|
||||||
|
pb.imshow(var.reshape(resolution,resolution).T[::-1,:],extent=[xmin[0],xmax[0],xmin[1],xmax[1]],cmap=pb.cm.binary,interpolation='bilinear')
|
||||||
|
|
||||||
|
|
||||||
|
for i,ul in enumerate(np.unique(labels)):
|
||||||
|
if type(ul) is np.string_:
|
||||||
|
this_label = ul
|
||||||
|
elif type(ul) is np.int64:
|
||||||
|
this_label = 'class %i'%ul
|
||||||
|
else:
|
||||||
|
this_label = 'class %i'%i
|
||||||
|
|
||||||
|
index = np.nonzero(labels==ul)[0]
|
||||||
|
if self.Q==1:
|
||||||
|
x = self.X[index,input_1]
|
||||||
|
y = np.zeros(index.size)
|
||||||
|
else:
|
||||||
|
x = self.X[index,input_1]
|
||||||
|
y = self.X[index,input_2]
|
||||||
|
pb.plot(x,y,marker='o',color=util.plot.Tango.nextMedium(),mew=0,label=this_label,linewidth=0)
|
||||||
|
|
||||||
|
pb.xlabel('latent dimension %i'%input_1)
|
||||||
|
pb.ylabel('latent dimension %i'%input_2)
|
||||||
|
|
||||||
|
if not np.all(labels==1.):
|
||||||
|
pb.legend(loc=0,numpoints=1)
|
||||||
|
|
||||||
|
pb.xlim(xmin[0],xmax[0])
|
||||||
|
pb.ylim(xmin[1],xmax[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue