[testing] BGPLVM

This commit is contained in:
mzwiessele 2015-10-06 14:22:29 +01:00
parent a6ad9c33a6
commit 133a815950
5 changed files with 33 additions and 19 deletions

View file

@ -190,12 +190,4 @@ class SSGPLVM(SparseGP_MPI):
if self.kern.ARD:
return self.kern.input_sensitivity()
else:
return self.variational_prior.pi
def plot_latent(self, plot_inducing=True, *args, **kwargs):
import sys
assert "matplotlib" in sys.modules, "matplotlib package has not been imported."
from ..plotting.matplot_dep import dim_reduction_plots
return dim_reduction_plots.plot_latent(self, plot_inducing=plot_inducing, *args, **kwargs)
return self.variational_prior.pi

View file

@ -41,9 +41,7 @@ if config.get('plotting', 'library') is not 'none':
from ..core import SparseGP
SparseGP.plot_inducing = gpy_plot.data_plots.plot_inducing
from ..models import GPLVM
from ..models import BayesianGPLVM
from ..models import bayesian_gplvm_minibatch
from ..models import GPLVM, BayesianGPLVM, bayesian_gplvm_minibatch, SSGPLVM, SSMRD
GPLVM.plot_prediction_fit = gpy_plot.latent_plots.plot_prediction_fit
GPLVM.plot_latent = gpy_plot.latent_plots.plot_latent
GPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
@ -53,6 +51,9 @@ if config.get('plotting', 'library') is not 'none':
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_latent = gpy_plot.latent_plots.plot_latent
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_prediction_fit = gpy_plot.latent_plots.plot_prediction_fit
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
SSGPLVM.plot_latent = gpy_plot.latent_plots.plot_latent
SSGPLVM.plot_prediction_fit = gpy_plot.latent_plots.plot_prediction_fit
SSGPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
from ..kern import Kern
Kern.plot_covariance = gpy_plot.kernel_plots.plot_covariance

View file

@ -72,7 +72,7 @@ def plot_prediction_fit(self, plot_limits=None,
:param dict sactter_kwargs: kwargs for the scatter plot, specific for the plotting library you are using
:param kwargs plot_kwargs: kwargs for the data plot for the plotting library you are using
"""
canvas, kwargs = pl.get_new_canvas(plot_kwargs)
canvas, kwargs = pl.get_new_canvas(**plot_kwargs)
plots = _plot_prediction_fit(self, canvas, plot_limits, which_data_rows, which_data_ycols,
fixed_inputs, resolution, plot_raw,
apply_link, visible_dims,
@ -289,9 +289,10 @@ def _plot_steepest_gradient_map(self, canvas, input_1, input_2, Xgrid,
Y, annotation = plot_function(Xgrid[:, [input_1, input_2]])
annotation_kwargs = update_not_existing_kwargs(annotation_kwargs or {}, pl.defaults.annotation)
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs or {}, pl.defaults.gradient)
imshow, annotation = pl.annotation_heatmap(canvas, Y, annotation, (xmin[0], xmax[0], xmin[1], xmax[1]),
None, plot_function, resolution, imshow_kwargs=imshow_kwargs, **annotation_kwargs)
imshow_kwargs = update_not_existing_kwargs(imshow_kwargs, pl.defaults.gradient)
imshow, annotation = pl.annotation_heatmap(canvas, Y, annotation,
(xmin[0], xmax[0], xmin[1], xmax[1]),
None, plot_function, resolution,
imshow_kwargs=imshow_kwargs, **annotation_kwargs)
return dict(heatmap=imshow, annotation=annotation)
def plot_steepest_gradient_map(self, output_labels=None, data_labels=None, which_indices=None,

View file

@ -71,7 +71,7 @@ class MatplotlibPlots(AbstractPlottingLibrary):
fontdict=dict(family='sans-serif', weight='light', size=9)
if legend >= 1:
#ax.legend(prop=fontdict)
legend_ontop(ax, ncol=legend)
legend_ontop(ax, ncol=legend, fontdict=fontdict)
if zlim is not None:
ax.set_zlim(zlim)
ax.figure.canvas.draw()
@ -144,7 +144,7 @@ class MatplotlibPlots(AbstractPlottingLibrary):
annotations = []
for [i, x], [j, y] in itertools.product(enumerate(xlin), enumerate(ylin[::-1])):
annotations.append(ax.text(x + xoffset, y + yoffset, "{}".format(annotation[j, i]), **annotation_kwargs))
return [imshow, annotations]
return imshow, annotations
def contour(self, ax, X, Y, C, levels=20, label=None, **kwargs):
return ax.contour(X, Y, C, levels=np.linspace(C.min(), C.max(), levels), label=label, **kwargs)

View file

@ -181,13 +181,33 @@ def test_gplvm():
m.optimize(messages=0)
labels = np.random.multinomial(1, np.random.dirichlet([.3333333, .3333333, .3333333]), size=(m.Y.shape[0])).nonzero()[1]
m.plot_prediction_fit(which_data_ycols=(0,1)) # ignore this test, as plotting is not consistent!!
m.plot_steepest_gradient_map(resolution=7)
plt.close('all')
m.plot_latent()
m.plot_magnification(labels=labels)
m.plot_steepest_gradient_map(resolution=7)
for do_test in _image_comparison(baseline_images=['gplvm_{}'.format(sub) for sub in ["latent", "magnification", 'gradient']], extensions=extensions):
yield (do_test, )
def test_bayesian_gplvm():
from ..examples.dimensionality_reduction import _simulate_matern
from ..kern import RBF
from ..models import BayesianGPLVM
Q = 3
_, _, Ylist = _simulate_matern(5, 1, 1, 100, num_inducing=5, plot_sim=False)
Y = Ylist[0]
k = RBF(Q, ARD=True) # + kern.white(Q, _np.exp(-2)) # + kern.bias(Q)
# k = kern.RBF(Q, ARD=True, lengthscale=10.)
m = BayesianGPLVM(Y, Q, init="PCA", kernel=k)
m.likelihood.variance = .1
m.optimize(messages=0)
labels = np.random.multinomial(1, np.random.dirichlet([.3333333, .3333333, .3333333]), size=(m.Y.shape[0])).nonzero()[1]
m.plot_prediction_fit(which_data_ycols=(0,1)) # ignore this test, as plotting is not consistent!!
plt.close('all')
m.plot_latent()
m.plot_magnification(labels=labels)
m.plot_steepest_gradient_map(resolution=7)
for do_test in _image_comparison(baseline_images=['bayesian_gplvm_{}'.format(sub) for sub in ["latent", "magnification", 'gradient']], extensions=extensions):
yield (do_test, )
if __name__ == '__main__':
import nose