From 37f94310d5a823359344a34cf7b63fc8c7440951 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Mon, 15 Apr 2013 15:58:33 +0100 Subject: [PATCH] plotting debug --- GPy/kern/kern.py | 4 +++- GPy/models/GPLVM.py | 5 +++-- GPy/models/mrd.py | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/GPy/kern/kern.py b/GPy/kern/kern.py index 447819c1..414a911f 100644 --- a/GPy/kern/kern.py +++ b/GPy/kern/kern.py @@ -52,12 +52,14 @@ class kern(parameterised): parameterised.__init__(self) - def plot_ARD(self, ax=pb.gca()): + def plot_ARD(self, ax=None): """ If an ARD kernel is present, it bar-plots the ARD parameters """ + if ax is None: + ax = pb.gca() for p in self.parts: if hasattr(p, 'ARD') and p.ARD: ax.set_title('ARD parameters, %s kernel' % p.name) diff --git a/GPy/models/GPLVM.py b/GPy/models/GPLVM.py index 0c81a9c1..3f9132ef 100644 --- a/GPy/models/GPLVM.py +++ b/GPy/models/GPLVM.py @@ -60,12 +60,13 @@ class GPLVM(GP): mu, var, upper, lower = self.predict(Xnew) pb.plot(mu[:,0], mu[:,1],'k',linewidth=1.5) - def plot_latent(self, labels=None, which_indices=None, resolution=50, ax=pb.gca()): + def plot_latent(self, labels=None, which_indices=None, resolution=50, ax=None): """ :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 ax is None: + ax = pb.gca() util.plot.Tango.reset() if labels is None: diff --git a/GPy/models/mrd.py b/GPy/models/mrd.py index 53825a50..81e46774 100644 --- a/GPy/models/mrd.py +++ b/GPy/models/mrd.py @@ -225,6 +225,29 @@ class MRD(model): self.X = X return X + def plot_X_1d(self, colors=None): + if colors is None: + colors = pylab.gca()._get_lines.color_cycle + fig = pylab.figure(num="MRD X 1d", figsize=(4 * len(self.bgplvms), (2 * self.X.shape[1]))) + fig.clf() + ax1 = fig.add_subplot(self.X.shape[1], 1, 1) + ax1.plot(self.X, c='k', alpha=.3) + plots = ax1.plot(self.X.T[0], c=colors.next()) + for i in range(self.X.shape[1] - 1): + ax = fig.add_subplot(self.X.shape[1], 1, i + 2) + ax.plot(self.X, c='k', alpha=.3) + plots.extend(ax.plot(self.X.T[i + 1], c=colors.next())) + if i < self.X.shape[1] - 2: + ax.set_xticklabels('') + ax1.set_xticklabels('') + ax1.legend(plots, [r"$\mathbf{{X_{}}}$".format(i + 1) for i in range(self.X.shape[1])], + bbox_to_anchor=(0., 1 + .01 * self.X.shape[1], + 1., 1. + .01 * self.X.shape[1]), loc=3, + ncol=self.X.shape[1], mode="expand", borderaxespad=0.) + pylab.draw() + fig.tight_layout(h_pad=.01, rect=(0, 0, 1, .95)) + return fig + def plot_X(self): fig = pylab.figure("MRD X", figsize=(4 * len(self.bgplvms), 3)) fig.clf() @@ -267,6 +290,7 @@ class MRD(model): def _debug_plot(self): self.plot_X() + self.plot_X_1d() self.plot_latent() self.plot_scales()