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

This commit is contained in:
Nicolas 2013-06-04 18:35:44 +01:00
commit c56d611936
9 changed files with 82 additions and 63 deletions

View file

@ -218,20 +218,20 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
return means, covars
def plot_X_1d(self, fig=None, axes=None, fig_num="LVM mu S 1d", colors=None):
def plot_X_1d(self, fignum=None, ax=None, colors=None):
"""
Plot latent space X in 1D:
-if fig is given, create Q subplots in fig and plot in these
-if axes is given plot Q 1D latent space plots of X into each `axis`
-if neither fig nor axes is given create a figure with fig_num and plot in there
-if ax is given plot Q 1D latent space plots of X into each `axis`
-if neither fig nor ax is given create a figure with fignum and plot in there
colors:
colors of different latent space dimensions Q
"""
import pylab
if fig is None and axes is None:
fig = pylab.figure(num=fig_num, figsize=(8, min(12, (2 * self.X.shape[1]))))
if ax is None:
fig = pylab.figure(num=fignum, figsize=(8, min(12, (2 * self.X.shape[1]))))
if colors is None:
colors = pylab.gca()._get_lines.color_cycle
pylab.clf()
@ -240,10 +240,12 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
plots = []
x = np.arange(self.X.shape[0])
for i in range(self.X.shape[1]):
if axes is None:
if ax is None:
ax = fig.add_subplot(self.X.shape[1], 1, i + 1)
elif isinstance(ax, (tuple, list)):
ax = ax[i]
else:
ax = axes[i]
raise ValueError("Need one ax per latent dimnesion Q")
ax.plot(self.X, c='k', alpha=.3)
plots.extend(ax.plot(x, self.X.T[i], c=colors.next(), label=r"$\mathbf{{X_{{{}}}}}$".format(i)))
ax.fill_between(x,

View file

@ -256,15 +256,17 @@ class MRD(model):
self.Z = Z
return Z
def _handle_plotting(self, fig_num, axes, plotf):
def _handle_plotting(self, fignum, axes, plotf):
if axes is None:
fig = pylab.figure(num=fig_num, figsize=(4 * len(self.bgplvms), 3))
fig = pylab.figure(num=fignum, figsize=(4 * len(self.bgplvms), 3))
for i, g in enumerate(self.bgplvms):
if axes is None:
ax = fig.add_subplot(1, len(self.bgplvms), i + 1)
axes = fig.add_subplot(1, len(self.bgplvms), i + 1)
elif isinstance(axes, (tuple, list)):
axes = axes[i]
else:
ax = axes[i]
plotf(i, g, ax)
raise ValueError("Need one axes per latent dimension Q")
plotf(i, g, axes)
pylab.draw()
if axes is None:
fig.tight_layout()
@ -275,20 +277,20 @@ class MRD(model):
def plot_X_1d(self):
return self.gref.plot_X_1d()
def plot_X(self, fig_num="MRD Predictions", axes=None):
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: ax.imshow(g.X))
def plot_X(self, fignum="MRD Predictions", ax=None):
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: ax.imshow(g.X))
return fig
def plot_predict(self, fig_num="MRD Predictions", axes=None, **kwargs):
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: ax.imshow(g.predict(g.X)[0], **kwargs))
def plot_predict(self, fignum="MRD Predictions", ax=None, **kwargs):
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: ax.imshow(g.predict(g.X)[0], **kwargs))
return fig
def plot_scales(self, fig_num="MRD Scales", axes=None, *args, **kwargs):
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: g.kern.plot_ARD(ax=ax, *args, **kwargs))
def plot_scales(self, fignum="MRD Scales", ax=None, *args, **kwargs):
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: g.kern.plot_ARD(axes=ax, *args, **kwargs))
return fig
def plot_latent(self, fig_num="MRD Latent Spaces", axes=None, *args, **kwargs):
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: g.plot_latent(ax=ax, *args, **kwargs))
def plot_latent(self, fignum="MRD Latent Spaces", ax=None, *args, **kwargs):
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: g.plot_latent(axes=ax, *args, **kwargs))
return fig
def _debug_plot(self):
@ -296,11 +298,11 @@ class MRD(model):
fig = pylab.figure("MRD DEBUG PLOT", figsize=(4 * len(self.bgplvms), 9))
fig.clf()
axes = [fig.add_subplot(3, len(self.bgplvms), i + 1) for i in range(len(self.bgplvms))]
self.plot_X(axes=axes)
self.plot_X(ax=axes)
axes = [fig.add_subplot(3, len(self.bgplvms), i + len(self.bgplvms) + 1) for i in range(len(self.bgplvms))]
self.plot_latent(axes=axes)
self.plot_latent(ax=axes)
axes = [fig.add_subplot(3, len(self.bgplvms), i + 2 * len(self.bgplvms) + 1) for i in range(len(self.bgplvms))]
self.plot_scales(axes=axes)
self.plot_scales(ax=axes)
pylab.draw()
fig.tight_layout()