added BGPLVM oil flow demo and changed default X_variance init

This commit is contained in:
Nicolo Fusi 2013-03-21 15:28:46 +00:00
parent 8ab1cfaf65
commit eeb965d136
3 changed files with 30 additions and 2 deletions

View file

@ -55,3 +55,31 @@ def GPLVM_oil_100():
print(m)
m.plot_latent(labels=data['Y'].argmax(axis=1))
return m
def BGPLVM_oil():
data = GPy.util.datasets.oil()
Y, X = data['Y'], data['X']
X -= X.mean(axis=0)
# X /= X.std(axis=0)
Q = 10
M = 30
kernel = GPy.kern.rbf(Q, ARD = True) + GPy.kern.bias(Q) + GPy.kern.white(Q)
m = GPy.models.Bayesian_GPLVM(X, Q, kernel=kernel, M=M)
m.scale_factor = 10000.0
m.constrain_positive('(white|noise|bias|X_variance|rbf_variance|rbf_length)')
from sklearn import cluster
km = cluster.KMeans(M, verbose=10)
Z = km.fit(m.X).cluster_centers_
# Z = GPy.util.misc.kmm_init(m.X, M)
m.set('iip', Z)
# optimize
# m.ensure_default_constraints()
import pdb; pdb.set_trace()
m.optimize('tnc', messages=1)
print m
m.plot_latent(labels=data['Y'].argmax(axis=1))
return m

View file

@ -242,8 +242,8 @@ class opt_SGD(Optimizer):
f, step, Nj = self.step_with_missing_data(f_fp, X, step, shapes, sparse_matrix)
else:
Nj = N
# momentum_term = self.momentum * step # compute momentum using update(t-1)
f, fp = f_fp(self.x_opt)
# momentum_term = self.momentum * step # compute momentum using update(t-1)
# step = self.learning_rate * fp # compute update(t)
# self.x_opt -= step + momentum_term
step = self.momentum * step + self.learning_rate * fp

View file

@ -27,7 +27,7 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
X = self.initialise_latent(init, Q, Y)
if S is None:
S = np.ones_like(X) * 1e-2#
S = np.ones_like(X) * 0.5 + np.random.randn(*X.shape) * 1e-3
if Z is None:
Z = np.random.permutation(X.copy())[:M]