diff --git a/GPy/core/sparse_GP.py b/GPy/core/sparse_GP.py index 55cff38f..fa96132f 100644 --- a/GPy/core/sparse_GP.py +++ b/GPy/core/sparse_GP.py @@ -286,6 +286,9 @@ class sparse_GP(GPBase): fig = pb.figure(num=fignum) ax = fig.add_subplot(111) + if which_data is 'all': + which_data = slice(None) + GPBase.plot(self, samples=0, plot_limits=None, which_data='all', which_parts='all', resolution=None, levels=20, ax=ax) if self.X.shape[1] == 1: if self.has_uncertain_inputs: diff --git a/GPy/examples/regression.py b/GPy/examples/regression.py index e26c7afe..b0ee14cc 100644 --- a/GPy/examples/regression.py +++ b/GPy/examples/regression.py @@ -310,6 +310,8 @@ def sparse_GP_regression_2D(N = 400, M = 50, max_nb_eval_optim=100): def uncertain_inputs_sparse_regression(max_nb_eval_optim=100): """Run a 1D example of a sparse GP regression with uncertain inputs.""" + fig, axes = pb.subplots(1,2,figsize=(12,5)) + # sample inputs and outputs S = np.ones((20,1)) X = np.random.uniform(-3.,3.,(20,1)) @@ -319,14 +321,22 @@ def uncertain_inputs_sparse_regression(max_nb_eval_optim=100): k = GPy.kern.rbf(1) + GPy.kern.white(1) - # create simple GP model - m = GPy.models.sparse_GP_regression(X, Y, kernel=k, Z=Z, X_variance=S) - - # contrain all parameters to be positive + # create simple GP model - no input uncertainty on this one + m = GPy.models.sparse_GP_regression(X, Y, kernel=k, Z=Z) m.ensure_default_constraints() + m.optimize('scg', messages=1, max_f_eval=max_nb_eval_optim) + m.plot(ax=axes[0]) + axes[0].set_title('no input uncertainty') - # optimize and plot - m.optimize('tnc', messages=1, max_f_eval=max_nb_eval_optim) - m.plot() + + #the same model with uncertainty + m = GPy.models.sparse_GP_regression(X, Y, kernel=k, Z=Z, X_variance=S) + m.ensure_default_constraints() + m.optimize('scg', messages=1, max_f_eval=max_nb_eval_optim) + m.plot(ax=axes[1]) + axes[1].set_title('with input uncertainty') print(m) + + fig.canvas.draw() + return m