diff --git a/GPy/examples/dimensionality_reduction.py b/GPy/examples/dimensionality_reduction.py index c1911e75..8a31968e 100644 --- a/GPy/examples/dimensionality_reduction.py +++ b/GPy/examples/dimensionality_reduction.py @@ -176,7 +176,7 @@ def bgplvm_oil(optimize=True, verbose=1, plot=True, N=200, Q=7, num_inducing=40, if plot: y = m.Y fig, (latent_axes, sense_axes) = plt.subplots(1, 2) - m.plot_latent(ax=latent_axes) + m.plot_latent(ax=latent_axes, labels=m.data_labels) data_show = GPy.plotting.matplot_dep.visualize.vector_show(y) lvm_visualizer = GPy.plotting.matplot_dep.visualize.lvm_dimselect(param_to_array(m.X.mean), # @UnusedVariable m, data_show, latent_axes=latent_axes, sense_axes=sense_axes) diff --git a/GPy/kern/_src/add.py b/GPy/kern/_src/add.py index fb0e114b..88b8e40c 100644 --- a/GPy/kern/_src/add.py +++ b/GPy/kern/_src/add.py @@ -167,4 +167,10 @@ class Add(CombinationKernel): else: self.add_parameter(other) self.input_dim, self.active_dims = self.get_input_dim_active_dims(self.parts) - return self \ No newline at end of file + return self + + def input_sensitivity(self): + in_sen = np.zeros(self.input_dim) + for i, p in enumerate(self.parts): + in_sen[p.active_dims] += p.input_sensitivity() + return in_sen diff --git a/GPy/kern/_src/kern.py b/GPy/kern/_src/kern.py index 6daff739..1ce7cd1e 100644 --- a/GPy/kern/_src/kern.py +++ b/GPy/kern/_src/kern.py @@ -238,7 +238,4 @@ class CombinationKernel(Kern): return input_dim, active_dims def input_sensitivity(self): - in_sen = np.zeros((self.num_params, self.input_dim)) - for i, p in enumerate(self.parts): - in_sen[i, p.active_dims] = p.input_sensitivity() - return in_sen + raise NotImplementedError("Choose the kernel you want to get the sensitivity for. You need to override the default behaviour for getting the input sensitivity to be able to get the input sensitivity. For sum kernel it is the sum of all sensitivities, TODO: product kernel? Other kernels?, also TODO: shall we return all the sensitivities here in the combination kernel? So we can combine them however we want? This could lead to just plot all the sensitivities here...") diff --git a/GPy/kern/_src/kernel_slice_operations.py b/GPy/kern/_src/kernel_slice_operations.py index 10dbacee..0a50fcc3 100644 --- a/GPy/kern/_src/kernel_slice_operations.py +++ b/GPy/kern/_src/kernel_slice_operations.py @@ -42,6 +42,7 @@ class _Slice_wrap(object): self.X2 = self.k._slice_X(X2) if X2 is not None else X2 self.ret = True else: + assert X.shape[1] == self.k.input_dim, "You did not specify active_dims and X has wrong shape: X_dim={} -- input_dim={}".format(X.shape[1], self.input_dim) self.X = X self.X2 = X2 self.ret = False diff --git a/GPy/plotting/matplot_dep/visualize.py b/GPy/plotting/matplot_dep/visualize.py index cf457633..89d36a7d 100644 --- a/GPy/plotting/matplot_dep/visualize.py +++ b/GPy/plotting/matplot_dep/visualize.py @@ -131,10 +131,10 @@ class lvm(matplotlib_show): def modify(self, vals): """When latent values are modified update the latent representation and ulso update the output visualization.""" - self.vals = vals[None,:].copy() + self.vals = vals.copy() y = self.model.predict(self.vals)[0] self.data_visualize.modify(y) - self.latent_handle.set_data(self.vals[:,self.latent_index[0]], self.vals[:,self.latent_index[1]]) + self.latent_handle.set_data(self.vals[0,self.latent_index[0]], self.vals[0,self.latent_index[1]]) self.axes.figure.canvas.draw() @@ -153,8 +153,8 @@ class lvm(matplotlib_show): if event.inaxes!=self.latent_axes: return if self.called and self.move_on: # Call modify code on move - self.latent_values[self.latent_index[0]]=event.xdata - self.latent_values[self.latent_index[1]]=event.ydata + self.latent_values[:, self.latent_index[0]]=event.xdata + self.latent_values[:, self.latent_index[1]]=event.ydata self.modify(self.latent_values) def show_sensitivities(self):