[test] coverage increased
|
|
@ -51,6 +51,7 @@ if config.get('plotting', 'library') is not 'none':
|
|||
|
||||
from ..core import GP
|
||||
GP.plot_data = gpy_plot.data_plots.plot_data
|
||||
GP.plot_data_error = gpy_plot.data_plots.plot_data_error
|
||||
GP.plot_errorbars_trainset = gpy_plot.data_plots.plot_errorbars_trainset
|
||||
GP.plot_mean = gpy_plot.gp_plots.plot_mean
|
||||
GP.plot_confidence = gpy_plot.gp_plots.plot_confidence
|
||||
|
|
|
|||
|
|
@ -134,24 +134,23 @@ def _plot_data_error(self, canvas, which_data_rows='all',
|
|||
plots = {}
|
||||
|
||||
if X_variance is not None:
|
||||
plots['xerrorplot'] = []
|
||||
plots['input_error'] = []
|
||||
#one dimensional plotting
|
||||
if len(free_dims) == 1:
|
||||
for d in ycols:
|
||||
update_not_existing_kwargs(error_kwargs, pl().defaults.xerrorbar)
|
||||
plots['xerrorplot'].append(pl().xerrorbar(canvas, X[rows, free_dims].flatten(), Y[rows, d].flatten(),
|
||||
plots['input_error'].append(pl().xerrorbar(canvas, X[rows, free_dims].flatten(), Y[rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
#2D plotting
|
||||
elif len(free_dims) == 2:
|
||||
update_not_existing_kwargs(error_kwargs, pl().defaults.xerrorbar) # @UndefinedVariable
|
||||
for d in ycols:
|
||||
plots['xerrorplot'].append(pl().xerrorbar(canvas, X[rows, free_dims[0]].flatten(), Y[rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims[0]].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
plots['yerrorplot'].append(pl().xerrorbar(canvas, X[rows, free_dims[1]].flatten(), Y[rows, d].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims[1]].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
plots['input_error'].append(pl().xerrorbar(canvas, X[rows, free_dims[0]].flatten(), X[rows, free_dims[1]].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims[0]].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
plots['input_error'].append(pl().yerrorbar(canvas, X[rows, free_dims[0]].flatten(), X[rows, free_dims[1]].flatten(),
|
||||
2 * np.sqrt(X_variance[rows, free_dims[1]].flatten()), label=label,
|
||||
**error_kwargs))
|
||||
elif len(free_dims) == 0:
|
||||
pass #Nothing to plot!
|
||||
else:
|
||||
|
|
@ -244,7 +243,7 @@ def _plot_errorbars_trainset(self, canvas,
|
|||
|
||||
plots = []
|
||||
|
||||
if len(free_dims)<=2:
|
||||
if len(free_dims)<=2 and projection=='2d':
|
||||
update_not_existing_kwargs(plot_kwargs, pl().defaults.yerrorbar)
|
||||
if predict_kw is None:
|
||||
predict_kw = {}
|
||||
|
|
@ -259,21 +258,20 @@ def _plot_errorbars_trainset(self, canvas,
|
|||
np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
label=label,
|
||||
**plot_kwargs))
|
||||
elif len(free_dims) == 2:
|
||||
for d in ycols:
|
||||
plots.append(pl().yerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
color=Y[rows,d],
|
||||
label=label,
|
||||
**plot_kwargs))
|
||||
plots.append(pl().xerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
color=Y[rows,d],
|
||||
label=label,
|
||||
**plot_kwargs))
|
||||
pass #Nothing to plot!
|
||||
# elif len(free_dims) == 2:
|
||||
# for d in ycols:
|
||||
# plots.append(pl().yerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
# np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
# #color=Y[rows,d],
|
||||
# label=label,
|
||||
# **plot_kwargs))
|
||||
# plots.append(pl().xerrorbar(canvas, X[rows,free_dims[0]], X[rows,free_dims[1]],
|
||||
# np.vstack([mu[rows, d] - percs[0][rows, d], percs[1][rows, d] - mu[rows,d]]),
|
||||
# #color=Y[rows,d],
|
||||
# label=label,
|
||||
# **plot_kwargs))
|
||||
else:
|
||||
raise NotImplementedError("Cannot plot in more then one dimension.")
|
||||
raise NotImplementedError("Cannot plot in more then one dimensions, or 3d")
|
||||
return dict(yerrorbars=plots)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -205,15 +205,13 @@ def _plot_samples(self, canvas, helper_data, helper_prediction, projection,
|
|||
if len(free_dims)==1:
|
||||
# 1D plotting:
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.samples_1d) # @UndefinedVariable
|
||||
return dict(gpmean=[pl().plot(canvas, Xgrid[:, free_dims], samples, label=label, **kwargs)])
|
||||
plots = [pl().plot(canvas, Xgrid[:, free_dims], samples[:, s], label=label if s==0 else None, **kwargs) for s in range(samples.shape[-1])]
|
||||
elif len(free_dims)==2 and projection=='3d':
|
||||
update_not_existing_kwargs(kwargs, pl().defaults.samples_3d) # @UndefinedVariable
|
||||
for s in range(samples.shape[-1]):
|
||||
return dict(gpmean=[pl().surface(canvas, x,
|
||||
y, samples[:, s].reshape(resolution, resolution),
|
||||
**kwargs)])
|
||||
plots = [pl().surface(canvas, x, y, samples[:, s].reshape(resolution, resolution), **kwargs) for s in range(samples.shape[-1])]
|
||||
else:
|
||||
pass # Nothing to plot!
|
||||
return dict(gpmean=plots)
|
||||
else:
|
||||
raise RuntimeError('Cannot plot mean in more then 1 input dimensions')
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ it gives back an empty default, when defaults are not defined.
|
|||
data_1d = dict(lw=1.5, marker='x', edgecolor='k')
|
||||
data_2d = dict(s=35, edgecolors='none', linewidth=0., cmap=cm.get_cmap('hot'), alpha=.5)
|
||||
inducing_1d = dict(lw=0, s=500, facecolors=Tango.colorsHex['darkRed'])
|
||||
inducing_2d = dict(s=14, edgecolors='k', linewidth=.4, facecolors='white', alpha=.5)
|
||||
inducing_2d = dict(s=14, edgecolors='k', linewidth=.4, facecolors='white', alpha=.5, marker='^')
|
||||
inducing_3d = dict(lw=.3, s=500, facecolors='white', edgecolors='k')
|
||||
xerrorbar = dict(color='k', fmt='none', elinewidth=.5, alpha=.5)
|
||||
yerrorbar = dict(color=Tango.colorsHex['darkRed'], fmt='none', elinewidth=.5, alpha=.5)
|
||||
|
|
|
|||
|
|
@ -127,18 +127,18 @@ class MatplotlibPlots(AbstractPlottingLibrary):
|
|||
bottom=bottom, label=label, color=color,
|
||||
**kwargs)
|
||||
|
||||
def xerrorbar(self, ax, X, Y, error, Z=None, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs):
|
||||
def xerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs):
|
||||
if not('linestyle' in kwargs or 'ls' in kwargs):
|
||||
kwargs['ls'] = 'none'
|
||||
if Z is not None:
|
||||
return ax.errorbar(X, Y, Z, xerr=error, ecolor=color, label=label, **kwargs)
|
||||
#if Z is not None:
|
||||
# return ax.errorbar(X, Y, Z, xerr=error, ecolor=color, label=label, **kwargs)
|
||||
return ax.errorbar(X, Y, xerr=error, ecolor=color, label=label, **kwargs)
|
||||
|
||||
def yerrorbar(self, ax, X, Y, error, Z=None, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs):
|
||||
def yerrorbar(self, ax, X, Y, error, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs):
|
||||
if not('linestyle' in kwargs or 'ls' in kwargs):
|
||||
kwargs['ls'] = 'none'
|
||||
if Z is not None:
|
||||
return ax.errorbar(X, Y, Z, yerr=error, ecolor=color, label=label, **kwargs)
|
||||
#if Z is not None:
|
||||
# return ax.errorbar(X, Y, Z, yerr=error, ecolor=color, label=label, **kwargs)
|
||||
return ax.errorbar(X, Y, yerr=error, ecolor=color, label=label, **kwargs)
|
||||
|
||||
def imshow(self, ax, X, extent=None, label=None, vmin=None, vmax=None, **imshow_kwargs):
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ def test_plot():
|
|||
X = np.random.uniform(-2, 2, (40, 1))
|
||||
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
|
||||
Y = f+np.random.normal(0, .1, f.shape)
|
||||
m = GPy.models.GPRegression(X, Y)
|
||||
m = GPy.models.SparseGPRegression(X, Y, X_variance=np.ones_like(X)*[0.06])
|
||||
m.optimize()
|
||||
m.plot_data()
|
||||
m.plot_mean()
|
||||
|
|
@ -120,7 +120,11 @@ def test_plot():
|
|||
m.plot_density()
|
||||
m.plot_errorbars_trainset()
|
||||
m.plot_samples()
|
||||
for do_test in _image_comparison(baseline_images=['gp_{}'.format(sub) for sub in ["data", "mean", 'conf', 'density', 'error', 'samples']], extensions=extensions):
|
||||
m.plot_data_error()
|
||||
for do_test in _image_comparison(baseline_images=['gp_{}'.format(sub) for sub in ["data", "mean", 'conf',
|
||||
'density',
|
||||
'out_error',
|
||||
'samples', 'in_error']], extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
||||
def test_twod():
|
||||
|
|
@ -128,11 +132,18 @@ def test_twod():
|
|||
X = np.random.uniform(-2, 2, (40, 2))
|
||||
f = .2 * np.sin(1.3*X[:,[0]]) + 1.3*np.cos(2*X[:,[1]])
|
||||
Y = f+np.random.normal(0, .1, f.shape)
|
||||
m = GPy.models.GPRegression(X, Y)
|
||||
m = GPy.models.SparseGPRegression(X, Y, X_variance=np.ones_like(X)*[0.01, 0.2])
|
||||
m.optimize()
|
||||
m.plot_data()
|
||||
m.plot_mean()
|
||||
for do_test in _image_comparison(baseline_images=['gp_2d_{}'.format(sub) for sub in ["data", "mean"]], extensions=extensions):
|
||||
m.plot_inducing()
|
||||
#m.plot_errorbars_trainset()
|
||||
m.plot_data_error()
|
||||
for do_test in _image_comparison(baseline_images=['gp_2d_{}'.format(sub) for sub in ["data", "mean",
|
||||
'inducing',
|
||||
#'out_error',
|
||||
'in_error',
|
||||
]], extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
||||
def test_threed():
|
||||
|
|
@ -140,7 +151,7 @@ def test_threed():
|
|||
X = np.random.uniform(-2, 2, (40, 2))
|
||||
f = .2 * np.sin(1.3*X[:,[0]]) + 1.3*np.cos(2*X[:,[1]])
|
||||
Y = f+np.random.normal(0, .1, f.shape)
|
||||
m = GPy.models.GPRegression(X, Y)
|
||||
m = GPy.models.SparseGPRegression(X, Y)
|
||||
m.likelihood.variance = .1
|
||||
#m.optimize()
|
||||
m.plot_samples(projection='3d', samples=1)
|
||||
|
|
@ -148,7 +159,10 @@ def test_threed():
|
|||
plt.close('all')
|
||||
m.plot_data(projection='3d')
|
||||
m.plot_mean(projection='3d')
|
||||
for do_test in _image_comparison(baseline_images=['gp_3d_{}'.format(sub) for sub in ["data", "mean",
|
||||
m.plot_inducing(projection='3d')
|
||||
#m.plot_errorbars_trainset(projection='3d')
|
||||
for do_test in _image_comparison(baseline_images=['gp_3d_{}'.format(sub) for sub in ["data", "mean", 'inducing',
|
||||
#'error',
|
||||
#"samples", "samples_lik"
|
||||
]], extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
|
@ -158,10 +172,11 @@ def test_sparse():
|
|||
X = np.random.uniform(-2, 2, (40, 1))
|
||||
f = .2 * np.sin(1.3*X) + 1.3*np.cos(2*X)
|
||||
Y = f+np.random.normal(0, .1, f.shape)
|
||||
m = GPy.models.SparseGPRegression(X, Y)
|
||||
m = GPy.models.SparseGPRegression(X, Y, X_variance=np.ones_like(X)*0.1)
|
||||
m.optimize()
|
||||
m.plot_inducing()
|
||||
for do_test in _image_comparison(baseline_images=['sparse_gp_{}'.format(sub) for sub in ['inducing']], extensions=extensions):
|
||||
#m.plot_inducing()
|
||||
m.plot_data()
|
||||
for do_test in _image_comparison(baseline_images=['sparse_gp_{}'.format(sub) for sub in ['data_error']], extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
||||
def test_classification():
|
||||
|
|
@ -173,9 +188,13 @@ def test_classification():
|
|||
m.optimize()
|
||||
_, ax = plt.subplots()
|
||||
m.plot(plot_raw=False, apply_link=False, ax=ax)
|
||||
m.plot_errorbars_trainset(plot_raw=False, apply_link=False, ax=ax)
|
||||
_, ax = plt.subplots()
|
||||
m.plot(plot_raw=True, apply_link=False, ax=ax)
|
||||
m.plot(plot_raw=True, apply_link=True)
|
||||
m.plot_errorbars_trainset(plot_raw=True, apply_link=False, ax=ax)
|
||||
_, ax = plt.subplots()
|
||||
m.plot(plot_raw=True, apply_link=True, ax=ax)
|
||||
m.plot_errorbars_trainset(plot_raw=True, apply_link=True, ax=ax)
|
||||
for do_test in _image_comparison(baseline_images=['gp_class_{}'.format(sub) for sub in ["likelihood", "raw", 'raw_link']], extensions=extensions):
|
||||
yield (do_test, )
|
||||
|
||||
|
|
|
|||
BIN
GPy/testing/plotting_tests/baseline/gp_2d_in_error.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
GPy/testing/plotting_tests/baseline/gp_2d_inducing.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
BIN
GPy/testing/plotting_tests/baseline/gp_3d_inducing.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 23 KiB |
BIN
GPy/testing/plotting_tests/baseline/gp_in_error.png
Normal file
|
After Width: | Height: | Size: 3 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 7.7 KiB |
BIN
GPy/testing/plotting_tests/baseline/gp_out_error.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 9.7 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 25 KiB |
BIN
GPy/testing/plotting_tests/baseline/sparse_gp_data_error.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |