From c40c83a19110af9020efaa50592ef1e710a0a355 Mon Sep 17 00:00:00 2001 From: Nicolo Fusi Date: Fri, 15 Feb 2013 12:39:45 +0000 Subject: [PATCH] working on SGD merge --- GPy/inference/SGD.py | 13 ++++++++----- GPy/models/BGPLVM.py | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/GPy/inference/SGD.py b/GPy/inference/SGD.py index 02b448f3..34ab467c 100644 --- a/GPy/inference/SGD.py +++ b/GPy/inference/SGD.py @@ -198,8 +198,9 @@ class opt_SGD(Optimizer): for j in features: count += 1 self.model.D = len(j) + self.model.likelihood.D = self.model.D self.model.likelihood.Y = Y[:, j] - # self.model.trYYT = np.sum(np.square(self.model.Y)) + self.model.likelihood.YYT = np.dot(self.model.likelihood.Y, self.model.likelihood.Y.T) if missing_data or sparse_matrix: shapes = self.get_param_shapes(N, Q) f, step, Nj = self.step_with_missing_data(f_fp, X, step, shapes, sparse_matrix) @@ -216,8 +217,8 @@ class opt_SGD(Optimizer): # TODO: remove this, it's only for debugging if self.model.__class__.__name__ == 'Bayesian_GPLVM': - beta = np.exp(self.x_opt)[-8] - status = "evaluating {feature: 5d}/{tot: 5d} \t f: {f: 2.3f} \t non-missing: {nm: 4d} \t inv_bbeta: {beta: 1.5f}\r".format(feature = count, tot = len(features), f = f, nm = Nj, beta = 1./beta) + beta = np.exp(self.x_opt)[-1] + status = "evaluating {feature: 5d}/{tot: 5d} \t f: {f: 2.3f} \t non-missing: {nm: 4d} \t inv_bbeta: {beta: 1.5f}\r".format(feature = count, tot = len(features), f = f, nm = Nj, beta = beta) sys.stdout.write(status) sys.stdout.flush() @@ -228,10 +229,12 @@ class opt_SGD(Optimizer): # should really be a sum(), but earlier samples in the iteration will have a very crappy ll self.f_opt = np.mean(NLL) self.model.N = N - self.model.likelihood.N = N - self.model.likelihood.Y = Y self.model.X = X self.model.D = D + self.model.likelihood.N = N + self.model.likelihood.N = N + self.model.likelihood.D = D + # self.model.Youter = np.dot(Y, Y.T) self.trace.append(self.f_opt) if self.messages != 0: diff --git a/GPy/models/BGPLVM.py b/GPy/models/BGPLVM.py index 45304915..883b6888 100644 --- a/GPy/models/BGPLVM.py +++ b/GPy/models/BGPLVM.py @@ -22,8 +22,9 @@ class Bayesian_GPLVM(sparse_GP, GPLVM): :type init: 'PCA'|'random' """ - def __init__(self, Y, Q, init='PCA', M=10, Z=None, kernel=None, **kwargs): - X = self.initialise_latent(init, Q, Y) + def __init__(self, Y, Q, X = None, init='PCA', M=10, Z=None, kernel=None, **kwargs): + if X == None: + X = self.initialise_latent(init, Q, Y) if Z is None: Z = np.random.permutation(X.copy())[:M] @@ -70,4 +71,3 @@ class Bayesian_GPLVM(sparse_GP, GPLVM): def _log_likelihood_gradients(self): return np.hstack((self.dL_dmuS().flatten(), sparse_GP._log_likelihood_gradients(self))) -