[tests working now?]

This commit is contained in:
mzwiessele 2015-10-07 00:52:47 +01:00
parent 5290e4bf0e
commit 7ebdc698f6
34 changed files with 42 additions and 33 deletions

View file

@ -43,20 +43,20 @@ if config.get('plotting', 'library') is not 'none':
from ..models import GPLVM, BayesianGPLVM, bayesian_gplvm_minibatch, SSGPLVM, SSMRD
GPLVM.plot_latent = gpy_plot.latent_plots.plot_latent
GPLVM.plot_latent_scatter = gpy_plot.latent_plots.plot_latent_scatter
GPLVM.plot_latent_inducing = gpy_plot.latent_plots.plot_latent_inducing
GPLVM.plot_scatter = gpy_plot.latent_plots.plot_latent_scatter
GPLVM.plot_inducing = gpy_plot.latent_plots.plot_latent_inducing
GPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
BayesianGPLVM.plot_latent = gpy_plot.latent_plots.plot_latent
BayesianGPLVM.plot_latent_scatter = gpy_plot.latent_plots.plot_latent_scatter
BayesianGPLVM.plot_latent_inducing = gpy_plot.latent_plots.plot_latent_inducing
BayesianGPLVM.plot_scatter = gpy_plot.latent_plots.plot_latent_scatter
BayesianGPLVM.plot_inducing = gpy_plot.latent_plots.plot_latent_inducing
BayesianGPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_latent = gpy_plot.latent_plots.plot_latent
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_latent_scatter = gpy_plot.latent_plots.plot_latent_scatter
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_latent_inducing = gpy_plot.latent_plots.plot_latent_inducing
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_scatter = gpy_plot.latent_plots.plot_latent_scatter
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_inducing = gpy_plot.latent_plots.plot_latent_inducing
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_latent_scatter = gpy_plot.latent_plots.plot_latent_scatter
SSGPLVM.plot_latent_inducing = gpy_plot.latent_plots.plot_latent_inducing
SSGPLVM.plot_scatter = gpy_plot.latent_plots.plot_latent_scatter
SSGPLVM.plot_inducing = gpy_plot.latent_plots.plot_latent_inducing
SSGPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
from ..kern import Kern

View file

@ -52,7 +52,7 @@ def _plot_latent_scatter(canvas, X, visible_dims, labels, marker, num_samples, p
Tango.reset()
X, labels = subsample_X(X, labels, num_samples)
scatters = []
generate_colors = 'color' not in kwargs
generate_colors = 'color' not in kwargs
for x, y, z, this_label, _, m in scatter_label_generator(labels, X, visible_dims, marker):
update_not_existing_kwargs(kwargs, pl.defaults.latent_scatter)
if generate_colors:
@ -89,7 +89,7 @@ def plot_latent_scatter(self, labels=None,
labels = np.ones(self.num_data)
legend = False
else:
legend = find_best_layout_for_subplots(len(np.unique(labels)))
legend = find_best_layout_for_subplots(len(np.unique(labels)))[1]
scatters = _plot_latent_scatter(canvas, X, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
if projection == '3d':
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend,
@ -126,9 +126,9 @@ def plot_latent_inducing(self,
if 'color' not in kwargs:
kwargs['color'] = 'white'
canvas, kwargs = pl.get_new_canvas(projection=projection, **kwargs)
X, _, _ = get_x_y_var(self)
labels = np.ones(self.num_data)
scatters = _plot_latent_scatter(canvas, X, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
Z = self.Z.values
labels = np.array(['inducing'] * Z.shape[0])
scatters = _plot_latent_scatter(canvas, Z, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
if projection == '3d':
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend,
xlabel='latent dimension %i' % input_1,

View file

@ -138,7 +138,6 @@ def scatter_label_generator(labels, X, visible_dims, marker=None):
for lab in labels:
if not lab in ulabels:
ulabels.append(lab)
if marker is not None:
marker = itertools.cycle(list(marker))
else:
@ -154,19 +153,20 @@ def scatter_label_generator(labels, X, visible_dims, marker=None):
except:
input_1 = visible_dims
input_2 = input_3 = None
for ul in ulabels:
if type(ul) is np.string_:
this_label = ul
elif type(ul) is np.int64:
this_label = 'class %i' % ul
else:
from numbers import Number
if isinstance(ul, str):
try:
this_label = unicode(ul)
except NameError:
#python3
this_label = ul
elif isinstance(ul, Number):
this_label = 'class {!s}'.format(ul)
else:
this_label = ul
if marker is not None:
m = next(marker)

View file

@ -76,7 +76,13 @@ class MatplotlibPlots(AbstractPlottingLibrary):
legend_ontop(ax, ncol=legend, fontdict=fontdict)
if zlim is not None:
ax.set_zlim(zlim)
#ax.figure.show()
ax.figure.canvas.draw()
ax.figure.show()
#try:
# ax.figure.tight_layout()
#except:
# # couldnt do tight layout, python 2.7 on MacOSX
# pass
ax.figure.canvas.draw()
return plots

View file

@ -35,7 +35,7 @@ def legend_ontop(ax, mode='expand', ncol=3, fontdict=None):
from mpl_toolkits.axes_grid1 import make_axes_locatable
handles, labels = ax.get_legend_handles_labels()
divider = make_axes_locatable(ax)
cax = divider.append_axes("top", "5%", pad="1%")
cax = divider.append_axes("top", "5%", pad=0)
lgd = cax.legend(handles, labels, bbox_to_anchor=(0., 0., 1., 1.), loc=3,
ncol=ncol, mode=mode, borderaxespad=0., prop=fontdict or {})
cax.set_axis_off()

View file

@ -74,7 +74,7 @@ def _image_comparison(baseline_images, extensions=['pdf','svg','ong'], tol=10):
fig.axes[0].set_axis_off()
fig.set_frameon(False)
fig.canvas.draw()
fig.savefig(os.path.join(result_dir, "{}.{}".format(base, ext)))
fig.savefig(os.path.join(result_dir, "{}.{}".format(base, ext)), transparent=True, edgecolor='none', facecolor='none')
for num, base in zip(plt.get_fignums(), baseline_images):
for ext in extensions:
#plt.close(num)
@ -145,9 +145,9 @@ def test_classification():
Y = f+np.random.normal(0, .1, f.shape)
m = GPy.models.GPClassification(X, Y>Y.mean())
m.optimize()
fig, ax = plt.subplots()
_, ax = plt.subplots()
m.plot(plot_raw=False, apply_link=False, ax=ax)
fig, ax = plt.subplots()
_, ax = plt.subplots()
m.plot(plot_raw=True, apply_link=False, ax=ax)
m.plot(plot_raw=True, apply_link=True)
for do_test in _image_comparison(baseline_images=['gp_class_{}'.format(sub) for sub in ["likelihood", "raw", 'raw_link']], extensions=extensions):
@ -182,7 +182,7 @@ 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_latent()
m.plot_latent_scatter(projection='3d', labels=labels)
m.plot_scatter(projection='3d', labels=labels)
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", "latent_3d", "magnification", 'gradient']], extensions=extensions):
@ -202,9 +202,9 @@ def test_bayesian_gplvm():
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_latent_inducing(projection='2d')
m.plot_latent_inducing(projection='3d')
m.plot_latent_scatter(projection='3d')
m.plot_inducing(projection='2d')
m.plot_inducing(projection='3d')
m.plot_scatter(projection='3d')
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 ["inducing", "inducing_3d", "latent_3d", "magnification", 'gradient']], extensions=extensions):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 51 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 37 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Before After
Before After

View file

@ -94,10 +94,13 @@ def prompt_user(prompt):
def data_available(dataset_name=None):
"""Check if the data set is available on the local machine already."""
from itertools import izip_longest
try:
from itertools import izip_longest
except ImportError:
from itertools import zip_longest as izip_longest
dr = data_resources[dataset_name]
zip_urls = (dr['files'], )
if dr.has_key('save_names'): zip_urls += (dr['save_names'], )
if 'save_names' in dr: zip_urls += (dr['save_names'], )
else: zip_urls += ([],)
for file_list, save_list in izip_longest(*zip_urls, fillvalue=[]):