mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-13 14:03:20 +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
|
|
@ -33,7 +33,7 @@ class GPBase(model.model):
|
||||||
# All leaf nodes should call self._set_params(self._get_params()) at
|
# All leaf nodes should call self._set_params(self._get_params()) at
|
||||||
# the end
|
# the end
|
||||||
|
|
||||||
def plot_f(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, full_cov=False):
|
def plot_f(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, full_cov=False, fignum=None, ax=None):
|
||||||
"""
|
"""
|
||||||
Plot the GP's view of the world, where the data is normalized and the
|
Plot the GP's view of the world, where the data is normalized and the
|
||||||
likelihood is Gaussian.
|
likelihood is Gaussian.
|
||||||
|
|
@ -57,46 +57,55 @@ class GPBase(model.model):
|
||||||
if which_data == 'all':
|
if which_data == 'all':
|
||||||
which_data = slice(None)
|
which_data = slice(None)
|
||||||
|
|
||||||
|
if ax is None:
|
||||||
|
fig = pb.figure(num=fignum)
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
|
||||||
if self.X.shape[1] == 1:
|
if self.X.shape[1] == 1:
|
||||||
Xnew, xmin, xmax = x_frame1D(self.X, plot_limits=plot_limits)
|
Xnew, xmin, xmax = x_frame1D(self.X, plot_limits=plot_limits)
|
||||||
if samples == 0:
|
if samples == 0:
|
||||||
m, v = self._raw_predict(Xnew, which_parts=which_parts)
|
m, v = self._raw_predict(Xnew, which_parts=which_parts)
|
||||||
gpplot(Xnew, m, m - 2 * np.sqrt(v), m + 2 * np.sqrt(v))
|
gpplot(Xnew, m, m - 2 * np.sqrt(v), m + 2 * np.sqrt(v), axes=ax)
|
||||||
pb.plot(self.X[which_data], self.likelihood.Y[which_data], 'kx', mew=1.5)
|
ax.plot(self.X[which_data], self.likelihood.Y[which_data], 'kx', mew=1.5)
|
||||||
else:
|
else:
|
||||||
m, v = self._raw_predict(Xnew, which_parts=which_parts, full_cov=True)
|
m, v = self._raw_predict(Xnew, which_parts=which_parts, full_cov=True)
|
||||||
Ysim = np.random.multivariate_normal(m.flatten(), v, samples)
|
Ysim = np.random.multivariate_normal(m.flatten(), v, samples)
|
||||||
gpplot(Xnew, m, m - 2 * np.sqrt(np.diag(v)[:, None]), m + 2 * np.sqrt(np.diag(v))[:, None])
|
gpplot(Xnew, m, m - 2 * np.sqrt(np.diag(v)[:, None]), m + 2 * np.sqrt(np.diag(v))[:, None,], axes=ax)
|
||||||
for i in range(samples):
|
for i in range(samples):
|
||||||
pb.plot(Xnew, Ysim[i, :], Tango.colorsHex['darkBlue'], linewidth=0.25)
|
ax.plot(Xnew, Ysim[i, :], Tango.colorsHex['darkBlue'], linewidth=0.25)
|
||||||
pb.plot(self.X[which_data], self.likelihood.Y[which_data], 'kx', mew=1.5)
|
ax.plot(self.X[which_data], self.likelihood.Y[which_data], 'kx', mew=1.5)
|
||||||
pb.xlim(xmin, xmax)
|
ax.set_xlim(xmin, xmax)
|
||||||
ymin, ymax = min(np.append(self.likelihood.Y, m - 2 * np.sqrt(np.diag(v)[:, None]))), max(np.append(self.likelihood.Y, m + 2 * np.sqrt(np.diag(v)[:, None])))
|
ymin, ymax = min(np.append(self.likelihood.Y, m - 2 * np.sqrt(np.diag(v)[:, None]))), max(np.append(self.likelihood.Y, m + 2 * np.sqrt(np.diag(v)[:, None])))
|
||||||
ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin)
|
ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin)
|
||||||
pb.ylim(ymin, ymax)
|
ax.set_ylim(ymin, ymax)
|
||||||
|
|
||||||
elif self.X.shape[1] == 2:
|
elif self.X.shape[1] == 2:
|
||||||
resolution = resolution or 50
|
resolution = resolution or 50
|
||||||
Xnew, xmin, xmax, xx, yy = x_frame2D(self.X, plot_limits, resolution)
|
Xnew, xmin, xmax, xx, yy = x_frame2D(self.X, plot_limits, resolution)
|
||||||
m, v = self._raw_predict(Xnew, which_parts=which_parts)
|
m, v = self._raw_predict(Xnew, which_parts=which_parts)
|
||||||
m = m.reshape(resolution, resolution).T
|
m = m.reshape(resolution, resolution).T
|
||||||
pb.contour(xx, yy, m, vmin=m.min(), vmax=m.max(), cmap=pb.cm.jet)
|
ax.contour(xx, yy, m, vmin=m.min(), vmax=m.max(), cmap=pb.cm.jet)
|
||||||
pb.scatter(self.X[:, 0], self.X[:, 1], 40, self.likelihood.Y, linewidth=0, cmap=pb.cm.jet, vmin=m.min(), vmax=m.max())
|
ax.scatter(self.X[:, 0], self.X[:, 1], 40, self.likelihood.Y, linewidth=0, cmap=pb.cm.jet, vmin=m.min(), vmax=m.max())
|
||||||
pb.xlim(xmin[0], xmax[0])
|
ax.set_xlim(xmin[0], xmax[0])
|
||||||
pb.ylim(xmin[1], xmax[1])
|
ax.set_ylim(xmin[1], xmax[1])
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError, "Cannot define a frame with more than two input dimensions"
|
raise NotImplementedError, "Cannot define a frame with more than two input dimensions"
|
||||||
|
|
||||||
def plot(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20):
|
def plot(self, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, samples=0, fignum=None, ax=None):
|
||||||
"""
|
"""
|
||||||
TODO: Docstrings!
|
TODO: Docstrings!
|
||||||
:param levels: for 2D plotting, the number of contour levels to use
|
:param levels: for 2D plotting, the number of contour levels to use
|
||||||
|
is ax is None, create a new figure
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# TODO include samples
|
# TODO include samples
|
||||||
if which_data == 'all':
|
if which_data == 'all':
|
||||||
which_data = slice(None)
|
which_data = slice(None)
|
||||||
|
|
||||||
|
if ax is None:
|
||||||
|
fig = pb.figure(num=fignum)
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
|
||||||
if self.X.shape[1] == 1:
|
if self.X.shape[1] == 1:
|
||||||
|
|
||||||
Xu = self.X * self._Xstd + self._Xmean # NOTE self.X are the normalized values now
|
Xu = self.X * self._Xstd + self._Xmean # NOTE self.X are the normalized values now
|
||||||
|
|
@ -104,12 +113,12 @@ class GPBase(model.model):
|
||||||
Xnew, xmin, xmax = x_frame1D(Xu, plot_limits=plot_limits)
|
Xnew, xmin, xmax = x_frame1D(Xu, plot_limits=plot_limits)
|
||||||
m, var, lower, upper = self.predict(Xnew, which_parts=which_parts)
|
m, var, lower, upper = self.predict(Xnew, which_parts=which_parts)
|
||||||
for d in range(m.shape[1]):
|
for d in range(m.shape[1]):
|
||||||
gpplot(Xnew, m[:,d], lower[:,d], upper[:,d])
|
gpplot(Xnew, m[:,d], lower[:,d], upper[:,d],axes=ax)
|
||||||
pb.plot(Xu[which_data], self.likelihood.data[which_data,d], 'kx', mew=1.5)
|
ax.plot(Xu[which_data], self.likelihood.data[which_data,d], 'kx', mew=1.5)
|
||||||
ymin, ymax = min(np.append(self.likelihood.data, lower)), max(np.append(self.likelihood.data, upper))
|
ymin, ymax = min(np.append(self.likelihood.data, lower)), max(np.append(self.likelihood.data, upper))
|
||||||
ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin)
|
ymin, ymax = ymin - 0.1 * (ymax - ymin), ymax + 0.1 * (ymax - ymin)
|
||||||
pb.xlim(xmin, xmax)
|
ax.set_xlim(xmin, xmax)
|
||||||
pb.ylim(ymin, ymax)
|
ax.set_ylim(ymin, ymax)
|
||||||
|
|
||||||
elif self.X.shape[1] == 2: # FIXME
|
elif self.X.shape[1] == 2: # FIXME
|
||||||
resolution = resolution or 50
|
resolution = resolution or 50
|
||||||
|
|
@ -117,11 +126,11 @@ class GPBase(model.model):
|
||||||
x, y = np.linspace(xmin[0], xmax[0], resolution), np.linspace(xmin[1], xmax[1], resolution)
|
x, y = np.linspace(xmin[0], xmax[0], resolution), np.linspace(xmin[1], xmax[1], resolution)
|
||||||
m, var, lower, upper = self.predict(Xnew, which_parts=which_parts)
|
m, var, lower, upper = self.predict(Xnew, which_parts=which_parts)
|
||||||
m = m.reshape(resolution, resolution).T
|
m = m.reshape(resolution, resolution).T
|
||||||
pb.contour(x, y, m, levels, vmin=m.min(), vmax=m.max(), cmap=pb.cm.jet)
|
ax.contour(x, y, m, levels, vmin=m.min(), vmax=m.max(), cmap=pb.cm.jet)
|
||||||
Yf = self.likelihood.Y.flatten()
|
Yf = self.likelihood.Y.flatten()
|
||||||
pb.scatter(self.X[:, 0], self.X[:, 1], 40, Yf, cmap=pb.cm.jet, vmin=m.min(), vmax=m.max(), linewidth=0.)
|
ax.scatter(self.X[:, 0], self.X[:, 1], 40, Yf, cmap=pb.cm.jet, vmin=m.min(), vmax=m.max(), linewidth=0.)
|
||||||
pb.xlim(xmin[0], xmax[0])
|
ax.set_xlim(xmin[0], xmax[0])
|
||||||
pb.ylim(xmin[1], xmax[1])
|
ax.set_ylim(xmin[1], xmax[1])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError, "Cannot define a frame with more than two input dimensions"
|
raise NotImplementedError, "Cannot define a frame with more than two input dimensions"
|
||||||
|
|
|
||||||
|
|
@ -281,17 +281,21 @@ class sparse_GP(GPBase):
|
||||||
|
|
||||||
return mean, var, _025pm, _975pm
|
return mean, var, _025pm, _975pm
|
||||||
|
|
||||||
def plot(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20):
|
def plot(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, fignum=None, ax=None):
|
||||||
GPBase.plot(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20)
|
if ax is None:
|
||||||
|
fig = pb.figure(num=fignum)
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
|
|
||||||
|
GPBase.plot(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, ax=ax)
|
||||||
if self.X.shape[1] == 1:
|
if self.X.shape[1] == 1:
|
||||||
Xu = self.X * self._Xstd + self._Xmean # NOTE self.X are the normalized values now
|
|
||||||
if self.has_uncertain_inputs:
|
if self.has_uncertain_inputs:
|
||||||
pb.errorbar(Xu[which_data, 0], self.likelihood.data[which_data, 0],
|
Xu = self.X * self._Xstd + self._Xmean # NOTE self.X are the normalized values now
|
||||||
|
ax.errorbar(Xu[which_data, 0], self.likelihood.data[which_data, 0],
|
||||||
xerr=2 * np.sqrt(self.X_variance[which_data, 0]),
|
xerr=2 * np.sqrt(self.X_variance[which_data, 0]),
|
||||||
ecolor='k', fmt=None, elinewidth=.5, alpha=.5)
|
ecolor='k', fmt=None, elinewidth=.5, alpha=.5)
|
||||||
Zu = self.Z * self._Xstd + self._Xmean
|
Zu = self.Z * self._Xstd + self._Xmean
|
||||||
pb.plot(Zu, Zu * 0 + pb.ylim()[0], 'r|', mew=1.5, markersize=12)
|
ax.plot(Zu, np.zeros_like(Zu) + ax.get_ylim()[0], 'r|', mew=1.5, markersize=12)
|
||||||
# pb.errorbar(self.X[:,0], pb.ylim()[0]+np.zeros(self.N), xerr=2*np.sqrt(self.X_variance.flatten()))
|
|
||||||
|
|
||||||
elif self.X.shape[1] == 2: # FIXME
|
elif self.X.shape[1] == 2:
|
||||||
pb.plot(self.Z[:, 0], self.Z[:, 1], 'wo')
|
Zu = self.Z * self._Xstd + self._Xmean
|
||||||
|
ax.plot(Zu[:, 0], Zu[:, 1], 'wo')
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,10 @@ def coregionalisation_toy2(max_nb_eval_optim=100):
|
||||||
|
|
||||||
k1 = GPy.kern.rbf(1) + GPy.kern.bias(1)
|
k1 = GPy.kern.rbf(1) + GPy.kern.bias(1)
|
||||||
k2 = GPy.kern.coregionalise(2,1)
|
k2 = GPy.kern.coregionalise(2,1)
|
||||||
k = k1.prod_orthogonal(k2)
|
k = k1.prod(k2,tensor=True)
|
||||||
m = GPy.models.GP_regression(X,Y,kernel=k)
|
m = GPy.models.GP_regression(X,Y,kernel=k)
|
||||||
m.constrain_fixed('rbf_var',1.)
|
m.constrain_fixed('.*rbf_var',1.)
|
||||||
m.constrain_positive('kappa')
|
#m.constrain_positive('.*kappa')
|
||||||
m.ensure_default_constraints()
|
m.ensure_default_constraints()
|
||||||
m.optimize('sim',messages=1,max_f_eval=max_nb_eval_optim)
|
m.optimize('sim',messages=1,max_f_eval=max_nb_eval_optim)
|
||||||
|
|
||||||
|
|
@ -117,10 +117,10 @@ def coregionalisation_toy(max_nb_eval_optim=100):
|
||||||
|
|
||||||
k1 = GPy.kern.rbf(1)
|
k1 = GPy.kern.rbf(1)
|
||||||
k2 = GPy.kern.coregionalise(2,2)
|
k2 = GPy.kern.coregionalise(2,2)
|
||||||
k = k1.prod_orthogonal(k2)
|
k = k1.prod(k2,tensor=True)
|
||||||
m = GPy.models.GP_regression(X,Y,kernel=k)
|
m = GPy.models.GP_regression(X,Y,kernel=k)
|
||||||
m.constrain_fixed('rbf_var',1.)
|
m.constrain_fixed('.*rbf_var',1.)
|
||||||
m.constrain_positive('kappa')
|
#m.constrain_positive('kappa')
|
||||||
m.ensure_default_constraints()
|
m.ensure_default_constraints()
|
||||||
m.optimize(max_f_eval=max_nb_eval_optim)
|
m.optimize(max_f_eval=max_nb_eval_optim)
|
||||||
|
|
||||||
|
|
@ -153,12 +153,12 @@ def coregionalisation_sparse(max_nb_eval_optim=100):
|
||||||
|
|
||||||
k1 = GPy.kern.rbf(1)
|
k1 = GPy.kern.rbf(1)
|
||||||
k2 = GPy.kern.coregionalise(2,2)
|
k2 = GPy.kern.coregionalise(2,2)
|
||||||
k = k1.prod_orthogonal(k2) + GPy.kern.white(2,0.001)
|
k = k1.prod(k2,tensor=True) + GPy.kern.white(2,0.001)
|
||||||
|
|
||||||
m = GPy.models.sparse_GP_regression(X,Y,kernel=k,Z=Z)
|
m = GPy.models.sparse_GP_regression(X,Y,kernel=k,Z=Z)
|
||||||
m.scale_factor = 10000.
|
m.scale_factor = 10000.
|
||||||
m.constrain_fixed('rbf_var',1.)
|
m.constrain_fixed('.*rbf_var',1.)
|
||||||
m.constrain_positive('kappa')
|
#m.constrain_positive('kappa')
|
||||||
m.constrain_fixed('iip')
|
m.constrain_fixed('iip')
|
||||||
m.ensure_default_constraints()
|
m.ensure_default_constraints()
|
||||||
m.optimize_restarts(5, robust=True, messages=1, max_f_eval=max_nb_eval_optim)
|
m.optimize_restarts(5, robust=True, messages=1, max_f_eval=max_nb_eval_optim)
|
||||||
|
|
@ -293,11 +293,11 @@ def sparse_GP_regression_2D(N = 400, M = 50, max_nb_eval_optim=100):
|
||||||
kernel = rbf + noise
|
kernel = rbf + noise
|
||||||
|
|
||||||
# create simple GP model
|
# create simple GP model
|
||||||
m = GPy.models.sparse_GP_regression(X,Y,kernel, M = M, max_nb_eval_optim=100)
|
m = GPy.models.sparse_GP_regression(X,Y,kernel, M = M)
|
||||||
|
|
||||||
# contrain all parameters to be positive (but not inducing inputs)
|
# contrain all parameters to be positive (but not inducing inputs)
|
||||||
m.constrain_positive('(variance|lengthscale|precision)')
|
m.ensure_default_constraints()
|
||||||
m.set('len',2.)
|
m.set('.*len',2.)
|
||||||
|
|
||||||
m.checkgrad()
|
m.checkgrad()
|
||||||
|
|
||||||
|
|
@ -314,16 +314,16 @@ def uncertain_inputs_sparse_regression(max_nb_eval_optim=100):
|
||||||
S = np.ones((20,1))
|
S = np.ones((20,1))
|
||||||
X = np.random.uniform(-3.,3.,(20,1))
|
X = np.random.uniform(-3.,3.,(20,1))
|
||||||
Y = np.sin(X)+np.random.randn(20,1)*0.05
|
Y = np.sin(X)+np.random.randn(20,1)*0.05
|
||||||
likelihood = GPy.likelihoods.Gaussian(Y)
|
#likelihood = GPy.likelihoods.Gaussian(Y)
|
||||||
Z = np.random.uniform(-3.,3.,(7,1))
|
Z = np.random.uniform(-3.,3.,(7,1))
|
||||||
|
|
||||||
k = GPy.kern.rbf(1) + GPy.kern.white(1)
|
k = GPy.kern.rbf(1) + GPy.kern.white(1)
|
||||||
|
|
||||||
# create simple GP model
|
# create simple GP model
|
||||||
m = GPy.models.sparse_GP(X, likelihood, kernel=k, Z=Z, X_uncertainty=S)
|
m = GPy.models.sparse_GP_regression(X, Y, kernel=k, Z=Z, X_variance=S)
|
||||||
|
|
||||||
# contrain all parameters to be positive
|
# contrain all parameters to be positive
|
||||||
m.constrain_positive('(variance|prec)')
|
m.ensure_default_constraints()
|
||||||
|
|
||||||
# optimize and plot
|
# optimize and plot
|
||||||
m.optimize('tnc', messages=1, max_f_eval=max_nb_eval_optim)
|
m.optimize('tnc', messages=1, max_f_eval=max_nb_eval_optim)
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,11 @@ class kern(parameterised):
|
||||||
parameterised.__init__(self)
|
parameterised.__init__(self)
|
||||||
|
|
||||||
|
|
||||||
def plot_ARD(self, ax=None):
|
def plot_ARD(self, fignum=None, ax=None):
|
||||||
"""If an ARD kernel is present, it bar-plots the ARD parameters"""
|
"""If an ARD kernel is present, it bar-plots the ARD parameters"""
|
||||||
if ax is None:
|
if ax is None:
|
||||||
ax = pb.gca()
|
fig = pb.figure(fignum)
|
||||||
|
ax = fig.add_subplot(111)
|
||||||
for p in self.parts:
|
for p in self.parts:
|
||||||
if hasattr(p, 'ARD') and p.ARD:
|
if hasattr(p, 'ARD') and p.ARD:
|
||||||
ax.set_title('ARD parameters, %s kernel' % p.name)
|
ax.set_title('ARD parameters, %s kernel' % p.name)
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
||||||
return means, covars
|
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:
|
Plot latent space X in 1D:
|
||||||
|
|
||||||
|
|
@ -230,7 +230,8 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
||||||
colors of different latent space dimensions Q
|
colors of different latent space dimensions Q
|
||||||
"""
|
"""
|
||||||
import pylab
|
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:
|
if colors is None:
|
||||||
colors = pylab.gca()._get_lines.color_cycle
|
colors = pylab.gca()._get_lines.color_cycle
|
||||||
pylab.clf()
|
pylab.clf()
|
||||||
|
|
@ -241,8 +242,10 @@ class Bayesian_GPLVM(sparse_GP, GPLVM):
|
||||||
for i in range(self.X.shape[1]):
|
for i in range(self.X.shape[1]):
|
||||||
if ax is None:
|
if ax is None:
|
||||||
ax = fig.add_subplot(self.X.shape[1], 1, i + 1)
|
ax = fig.add_subplot(self.X.shape[1], 1, i + 1)
|
||||||
else:
|
elif isinstance(ax, (tuple, list)):
|
||||||
ax = ax[i]
|
ax = ax[i]
|
||||||
|
else:
|
||||||
|
raise ValueError("Need one ax per latent dimnesion Q")
|
||||||
ax.plot(self.X, c='k', alpha=.3)
|
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)))
|
plots.extend(ax.plot(x, self.X.T[i], c=colors.next(), label=r"$\mathbf{{X_{{{}}}}}$".format(i)))
|
||||||
ax.fill_between(x,
|
ax.fill_between(x,
|
||||||
|
|
|
||||||
|
|
@ -256,15 +256,17 @@ class MRD(model):
|
||||||
self.Z = Z
|
self.Z = Z
|
||||||
return Z
|
return Z
|
||||||
|
|
||||||
def _handle_plotting(self, fig_num, axes, plotf):
|
def _handle_plotting(self, fignum, axes, plotf):
|
||||||
if axes is None:
|
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):
|
for i, g in enumerate(self.bgplvms):
|
||||||
if axes is None:
|
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:
|
else:
|
||||||
ax = axes[i]
|
raise ValueError("Need one axes per latent dimension Q")
|
||||||
plotf(i, g, ax)
|
plotf(i, g, axes)
|
||||||
pylab.draw()
|
pylab.draw()
|
||||||
if axes is None:
|
if axes is None:
|
||||||
fig.tight_layout()
|
fig.tight_layout()
|
||||||
|
|
@ -275,20 +277,20 @@ class MRD(model):
|
||||||
def plot_X_1d(self):
|
def plot_X_1d(self):
|
||||||
return self.gref.plot_X_1d()
|
return self.gref.plot_X_1d()
|
||||||
|
|
||||||
def plot_X(self, fig_num="MRD Predictions", axes=None):
|
def plot_X(self, fignum="MRD Predictions", ax=None):
|
||||||
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: ax.imshow(g.X))
|
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: ax.imshow(g.X))
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
def plot_predict(self, fig_num="MRD Predictions", axes=None, **kwargs):
|
def plot_predict(self, fignum="MRD Predictions", ax=None, **kwargs):
|
||||||
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: ax.imshow(g.predict(g.X)[0], **kwargs))
|
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: ax.imshow(g.predict(g.X)[0], **kwargs))
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
def plot_scales(self, fig_num="MRD Scales", axes=None, *args, **kwargs):
|
def plot_scales(self, fignum="MRD Scales", ax=None, *args, **kwargs):
|
||||||
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: g.kern.plot_ARD(ax=ax, *args, **kwargs))
|
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: g.kern.plot_ARD(axes=ax, *args, **kwargs))
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
def plot_latent(self, fig_num="MRD Latent Spaces", axes=None, *args, **kwargs):
|
def plot_latent(self, fignum="MRD Latent Spaces", ax=None, *args, **kwargs):
|
||||||
fig = self._handle_plotting(fig_num, axes, lambda i, g, ax: g.plot_latent(ax=ax, *args, **kwargs))
|
fig = self._handle_plotting(fignum, ax, lambda i, g, ax: g.plot_latent(axes=ax, *args, **kwargs))
|
||||||
return fig
|
return fig
|
||||||
|
|
||||||
def _debug_plot(self):
|
def _debug_plot(self):
|
||||||
|
|
@ -296,11 +298,11 @@ class MRD(model):
|
||||||
fig = pylab.figure("MRD DEBUG PLOT", figsize=(4 * len(self.bgplvms), 9))
|
fig = pylab.figure("MRD DEBUG PLOT", figsize=(4 * len(self.bgplvms), 9))
|
||||||
fig.clf()
|
fig.clf()
|
||||||
axes = [fig.add_subplot(3, len(self.bgplvms), i + 1) for i in range(len(self.bgplvms))]
|
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))]
|
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))]
|
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()
|
pylab.draw()
|
||||||
fig.tight_layout()
|
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)
|
#kern defaults to rbf (plus white for stability)
|
||||||
if kernel is None:
|
if kernel is None:
|
||||||
kernel = kern.rbf(X.shape[1]) + kern.white(X.shape[1],1e-3)
|
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 defaults to Gaussian
|
||||||
likelihood = likelihoods.Gaussian(Y,normalize=normalize_Y)
|
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())
|
self._set_params(self._get_params())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue