diff --git a/GPy/core/gp.py b/GPy/core/gp.py index 16b0ca0f..c08e7906 100644 --- a/GPy/core/gp.py +++ b/GPy/core/gp.py @@ -83,6 +83,9 @@ class GP(Model): assert isinstance(likelihood, likelihoods.Likelihood) self.likelihood = likelihood + if self.kern._effective_input_dim != self.X.shape[1]: + warnings.warn("Your kernel has a different input dimension {} then the given X dimension {}. Be very sure this is what you want and you have not forgotten to set the right input dimenion in your kernel".format(self.kern._effective_input_dim, self.X.shape[1])) + #handle the mean function self.mean_function = mean_function if mean_function is not None: diff --git a/GPy/kern/src/kern.py b/GPy/kern/src/kern.py index c3d98a9b..4d535b60 100644 --- a/GPy/kern/src/kern.py +++ b/GPy/kern/src/kern.py @@ -62,6 +62,10 @@ class Kern(Parameterized): from .psi_comp import PSICOMP_GH self.psicomp = PSICOMP_GH() + @property + def _effective_input_dim(self): + return self._all_dims_active.size + @Cache_this(limit=20) def _slice_X(self, X): return X[:, self._all_dims_active] diff --git a/GPy/plotting/gpy_plot/kernel_plots.py b/GPy/plotting/gpy_plot/kernel_plots.py index 01796d84..492754b2 100644 --- a/GPy/plotting/gpy_plot/kernel_plots.py +++ b/GPy/plotting/gpy_plot/kernel_plots.py @@ -49,7 +49,7 @@ def plot_ARD(kernel, filtering=None, legend=False, **kwargs): bottom = 0 last_bottom = bottom - x = np.arange(kernel.input_dim) + x = np.arange(kernel._effective_input_dim) parts = [] def visit(x): @@ -62,7 +62,7 @@ def plot_ARD(kernel, filtering=None, legend=False, **kwargs): bars = [] kwargs = update_not_existing_kwargs(kwargs, pl().defaults.ard) - canvas, kwargs = pl().new_canvas(xlim=(-.5, kernel.input_dim-.5), xlabel='input dimension', ylabel='sensitivity', **kwargs) + canvas, kwargs = pl().new_canvas(xlim=(-.5, kernel._effective_input_dim-.5), xlabel='input dimension', ylabel='sensitivity', **kwargs) for i in range(ard_params.shape[0]): if parts[i].name in filtering: c = Tango.nextMedium() @@ -94,15 +94,15 @@ def plot_covariance(kernel, x=None, label=None, :param int levels: for 2D projection, how many levels for the contour plot to use? :param kwargs: valid kwargs for your specific plotting library """ - X = np.ones((2, kernel.input_dim)) * [[-3], [3]] + X = np.ones((2, kernel._effective_input_dim)) * [[-3], [3]] _, free_dims, Xgrid, xx, yy, _, _, resolution = helper_for_plot_data(kernel, X, plot_limits, visible_dims, None, resolution) from numbers import Number if x is None: from ...kern.src.stationary import Stationary - x = np.ones((1, kernel.input_dim)) * (not isinstance(kernel, Stationary)) + x = np.ones((1, kernel._effective_input_dim)) * (not isinstance(kernel, Stationary)) elif isinstance(x, Number): - x = np.ones((1, kernel.input_dim))*x + x = np.ones((1, kernel._effective_input_dim))*x K = kernel.K(Xgrid, x) if projection == '3d':