diff --git a/GPy/kern/__init__.py b/GPy/kern/__init__.py index f8f7d016..e2990f99 100644 --- a/GPy/kern/__init__.py +++ b/GPy/kern/__init__.py @@ -28,4 +28,4 @@ from .src.trunclinear import TruncLinear,TruncLinear_inf from .src.splitKern import SplitKern,DEtime from .src.splitKern import DEtime as DiffGenomeKern from .src.spline import Spline -from .src.basis_funcs import LinearSlopeBasisFuncKernel, BasisFuncKernel, ChangePointBasisFuncKernel, DomainKernel \ No newline at end of file +from .src.basis_funcs import LogisticBasisFuncKernel, LinearSlopeBasisFuncKernel, BasisFuncKernel, ChangePointBasisFuncKernel, DomainKernel \ No newline at end of file diff --git a/GPy/plotting/gpy_plot/latent_plots.py b/GPy/plotting/gpy_plot/latent_plots.py index 240f35ae..976641b2 100644 --- a/GPy/plotting/gpy_plot/latent_plots.py +++ b/GPy/plotting/gpy_plot/latent_plots.py @@ -50,6 +50,19 @@ def _wait_for_updates(view, updates): # No updateable view: pass +def _new_canvas(self, projection, kwargs, which_indices): + input_1, input_2, input_3 = sig_dims = self.get_most_significant_input_dimensions(which_indices) + + if input_3 is None: + zlabel = None + else: + zlabel = 'latent dimension %i' % input_3 + if 'color' not in kwargs: + kwargs['color'] = 'white' + canvas, kwargs = pl().new_canvas(projection=projection, xlabel='latent dimension %i' % input_1, + ylabel='latent dimension %i' % input_2, + zlabel=zlabel, **kwargs) + return canvas, projection, kwargs, sig_dims def _plot_latent_scatter(canvas, X, visible_dims, labels, marker, num_samples, projection='2d', **kwargs): from .. import Tango @@ -85,12 +98,8 @@ def plot_latent_scatter(self, labels=None, :param str marker: markers to use - cycle if more labels then markers are given :param kwargs: the kwargs for the scatter plots """ - input_1, input_2, input_3 = sig_dims = self.get_most_significant_input_dimensions(which_indices) + canvas, projection, kwargs, sig_dims = _new_canvas(self, projection, kwargs, which_indices) - canvas, kwargs = pl().new_canvas(projection=projection, - xlabel='latent dimension %i' % input_1, - ylabel='latent dimension %i' % input_2, - zlabel='latent dimension %i' % input_3, **kwargs) X, _, _ = get_x_y_var(self) if labels is None: labels = np.ones(self.num_data) @@ -101,8 +110,6 @@ def plot_latent_scatter(self, labels=None, return pl().add_to_canvas(canvas, dict(scatter=scatters), legend=legend) - - def plot_latent_inducing(self, which_indices=None, legend=False, @@ -122,17 +129,8 @@ def plot_latent_inducing(self, :param str marker: markers to use - cycle if more labels then markers are given :param kwargs: the kwargs for the scatter plots """ - input_1, input_2, input_3 = sig_dims = self.get_most_significant_input_dimensions(which_indices) - if input_3 is None: zlabel=None - else: zlabel = 'latent dimension %i' % input_3 - + canvas, projection, kwargs, sig_dims = _new_canvas(self, projection, kwargs, which_indices) - if 'color' not in kwargs: - kwargs['color'] = 'white' - canvas, kwargs = pl().new_canvas(projection=projection, - xlabel='latent dimension %i' % input_1, - ylabel='latent dimension %i' % input_2, - zlabel=zlabel, **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) diff --git a/GPy/plotting/matplot_dep/plot_definitions.py b/GPy/plotting/matplot_dep/plot_definitions.py index a33e6bbe..9eb9efb0 100644 --- a/GPy/plotting/matplot_dep/plot_definitions.py +++ b/GPy/plotting/matplot_dep/plot_definitions.py @@ -1,21 +1,21 @@ #=============================================================================== # Copyright (c) 2015, Max Zwiessele # All rights reserved. -# +# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: -# +# # * Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. -# +# # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. -# +# # * Neither the name of GPy.plotting.matplot_dep.plot_definitions nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -41,14 +41,14 @@ class MatplotlibPlots(AbstractPlottingLibrary): def __init__(self): super(MatplotlibPlots, self).__init__() self._defaults = defaults.__dict__ - + def figure(self, rows=1, cols=1, **kwargs): fig = plt.figure(**kwargs) fig.rows = rows fig.cols = cols return fig - - def new_canvas(self, figure=None, col=1, row=1, projection='2d', xlabel=None, ylabel=None, zlabel=None, title=None, xlim=None, ylim=None, zlim=None, **kwargs): + + def new_canvas(self, figure=None, row=1, col=1, projection='2d', xlabel=None, ylabel=None, zlabel=None, title=None, xlim=None, ylim=None, zlim=None, **kwargs): if projection == '3d': from mpl_toolkits.mplot3d import Axes3D elif projection == '2d': @@ -64,10 +64,10 @@ class MatplotlibPlots(AbstractPlottingLibrary): fig = self.figure(figsize=kwargs.pop('figsize')) else: fig = self.figure() - + #if hasattr(fig, 'rows') and hasattr(fig, 'cols'): ax = fig.add_subplot(fig.rows, fig.cols, (col,row), projection=projection) - + if xlim is not None: ax.set_xlim(xlim) if ylim is not None: ax.set_ylim(ylim) if xlabel is not None: ax.set_xlabel(xlabel) @@ -77,7 +77,7 @@ class MatplotlibPlots(AbstractPlottingLibrary): if zlim is not None: ax.set_zlim(zlim) if zlabel is not None: ax.set_zlabel(zlabel) return ax, kwargs - + def add_to_canvas(self, ax, plots, legend=False, title=None, **kwargs): ax.autoscale_view() fontdict=dict(family='sans-serif', weight='light', size=9) @@ -88,18 +88,18 @@ class MatplotlibPlots(AbstractPlottingLibrary): legend_ontop(ax, ncol=legend, fontdict=fontdict) if title is not None: ax.figure.suptitle(title) return ax - + def show_canvas(self, ax, tight_layout=False, **kwargs): if tight_layout: ax.figure.tight_layout() ax.figure.canvas.draw() return ax.figure - + def scatter(self, ax, X, Y, Z=None, color=Tango.colorsHex['mediumBlue'], label=None, marker='o', **kwargs): if Z is not None: return ax.scatter(X, Y, c=color, zs=Z, label=label, marker=marker, **kwargs) return ax.scatter(X, Y, c=color, label=label, marker=marker, **kwargs) - + def plot(self, ax, X, Y, Z=None, color=None, label=None, **kwargs): if Z is not None: return ax.plot(X, Y, color=color, zs=Z, label=label, **kwargs) @@ -122,23 +122,23 @@ class MatplotlibPlots(AbstractPlottingLibrary): if 'align' not in kwargs: kwargs['align'] = 'center' return ax.bar(left=x, height=height, width=width, - bottom=bottom, label=label, color=color, + bottom=bottom, label=label, color=color, **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) return ax.errorbar(X, Y, xerr=error, ecolor=color, label=label, **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) 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): if 'origin' not in imshow_kwargs: imshow_kwargs['origin'] = 'lower' @@ -178,7 +178,7 @@ class MatplotlibPlots(AbstractPlottingLibrary): if 'origin' not in imshow_kwargs: imshow_kwargs['origin'] = 'lower' return ImAnnotateController(ax, plot_function, extent, resolution=resolution, imshow_kwargs=imshow_kwargs or {}, **annotation_kwargs) - + 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) @@ -191,13 +191,13 @@ class MatplotlibPlots(AbstractPlottingLibrary): def fill_gradient(self, canvas, X, percentiles, color=Tango.colorsHex['mediumBlue'], label=None, **kwargs): ax = canvas plots = [] - + if 'edgecolors' not in kwargs: kwargs['edgecolors'] = 'none' - + if 'facecolors' in kwargs: color = kwargs.pop('facecolors') - + if 'array' in kwargs: array = kwargs.pop('array') else: @@ -231,8 +231,8 @@ class MatplotlibPlots(AbstractPlottingLibrary): # pass a, b = tee(iterable) next(b, None) - return zip(a, b) - + return zip(a, b) + polycol = [] for y1, y2 in pairwise(percentiles): import matplotlib.mlab as mlab @@ -244,51 +244,51 @@ class MatplotlibPlots(AbstractPlottingLibrary): x = ma.masked_invalid(ax.convert_xunits(X)) y1 = ma.masked_invalid(ax.convert_yunits(y1)) y2 = ma.masked_invalid(ax.convert_yunits(y2)) - + if y1.ndim == 0: y1 = np.ones_like(x) * y1 if y2.ndim == 0: y2 = np.ones_like(x) * y2 - + if where is None: where = np.ones(len(x), np.bool) else: where = np.asarray(where, np.bool) - + if not (x.shape == y1.shape == y2.shape == where.shape): raise ValueError("Argument dimensions are incompatible") - + from functools import reduce mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)]) if mask is not ma.nomask: where &= ~mask - + polys = [] for ind0, ind1 in mlab.contiguous_regions(where): xslice = x[ind0:ind1] y1slice = y1[ind0:ind1] y2slice = y2[ind0:ind1] - + if not len(xslice): continue - + N = len(xslice) p = np.zeros((2 * N + 2, 2), np.float) - + # the purpose of the next two lines is for when y2 is a # scalar like 0 and we want the fill to go all the way # down to 0 even if none of the y1 sample points do start = xslice[0], y2slice[0] end = xslice[-1], y2slice[-1] - + p[0] = start p[N + 1] = end - + p[1:N + 1, 0] = xslice p[1:N + 1, 1] = y1slice p[N + 2:, 0] = xslice[::-1] p[N + 2:, 1] = y2slice[::-1] - + polys.append(p) polycol.extend(polys) from matplotlib.collections import PolyCollection