From fa750d4ba45b5d00726f09995f9f196bf71250f6 Mon Sep 17 00:00:00 2001 From: mzwiessele Date: Thu, 22 May 2014 15:08:36 +0100 Subject: [PATCH] [dim_reduce examples] updated plotting of brendan and bgplvm_oil --- GPy/examples/dimensionality_reduction.py | 20 ++++++++++---------- GPy/plotting/matplot_dep/visualize.py | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/GPy/examples/dimensionality_reduction.py b/GPy/examples/dimensionality_reduction.py index a216eec6..774bbefb 100644 --- a/GPy/examples/dimensionality_reduction.py +++ b/GPy/examples/dimensionality_reduction.py @@ -172,14 +172,14 @@ def bgplvm_oil(optimize=True, verbose=1, plot=True, N=200, Q=7, num_inducing=40, m.data_labels = data['Y'][:N].argmax(axis=1) if optimize: - m.optimize('scg', messages=verbose, max_iters=max_iters, gtol=.05) + m.optimize('bfgs', messages=verbose, max_iters=max_iters, gtol=.05) if plot: fig, (latent_axes, sense_axes) = plt.subplots(1, 2) m.plot_latent(ax=latent_axes, labels=m.data_labels) data_show = GPy.plotting.matplot_dep.visualize.vector_show((m.Y[0,:])) lvm_visualizer = GPy.plotting.matplot_dep.visualize.lvm_dimselect(param_to_array(m.X.mean)[0:1,:], # @UnusedVariable - m, data_show, latent_axes=latent_axes, sense_axes=sense_axes) + m, data_show, latent_axes=latent_axes, sense_axes=sense_axes, labels=m.data_labels) raw_input('Press enter to finish') plt.close(fig) return m @@ -386,18 +386,17 @@ def brendan_faces(optimize=True, verbose=True, plot=True): Yn = Y - Y.mean() Yn /= Yn.std() - m = GPy.models.GPLVM(Yn, Q) + m = GPy.models.BayesianGPLVM(Yn, Q, num_inducing=20) # optimize - m.constrain('rbf|noise|white', GPy.transformations.LogexpClipped()) - if optimize: m.optimize('scg', messages=verbose, max_iters=1000) + if optimize: m.optimize('bfgs', messages=verbose, max_iters=1000) if plot: ax = m.plot_latent(which_indices=(0, 1)) - y = m.likelihood.Y[0, :] + y = m.Y[0, :] data_show = GPy.plotting.matplot_dep.visualize.image_show(y[None, :], dimensions=(20, 28), transpose=True, order='F', invert=False, scale=False) - GPy.plotting.matplot_dep.visualize.lvm(m.X[0, :].copy(), m, data_show, ax) + lvm = GPy.plotting.matplot_dep.visualize.lvm(m.X.mean[0, :].copy(), m, data_show, ax) raw_input('Press enter to finish') return m @@ -411,13 +410,14 @@ def olivetti_faces(optimize=True, verbose=True, plot=True): Yn = Y - Y.mean() Yn /= Yn.std() - m = GPy.models.GPLVM(Yn, Q) - if optimize: m.optimize('scg', messages=verbose, max_iters=1000) + m = GPy.models.BayesianGPLVM(Yn, Q, num_inducing=20) + + if optimize: m.optimize('bfgs', messages=verbose, max_iters=1000) if plot: ax = m.plot_latent(which_indices=(0, 1)) y = m.likelihood.Y[0, :] data_show = GPy.plotting.matplot_dep.visualize.image_show(y[None, :], dimensions=(112, 92), transpose=False, invert=False, scale=False) - GPy.plotting.matplot_dep.visualize.lvm(m.X[0, :].copy(), m, data_show, ax) + lvm = GPy.plotting.matplot_dep.visualize.lvm(m.X.mean[0, :].copy(), m, data_show, ax) raw_input('Press enter to finish') return m diff --git a/GPy/plotting/matplot_dep/visualize.py b/GPy/plotting/matplot_dep/visualize.py index 3ba120aa..4026b7af 100644 --- a/GPy/plotting/matplot_dep/visualize.py +++ b/GPy/plotting/matplot_dep/visualize.py @@ -98,9 +98,9 @@ class lvm(matplotlib_show): """ if vals is None: if isinstance(model.X, VariationalPosterior): - vals = param_to_array(model.X.mean) + vals = model.X.mean else: - vals = param_to_array(model.X) + vals = model.X if len(vals.shape)==1: vals = vals[None,:] matplotlib_show.__init__(self, vals, axes=latent_axes) @@ -133,7 +133,7 @@ class lvm(matplotlib_show): def modify(self, vals): """When latent values are modified update the latent representation and ulso update the output visualization.""" - self.vals = vals.copy() + self.vals = vals.view(np.ndarray).copy() y = self.model.predict(self.vals)[0] self.data_visualize.modify(y) self.latent_handle.set_data(self.vals[0,self.latent_index[0]], self.vals[0,self.latent_index[1]])