Merge branch 'devel' of github.com:SheffieldML/GPy into devel

This commit is contained in:
Alan Saul 2013-06-05 19:25:25 +01:00
commit a31fd31ccb
6 changed files with 73 additions and 67 deletions

View file

@ -142,7 +142,7 @@ class GP(GPBase):
"""
# normalize X values
Xnew = (Xnew.copy() - self._Xmean) / self._Xstd
Xnew = (Xnew.copy() - self._Xoffset) / self._Xscale
mu, var = self._raw_predict(Xnew, full_cov=full_cov, which_parts=which_parts)
# now push through likelihood

View file

@ -21,12 +21,12 @@ class GPBase(Model):
self.num_data, self.output_dim = self.likelihood.data.shape
if normalize_X:
self._Xmean = X.mean(0)[None, :]
self._Xstd = X.std(0)[None, :]
self.X = (X.copy() - self._Xmean) / self._Xstd
self._Xoffset = X.mean(0)[None, :]
self._Xscale = X.std(0)[None, :]
self.X = (X.copy() - self._Xoffset) / self._Xscale
else:
self._Xmean = np.zeros((1, self.input_dim))
self._Xstd = np.ones((1, self.input_dim))
self._Xoffset = np.zeros((1, self.input_dim))
self._Xscale = np.ones((1, self.input_dim))
super(GPBase, self).__init__()
# All leaf nodes should call self._set_params(self._get_params()) at
@ -107,7 +107,7 @@ class GPBase(Model):
if self.X.shape[1] == 1:
Xu = self.X * self._Xstd + self._Xmean # NOTE self.X are the normalized values now
Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now
Xnew, xmin, xmax = x_frame1D(Xu, plot_limits=plot_limits)
m, _, lower, upper = self.predict(Xnew, which_parts=which_parts)

View file

@ -43,11 +43,11 @@ class SparseGP(GPBase):
self.X_variance = X_variance
if normalize_X:
self.Z = (self.Z.copy() - self._Xmean) / self._Xstd
self.Z = (self.Z.copy() - self._Xoffset) / self._Xscale
# normalize X uncertainty also
if self.has_uncertain_inputs:
self.X_variance /= np.square(self._Xstd)
self.X_variance /= np.square(self._Xscale)
def _compute_kernel_matrices(self):
# kernel computations, using BGPLVM notation
@ -269,9 +269,9 @@ class SparseGP(GPBase):
"""
# normalize X values
Xnew = (Xnew.copy() - self._Xmean) / self._Xstd
Xnew = (Xnew.copy() - self._Xoffset) / self._Xscale
if X_variance_new is not None:
X_variance_new = X_variance_new / self._Xstd ** 2
X_variance_new = X_variance_new / self._Xscale ** 2
# here's the actual prediction by the GP model
mu, var = self._raw_predict(Xnew, X_variance_new, full_cov=full_cov, which_parts=which_parts)
@ -292,13 +292,13 @@ class SparseGP(GPBase):
GPBase.plot(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, ax=ax)
if self.X.shape[1] == 1:
if self.has_uncertain_inputs:
Xu = self.X * self._Xstd + self._Xmean # NOTE self.X are the normalized values now
Xu = self.X * self._Xscale + self._Xoffset # NOTE self.X are the normalized values now
ax.errorbar(Xu[which_data, 0], self.likelihood.data[which_data, 0],
xerr=2 * np.sqrt(self.X_variance[which_data, 0]),
ecolor='k', fmt=None, elinewidth=.5, alpha=.5)
Zu = self.Z * self._Xstd + self._Xmean
Zu = self.Z * self._Xscale + self._Xoffset
ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12)
elif self.X.shape[1] == 2:
Zu = self.Z * self._Xstd + self._Xmean
Zu = self.Z * self._Xscale + self._Xoffset
ax.plot(Zu[:, 0], Zu[:, 1], 'wo')

View file

@ -162,6 +162,7 @@ def FITC_crescent_data(num_inducing=10, seed=default_seed):
Y[Y.flatten()==-1]=0
m = GPy.models.FITCClassification(data['X'], Y,num_inducing=num_inducing)
m.constrain_bounded('.*len',1.,1e3)
m.ensure_default_constraints()
m['.*len'] = 3.
#m.update_likelihood_approximation()

View file

@ -304,72 +304,75 @@ def mrd_simulation(optimize=True, plot=True, plot_sim=True, **kw):
m.plot_scales("MRD Scales")
return m
def brendan_faces():
from GPy import kern
data = GPy.util.datasets.brendan_faces()
Q = 2
Y = data['Y'][0:-1:10, :]
# Y = data['Y']
Yn = Y - Y.mean()
Yn /= Yn.std()
# # Commented out because dataset is missing
# def brendan_faces():
# from GPy import kern
# data = GPy.util.datasets.brendan_faces()
# Q = 2
# Y = data['Y'][0:-1:10, :]
# # Y = data['Y']
# Yn = Y - Y.mean()
# Yn /= Yn.std()
m = GPy.models.GPLVM(Yn, Q)
# m = GPy.models.BayesianGPLVM(Yn, Q, num_inducing=100)
# m = GPy.models.GPLVM(Yn, Q)
# # m = GPy.models.BayesianGPLVM(Yn, Q, num_inducing=100)
# optimize
m.constrain('rbf|noise|white', GPy.core.transformations.logexp_clipped())
# # optimize
# m.constrain('rbf|noise|white', GPy.core.transformations.logexp_clipped())
m.ensure_default_constraints()
m.optimize('scg', messages=1, max_f_eval=10000)
# m.ensure_default_constraints()
# m.optimize('scg', messages=1, max_f_eval=10000)
ax = m.plot_latent(which_indices=(0, 1))
y = m.likelihood.Y[0, :]
data_show = GPy.util.visualize.image_show(y[None, :], dimensions=(20, 28), transpose=True, invert=False, scale=False)
lvm_visualizer = GPy.util.visualize.lvm(m.X[0, :].copy(), m, data_show, ax)
raw_input('Press enter to finish')
plt.close('all')
# ax = m.plot_latent(which_indices=(0, 1))
# y = m.likelihood.Y[0, :]
# data_show = GPy.util.visualize.image_show(y[None, :], dimensions=(20, 28), transpose=True, invert=False, scale=False)
# lvm_visualizer = GPy.util.visualize.lvm(m.X[0, :].copy(), m, data_show, ax)
# raw_input('Press enter to finish')
# plt.close('all')
return m
# return m
def stick():
data = GPy.util.datasets.stick()
m = GPy.models.GPLVM(data['Y'], 2)
# # Commented out because dataset is missing
# def stick():
# data = GPy.util.datasets.stick()
# m = GPy.models.GPLVM(data['Y'], 2)
# optimize
m.ensure_default_constraints()
m.optimize(messages=1, max_f_eval=10000)
m._set_params(m._get_params())
# # optimize
# m.ensure_default_constraints()
# m.optimize(messages=1, max_f_eval=10000)
# m._set_params(m._get_params())
ax = m.plot_latent()
y = m.likelihood.Y[0, :]
data_show = GPy.util.visualize.stick_show(y[None, :], connect=data['connect'])
lvm_visualizer = GPy.util.visualize.lvm(m.X[0, :].copy(), m, data_show, ax)
raw_input('Press enter to finish')
plt.close('all')
# ax = m.plot_latent()
# y = m.likelihood.Y[0, :]
# data_show = GPy.util.visualize.stick_show(y[None, :], connect=data['connect'])
# lvm_visualizer = GPy.util.visualize.lvm(m.X[0, :].copy(), m, data_show, ax)
# raw_input('Press enter to finish')
# plt.close('all')
return m
# return m
def cmu_mocap(subject='35', motion=['01'], in_place=True):
# # Commented out because dataset is missing
# def cmu_mocap(subject='35', motion=['01'], in_place=True):
data = GPy.util.datasets.cmu_mocap(subject, motion)
Y = data['Y']
if in_place:
# Make figure move in place.
data['Y'][:, 0:3] = 0.0
m = GPy.models.GPLVM(data['Y'], 2, normalize_Y=True)
# data = GPy.util.datasets.cmu_mocap(subject, motion)
# Y = data['Y']
# if in_place:
# # Make figure move in place.
# data['Y'][:, 0:3] = 0.0
# m = GPy.models.GPLVM(data['Y'], 2, normalize_Y=True)
# optimize
m.ensure_default_constraints()
m.optimize(messages=1, max_f_eval=10000)
# # optimize
# m.ensure_default_constraints()
# m.optimize(messages=1, max_f_eval=10000)
ax = m.plot_latent()
y = m.likelihood.Y[0, :]
data_show = GPy.util.visualize.skeleton_show(y[None, :], data['skel'])
lvm_visualizer = GPy.util.visualize.lvm(m.X[0, :].copy(), m, data_show, ax)
raw_input('Press enter to finish')
plt.close('all')
# ax = m.plot_latent()
# y = m.likelihood.Y[0, :]
# data_show = GPy.util.visualize.skeleton_show(y[None, :], data['skel'])
# lvm_visualizer = GPy.util.visualize.lvm(m.X[0, :].copy(), m, data_show, ax)
# raw_input('Press enter to finish')
# plt.close('all')
return m
# return m
# def BGPLVM_oil():
# data = GPy.util.datasets.oil()

View file

@ -143,5 +143,7 @@ def model_interaction():
X = np.random.randn(20,1)
Y = np.sin(X) + np.random.randn(*X.shape)*0.01 + 5.
k = GPy.kern.rbf(1) + GPy.kern.bias(1)
return GPy.models.GPRegression(X, Y, kernel=k)
m = GPy.models.GPRegression(X, Y, kernel=k)
m.ensure_default_constraints()
return m