mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-13 05:52:38 +02:00
Merge branch 'devel' of github.com:SheffieldML/GPy into devel
This commit is contained in:
commit
eb5f2ff5f0
7 changed files with 86 additions and 67 deletions
|
|
@ -218,7 +218,7 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
|||
return means, covars
|
||||
|
||||
|
||||
def plot_X_1d(self, ax=None, fignum=None, colors=None):
|
||||
def plot_X_1d(self, fignum=None, ax=None, colors=None):
|
||||
"""
|
||||
Plot latent space X in 1D:
|
||||
|
||||
|
|
@ -230,7 +230,8 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
|||
colors of different latent space dimensions Q
|
||||
"""
|
||||
import pylab
|
||||
fig = pylab.figure(num=fignum, 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()
|
||||
|
|
@ -241,8 +242,10 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
|||
for i in range(self.X.shape[1]):
|
||||
if ax is None:
|
||||
ax = fig.add_subplot(self.X.shape[1], 1, i + 1)
|
||||
else:
|
||||
elif isinstance(ax, (tuple, list)):
|
||||
ax = ax[i]
|
||||
else:
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class sparse_GP_regression(sparse_GP):
|
|||
|
||||
"""
|
||||
|
||||
def __init__(self, X, Y, kernel=None, normalize_X=False, normalize_Y=False, Z=None, M=10):
|
||||
def __init__(self, X, Y, kernel=None, normalize_X=False, normalize_Y=False, Z=None, M=10, X_variance=None):
|
||||
#kern defaults to rbf (plus white for stability)
|
||||
if kernel is None:
|
||||
kernel = kern.rbf(X.shape[1]) + kern.white(X.shape[1],1e-3)
|
||||
|
|
@ -43,5 +43,5 @@ class sparse_GP_regression(sparse_GP):
|
|||
#likelihood defaults to Gaussian
|
||||
likelihood = likelihoods.Gaussian(Y,normalize=normalize_Y)
|
||||
|
||||
sparse_GP.__init__(self, X, likelihood, kernel, Z=Z, normalize_X=normalize_X)
|
||||
sparse_GP.__init__(self, X, likelihood, kernel, Z=Z, normalize_X=normalize_X, X_variance=X_variance)
|
||||
self._set_params(self._get_params())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue