diff --git a/GPy/plotting/__init__.py b/GPy/plotting/__init__.py index 0fe5ba07..8f82720e 100644 --- a/GPy/plotting/__init__.py +++ b/GPy/plotting/__init__.py @@ -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 diff --git a/GPy/plotting/gpy_plot/data_plots.py b/GPy/plotting/gpy_plot/data_plots.py index a071a427..a24a67ab 100644 --- a/GPy/plotting/gpy_plot/data_plots.py +++ b/GPy/plotting/gpy_plot/data_plots.py @@ -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) diff --git a/GPy/plotting/gpy_plot/gp_plots.py b/GPy/plotting/gpy_plot/gp_plots.py index 53a1a213..2b00dfa8 100644 --- a/GPy/plotting/gpy_plot/gp_plots.py +++ b/GPy/plotting/gpy_plot/gp_plots.py @@ -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') diff --git a/GPy/plotting/matplot_dep/defaults.py b/GPy/plotting/matplot_dep/defaults.py index f67b6e14..eab98298 100644 --- a/GPy/plotting/matplot_dep/defaults.py +++ b/GPy/plotting/matplot_dep/defaults.py @@ -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) diff --git a/GPy/plotting/matplot_dep/plot_definitions.py b/GPy/plotting/matplot_dep/plot_definitions.py index 15578446..3c6ace0c 100644 --- a/GPy/plotting/matplot_dep/plot_definitions.py +++ b/GPy/plotting/matplot_dep/plot_definitions.py @@ -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): diff --git a/GPy/testing/plotting_tests.py b/GPy/testing/plotting_tests.py index 96640eea..b3d3d26d 100644 --- a/GPy/testing/plotting_tests.py +++ b/GPy/testing/plotting_tests.py @@ -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, ) diff --git a/GPy/testing/plotting_tests/baseline/gp_2d_in_error.png b/GPy/testing/plotting_tests/baseline/gp_2d_in_error.png new file mode 100644 index 00000000..9f0652c2 Binary files /dev/null and b/GPy/testing/plotting_tests/baseline/gp_2d_in_error.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_2d_inducing.png b/GPy/testing/plotting_tests/baseline/gp_2d_inducing.png new file mode 100644 index 00000000..8814f0ea Binary files /dev/null and b/GPy/testing/plotting_tests/baseline/gp_2d_inducing.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_2d_mean.png b/GPy/testing/plotting_tests/baseline/gp_2d_mean.png index 44e7caa7..412757da 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_2d_mean.png and b/GPy/testing/plotting_tests/baseline/gp_2d_mean.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_3d_inducing.png b/GPy/testing/plotting_tests/baseline/gp_3d_inducing.png new file mode 100644 index 00000000..00feec6e Binary files /dev/null and b/GPy/testing/plotting_tests/baseline/gp_3d_inducing.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_3d_mean.png b/GPy/testing/plotting_tests/baseline/gp_3d_mean.png index eedf2ca0..715ea28f 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_3d_mean.png and b/GPy/testing/plotting_tests/baseline/gp_3d_mean.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_class_likelihood.png b/GPy/testing/plotting_tests/baseline/gp_class_likelihood.png index 296d4496..7c404553 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_class_likelihood.png and b/GPy/testing/plotting_tests/baseline/gp_class_likelihood.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_class_raw.png b/GPy/testing/plotting_tests/baseline/gp_class_raw.png index 7e407615..c8b7d2aa 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_class_raw.png and b/GPy/testing/plotting_tests/baseline/gp_class_raw.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_class_raw_link.png b/GPy/testing/plotting_tests/baseline/gp_class_raw_link.png index 22b094ea..ebbe6327 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_class_raw_link.png and b/GPy/testing/plotting_tests/baseline/gp_class_raw_link.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_conf.png b/GPy/testing/plotting_tests/baseline/gp_conf.png index 6a41eddf..e7777f11 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_conf.png and b/GPy/testing/plotting_tests/baseline/gp_conf.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_density.png b/GPy/testing/plotting_tests/baseline/gp_density.png index 504dfab6..d1af3d59 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_density.png and b/GPy/testing/plotting_tests/baseline/gp_density.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_in_error.png b/GPy/testing/plotting_tests/baseline/gp_in_error.png new file mode 100644 index 00000000..aea2dc56 Binary files /dev/null and b/GPy/testing/plotting_tests/baseline/gp_in_error.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_mean.png b/GPy/testing/plotting_tests/baseline/gp_mean.png index 61b11ace..abe92100 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_mean.png and b/GPy/testing/plotting_tests/baseline/gp_mean.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_out_error.png b/GPy/testing/plotting_tests/baseline/gp_out_error.png new file mode 100644 index 00000000..e0e8c779 Binary files /dev/null and b/GPy/testing/plotting_tests/baseline/gp_out_error.png differ diff --git a/GPy/testing/plotting_tests/baseline/gp_samples.png b/GPy/testing/plotting_tests/baseline/gp_samples.png index 78c6fbba..155ef420 100644 Binary files a/GPy/testing/plotting_tests/baseline/gp_samples.png and b/GPy/testing/plotting_tests/baseline/gp_samples.png differ diff --git a/GPy/testing/plotting_tests/baseline/sparse_gp_class_likelihood.png b/GPy/testing/plotting_tests/baseline/sparse_gp_class_likelihood.png index 6330696b..d6037c8d 100644 Binary files a/GPy/testing/plotting_tests/baseline/sparse_gp_class_likelihood.png and b/GPy/testing/plotting_tests/baseline/sparse_gp_class_likelihood.png differ diff --git a/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw.png b/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw.png index c1849814..7e91837c 100644 Binary files a/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw.png and b/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw.png differ diff --git a/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw_link.png b/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw_link.png index e0081245..bceb064c 100644 Binary files a/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw_link.png and b/GPy/testing/plotting_tests/baseline/sparse_gp_class_raw_link.png differ diff --git a/GPy/testing/plotting_tests/baseline/sparse_gp_data_error.png b/GPy/testing/plotting_tests/baseline/sparse_gp_data_error.png new file mode 100644 index 00000000..c78a8df1 Binary files /dev/null and b/GPy/testing/plotting_tests/baseline/sparse_gp_data_error.png differ diff --git a/GPy/testing/plotting_tests/baseline/sparse_gp_inducing.png b/GPy/testing/plotting_tests/baseline/sparse_gp_inducing.png deleted file mode 100644 index 24a60044..00000000 Binary files a/GPy/testing/plotting_tests/baseline/sparse_gp_inducing.png and /dev/null differ diff --git a/setup.py b/setup.py index fa8f7e7c..b1ceb425 100644 --- a/setup.py +++ b/setup.py @@ -125,6 +125,7 @@ setup(name = 'GPy', "GPy.plotting.gpy_plot", "GPy.plotting.matplot_dep.controllers", "GPy.plotting.matplot_dep", + "GPy.plotting.plotly_dep", ], package_dir={'GPy': 'GPy'}, package_data = {'GPy': ['defaults.cfg', 'installation.cfg',