[tests working now?]
|
|
@ -43,20 +43,20 @@ if config.get('plotting', 'library') is not 'none':
|
||||||
|
|
||||||
from ..models import GPLVM, BayesianGPLVM, bayesian_gplvm_minibatch, SSGPLVM, SSMRD
|
from ..models import GPLVM, BayesianGPLVM, bayesian_gplvm_minibatch, SSGPLVM, SSMRD
|
||||||
GPLVM.plot_latent = gpy_plot.latent_plots.plot_latent
|
GPLVM.plot_latent = gpy_plot.latent_plots.plot_latent
|
||||||
GPLVM.plot_latent_scatter = gpy_plot.latent_plots.plot_latent_scatter
|
GPLVM.plot_scatter = gpy_plot.latent_plots.plot_latent_scatter
|
||||||
GPLVM.plot_latent_inducing = gpy_plot.latent_plots.plot_latent_inducing
|
GPLVM.plot_inducing = gpy_plot.latent_plots.plot_latent_inducing
|
||||||
GPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
|
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 = gpy_plot.latent_plots.plot_latent
|
||||||
BayesianGPLVM.plot_latent_scatter = gpy_plot.latent_plots.plot_latent_scatter
|
BayesianGPLVM.plot_scatter = gpy_plot.latent_plots.plot_latent_scatter
|
||||||
BayesianGPLVM.plot_latent_inducing = gpy_plot.latent_plots.plot_latent_inducing
|
BayesianGPLVM.plot_inducing = gpy_plot.latent_plots.plot_latent_inducing
|
||||||
BayesianGPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
|
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 = 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_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_inducing = gpy_plot.latent_plots.plot_latent_inducing
|
||||||
bayesian_gplvm_minibatch.BayesianGPLVMMiniBatch.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
|
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 = gpy_plot.latent_plots.plot_latent
|
||||||
SSGPLVM.plot_latent_scatter = gpy_plot.latent_plots.plot_latent_scatter
|
SSGPLVM.plot_scatter = gpy_plot.latent_plots.plot_latent_scatter
|
||||||
SSGPLVM.plot_latent_inducing = gpy_plot.latent_plots.plot_latent_inducing
|
SSGPLVM.plot_inducing = gpy_plot.latent_plots.plot_latent_inducing
|
||||||
SSGPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
|
SSGPLVM.plot_steepest_gradient_map = gpy_plot.latent_plots.plot_steepest_gradient_map
|
||||||
|
|
||||||
from ..kern import Kern
|
from ..kern import Kern
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ def _plot_latent_scatter(canvas, X, visible_dims, labels, marker, num_samples, p
|
||||||
Tango.reset()
|
Tango.reset()
|
||||||
X, labels = subsample_X(X, labels, num_samples)
|
X, labels = subsample_X(X, labels, num_samples)
|
||||||
scatters = []
|
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):
|
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)
|
update_not_existing_kwargs(kwargs, pl.defaults.latent_scatter)
|
||||||
if generate_colors:
|
if generate_colors:
|
||||||
|
|
@ -89,7 +89,7 @@ def plot_latent_scatter(self, labels=None,
|
||||||
labels = np.ones(self.num_data)
|
labels = np.ones(self.num_data)
|
||||||
legend = False
|
legend = False
|
||||||
else:
|
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)
|
scatters = _plot_latent_scatter(canvas, X, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
|
||||||
if projection == '3d':
|
if projection == '3d':
|
||||||
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend,
|
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend,
|
||||||
|
|
@ -126,9 +126,9 @@ def plot_latent_inducing(self,
|
||||||
if 'color' not in kwargs:
|
if 'color' not in kwargs:
|
||||||
kwargs['color'] = 'white'
|
kwargs['color'] = 'white'
|
||||||
canvas, kwargs = pl.get_new_canvas(projection=projection, **kwargs)
|
canvas, kwargs = pl.get_new_canvas(projection=projection, **kwargs)
|
||||||
X, _, _ = get_x_y_var(self)
|
Z = self.Z.values
|
||||||
labels = np.ones(self.num_data)
|
labels = np.array(['inducing'] * Z.shape[0])
|
||||||
scatters = _plot_latent_scatter(canvas, X, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
|
scatters = _plot_latent_scatter(canvas, Z, sig_dims, labels, marker, num_samples, projection=projection, **kwargs)
|
||||||
if projection == '3d':
|
if projection == '3d':
|
||||||
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend,
|
return pl.show_canvas(canvas, dict(scatter=scatters), legend=legend,
|
||||||
xlabel='latent dimension %i' % input_1,
|
xlabel='latent dimension %i' % input_1,
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,6 @@ def scatter_label_generator(labels, X, visible_dims, marker=None):
|
||||||
for lab in labels:
|
for lab in labels:
|
||||||
if not lab in ulabels:
|
if not lab in ulabels:
|
||||||
ulabels.append(lab)
|
ulabels.append(lab)
|
||||||
|
|
||||||
if marker is not None:
|
if marker is not None:
|
||||||
marker = itertools.cycle(list(marker))
|
marker = itertools.cycle(list(marker))
|
||||||
else:
|
else:
|
||||||
|
|
@ -154,19 +153,20 @@ def scatter_label_generator(labels, X, visible_dims, marker=None):
|
||||||
except:
|
except:
|
||||||
input_1 = visible_dims
|
input_1 = visible_dims
|
||||||
input_2 = input_3 = None
|
input_2 = input_3 = None
|
||||||
|
|
||||||
for ul in ulabels:
|
for ul in ulabels:
|
||||||
if type(ul) is np.string_:
|
from numbers import Number
|
||||||
this_label = ul
|
if isinstance(ul, str):
|
||||||
elif type(ul) is np.int64:
|
|
||||||
this_label = 'class %i' % ul
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
this_label = unicode(ul)
|
this_label = unicode(ul)
|
||||||
except NameError:
|
except NameError:
|
||||||
#python3
|
#python3
|
||||||
this_label = ul
|
this_label = ul
|
||||||
|
elif isinstance(ul, Number):
|
||||||
|
this_label = 'class {!s}'.format(ul)
|
||||||
|
else:
|
||||||
|
this_label = ul
|
||||||
|
|
||||||
if marker is not None:
|
if marker is not None:
|
||||||
m = next(marker)
|
m = next(marker)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,13 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
||||||
legend_ontop(ax, ncol=legend, fontdict=fontdict)
|
legend_ontop(ax, ncol=legend, fontdict=fontdict)
|
||||||
if zlim is not None:
|
if zlim is not None:
|
||||||
ax.set_zlim(zlim)
|
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()
|
ax.figure.canvas.draw()
|
||||||
return plots
|
return plots
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ def legend_ontop(ax, mode='expand', ncol=3, fontdict=None):
|
||||||
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
from mpl_toolkits.axes_grid1 import make_axes_locatable
|
||||||
handles, labels = ax.get_legend_handles_labels()
|
handles, labels = ax.get_legend_handles_labels()
|
||||||
divider = make_axes_locatable(ax)
|
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,
|
lgd = cax.legend(handles, labels, bbox_to_anchor=(0., 0., 1., 1.), loc=3,
|
||||||
ncol=ncol, mode=mode, borderaxespad=0., prop=fontdict or {})
|
ncol=ncol, mode=mode, borderaxespad=0., prop=fontdict or {})
|
||||||
cax.set_axis_off()
|
cax.set_axis_off()
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ def _image_comparison(baseline_images, extensions=['pdf','svg','ong'], tol=10):
|
||||||
fig.axes[0].set_axis_off()
|
fig.axes[0].set_axis_off()
|
||||||
fig.set_frameon(False)
|
fig.set_frameon(False)
|
||||||
fig.canvas.draw()
|
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 num, base in zip(plt.get_fignums(), baseline_images):
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
#plt.close(num)
|
#plt.close(num)
|
||||||
|
|
@ -145,9 +145,9 @@ def test_classification():
|
||||||
Y = f+np.random.normal(0, .1, f.shape)
|
Y = f+np.random.normal(0, .1, f.shape)
|
||||||
m = GPy.models.GPClassification(X, Y>Y.mean())
|
m = GPy.models.GPClassification(X, Y>Y.mean())
|
||||||
m.optimize()
|
m.optimize()
|
||||||
fig, ax = plt.subplots()
|
_, ax = plt.subplots()
|
||||||
m.plot(plot_raw=False, apply_link=False, ax=ax)
|
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=False, ax=ax)
|
||||||
m.plot(plot_raw=True, apply_link=True)
|
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):
|
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)
|
#m.optimize(messages=0)
|
||||||
labels = np.random.multinomial(1, np.random.dirichlet([.3333333, .3333333, .3333333]), size=(m.Y.shape[0])).nonzero()[1]
|
labels = np.random.multinomial(1, np.random.dirichlet([.3333333, .3333333, .3333333]), size=(m.Y.shape[0])).nonzero()[1]
|
||||||
m.plot_latent()
|
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_magnification(labels=labels)
|
||||||
m.plot_steepest_gradient_map(resolution=7)
|
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):
|
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.likelihood.variance = .1
|
||||||
#m.optimize(messages=0)
|
#m.optimize(messages=0)
|
||||||
labels = np.random.multinomial(1, np.random.dirichlet([.3333333, .3333333, .3333333]), size=(m.Y.shape[0])).nonzero()[1]
|
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_inducing(projection='2d')
|
||||||
m.plot_latent_inducing(projection='3d')
|
m.plot_inducing(projection='3d')
|
||||||
m.plot_latent_scatter(projection='3d')
|
m.plot_scatter(projection='3d')
|
||||||
m.plot_magnification(labels=labels)
|
m.plot_magnification(labels=labels)
|
||||||
m.plot_steepest_gradient_map(resolution=7)
|
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):
|
for do_test in _image_comparison(baseline_images=['bayesian_gplvm_{}'.format(sub) for sub in ["inducing", "inducing_3d", "latent_3d", "magnification", 'gradient']], extensions=extensions):
|
||||||
|
|
|
||||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 7 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 4.1 KiB After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 8.4 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 36 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.5 KiB |
|
|
@ -94,10 +94,13 @@ def prompt_user(prompt):
|
||||||
|
|
||||||
def data_available(dataset_name=None):
|
def data_available(dataset_name=None):
|
||||||
"""Check if the data set is available on the local machine already."""
|
"""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]
|
dr = data_resources[dataset_name]
|
||||||
zip_urls = (dr['files'], )
|
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 += ([],)
|
else: zip_urls += ([],)
|
||||||
|
|
||||||
for file_list, save_list in izip_longest(*zip_urls, fillvalue=[]):
|
for file_list, save_list in izip_longest(*zip_urls, fillvalue=[]):
|
||||||
|
|
|
||||||
|
|
@ -38,5 +38,5 @@ matplotlib.rcParams[u'figure.figsize'] = (4,3)
|
||||||
matplotlib.rcParams[u'text.usetex'] = False
|
matplotlib.rcParams[u'text.usetex'] = False
|
||||||
|
|
||||||
import nose
|
import nose
|
||||||
nose.main('GPy', defaultTest='GPy/testing')
|
nose.main('GPy', defaultTest='GPy/testing/plotting_tests.py')
|
||||||
|
|
||||||
|
|
|
||||||