From c302e515e20638db0a4463a2bfba412758e38678 Mon Sep 17 00:00:00 2001 From: James Hensman Date: Thu, 13 Mar 2014 16:44:39 +0000 Subject: [PATCH 1/2] plotting fix --- GPy/core/gp.py | 4 ++-- GPy/likelihoods/gaussian.py | 2 +- GPy/likelihoods/likelihood.py | 2 +- GPy/likelihoods/student_t.py | 2 +- GPy/plotting/matplot_dep/models_plots.py | 3 +-- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/GPy/core/gp.py b/GPy/core/gp.py index a04ac8da..35a41cde 100644 --- a/GPy/core/gp.py +++ b/GPy/core/gp.py @@ -148,7 +148,7 @@ class GP(Model): return Ysim - def posterior_samples(self,X,size=10, full_cov=True, Y_metadata=None): + def posterior_samples(self, X, size=10, full_cov=False, Y_metadata=None): """ Samples the posterior GP at the points X. @@ -163,7 +163,7 @@ class GP(Model): :returns: Ysim: set of simulations, a Numpy array (N x samples). """ Ysim = self.posterior_samples_f(X, size, full_cov=full_cov) - Ysim = self.likelihood.noise_model.samples(Ysim, Y_metadata) + Ysim = self.likelihood.samples(Ysim, Y_metadata) return Ysim diff --git a/GPy/likelihoods/gaussian.py b/GPy/likelihoods/gaussian.py index 032136a7..aaa356b6 100644 --- a/GPy/likelihoods/gaussian.py +++ b/GPy/likelihoods/gaussian.py @@ -94,7 +94,7 @@ class Gaussian(Likelihood): return self.variance + sigma**2 def predictive_quantiles(self, mu, var, quantiles, Y_metadata): - return [stats.norm.ppf(q)*np.sqrt(var) + mu for q in quantiles] + return [stats.norm.ppf(q/100.)*np.sqrt(var) + mu for q in quantiles] def pdf_link(self, link_f, y, extra_data=None): """ diff --git a/GPy/likelihoods/likelihood.py b/GPy/likelihoods/likelihood.py index 67c406df..3eafedb1 100644 --- a/GPy/likelihoods/likelihood.py +++ b/GPy/likelihoods/likelihood.py @@ -397,7 +397,7 @@ class Likelihood(Parameterized): return [np.percentile(ss_y ,q, axis=1)[:,None] for q in quantiles] - def samples(self, gp): + def samples(self, gp, Y_metadata=None): """ Returns a set of samples of observations based on a given value of the latent variable. diff --git a/GPy/likelihoods/student_t.py b/GPy/likelihoods/student_t.py index ce86d9d6..15fd9fa0 100644 --- a/GPy/likelihoods/student_t.py +++ b/GPy/likelihoods/student_t.py @@ -263,7 +263,7 @@ class StudentT(Likelihood): def conditional_variance(self, gp): return self.deg_free/(self.deg_free - 2.) - def samples(self, gp): + def samples(self, gp, Y_metadata=None): """ Returns a set of samples of observations based on a given value of the latent variable. diff --git a/GPy/plotting/matplot_dep/models_plots.py b/GPy/plotting/matplot_dep/models_plots.py index c87eb694..7507c376 100644 --- a/GPy/plotting/matplot_dep/models_plots.py +++ b/GPy/plotting/matplot_dep/models_plots.py @@ -86,8 +86,7 @@ def plot_fit(model, plot_limits=None, which_data_rows='all', upper = m + 2*np.sqrt(v) else: m, v = model.predict(Xgrid, full_cov=False, Y_metadata=Y_metadata) - - lower, upper = model.predict_quantiles(Xgrid, Y_metadata=Y_metadata) + lower, upper = model.predict_quantiles(Xgrid, Y_metadata=Y_metadata) for d in which_data_ycols: From 55f5da69f9eaa9b387a9c41a2265e0d420b7d0e6 Mon Sep 17 00:00:00 2001 From: Alan Saul Date: Thu, 13 Mar 2014 17:09:55 +0000 Subject: [PATCH 2/2] Added test for independent kern --- GPy/testing/kernel_tests.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/GPy/testing/kernel_tests.py b/GPy/testing/kernel_tests.py index d54b3871..673acb92 100644 --- a/GPy/testing/kernel_tests.py +++ b/GPy/testing/kernel_tests.py @@ -258,20 +258,20 @@ class KernelGradientTestsContinuous(unittest.TestCase): # self.N, self.D = 100, 1 # self.X = np.random.randn(self.N,self.D) # self.X2 = np.random.randn(self.N+10,self.D) -# +# # continuous_kerns = ['RBF', 'Linear'] # self.kernclasses = [getattr(GPy.kern, s) for s in continuous_kerns] -# +# # def test_PeriodicExponential(self): # k = GPy.kern.PeriodicExponential(self.D) # k.randomize() # self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose)) -# +# # def test_PeriodicMatern32(self): # k = GPy.kern.PeriodicMatern32(self.D) # k.randomize() # self.assertTrue(check_kernel_gradient_functions(k, X=self.X, X2=self.X2, verbose=verbose)) -# +# # def test_PeriodicMatern52(self): # k = GPy.kern.PeriodicMatern52(self.D) # k.randomize() @@ -279,7 +279,6 @@ class KernelGradientTestsContinuous(unittest.TestCase): class KernelTestsMiscellaneous(unittest.TestCase): - def setUp(self): N, D = 100, 10 self.X = np.linspace(-np.pi, +np.pi, N)[:,None] * np.ones(D) @@ -298,6 +297,24 @@ class KernelTestsMiscellaneous(unittest.TestCase): self.assertTrue(np.allclose(self.sumkern.K(self.X, which_parts=[self.linear, self.rbf]), self.linear.K(self.X)+self.rbf.K(self.X))) self.assertTrue(np.allclose(self.sumkern.K(self.X, which_parts=self.sumkern.parts[0]), self.rbf.K(self.X))) +class KernelTestsNonContinuous(unittest.TestCase): + def setUp(self): + N = 100 + N1 = 110 + self.D = 2 + D = self.D + self.X = np.random.randn(N,D) + self.X2 = np.random.randn(N1,D) + self.X_block = np.zeros((N+N1, D+D+1)) + self.X_block[0:N, 0:D] = self.X + self.X_block[N:N+N1, D:D+D] = self.X2 + self.X_block[0:N, -1] = 1 + self.X_block[N:N+1, -1] = 2 + + def test_IndependantOutputs(self): + k = GPy.kern.RBF(self.D) + kern = GPy.kern.IndependentOutputs(self.D+self.D,k) + self.assertTrue(check_kernel_gradient_functions(kern, X=self.X, X2=self.X2, verbose=verbose)) if __name__ == "__main__": print "Running unit tests, please be (very) patient..."