From e6b1482d2132a687496b9a2b669c9065f75154b0 Mon Sep 17 00:00:00 2001 From: Zhenwen Dai Date: Mon, 7 Sep 2015 14:04:57 +0100 Subject: [PATCH 1/6] speed tuning for mlp kernel and gauss qudrature for psi-statistics --- GPy/kern/_src/kern.py | 2 ++ GPy/kern/_src/kernel_slice_operations.py | 1 + GPy/kern/_src/mlp.py | 7 +++++++ GPy/kern/_src/psi_comp/gaussherm.py | 5 +++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/GPy/kern/_src/kern.py b/GPy/kern/_src/kern.py index ff5d49d3..531137ae 100644 --- a/GPy/kern/_src/kern.py +++ b/GPy/kern/_src/kern.py @@ -88,6 +88,8 @@ class Kern(Parameterized): return self.psicomp.psicomputations(self, Z, variational_posterior, return_psi2_n=True)[2] def gradients_X(self, dL_dK, X, X2): raise NotImplementedError + def gradients_X_X2(self, dL_dK, X, X2): + return self.gradients_X(dL_dK, X, X2), self.gradients_X(dL_dK.T, X2, X) def gradients_XX(self, dL_dK, X, X2): raise(NotImplementedError, "This is the second derivative of K wrt X and X2, and not implemented for this kernel") def gradients_XX_diag(self, dL_dKdiag, X): diff --git a/GPy/kern/_src/kernel_slice_operations.py b/GPy/kern/_src/kernel_slice_operations.py index 8c06d0c0..f274eef3 100644 --- a/GPy/kern/_src/kernel_slice_operations.py +++ b/GPy/kern/_src/kernel_slice_operations.py @@ -19,6 +19,7 @@ class KernCallsViaSlicerMeta(ParametersChangedMeta): put_clean(dct, 'update_gradients_full', _slice_update_gradients_full) put_clean(dct, 'update_gradients_diag', _slice_update_gradients_diag) put_clean(dct, 'gradients_X', _slice_gradients_X) + put_clean(dct, 'gradients_X_X2', _slice_gradients_X) put_clean(dct, 'gradients_XX', _slice_gradients_XX) put_clean(dct, 'gradients_XX_diag', _slice_gradients_X_diag) put_clean(dct, 'gradients_X_diag', _slice_gradients_X_diag) diff --git a/GPy/kern/_src/mlp.py b/GPy/kern/_src/mlp.py index b65fb2e0..c495b77b 100644 --- a/GPy/kern/_src/mlp.py +++ b/GPy/kern/_src/mlp.py @@ -5,6 +5,7 @@ from .kern import Kern from ...core.parameterization import Param from ...core.parameterization.transformations import Logexp import numpy as np +from ...util.linalg import tdot from ...util.caching import Cache_this four_over_tau = 2./np.pi @@ -40,6 +41,7 @@ class MLP(Kern): self.link_parameters(self.variance, self.weight_variance, self.bias_variance) + @Cache_this(limit=20, ignore_args=()) def K(self, X, X2=None): if X2 is None: X_denom = np.sqrt(self._comp_prod(X)+1.) @@ -51,6 +53,7 @@ class MLP(Kern): XTX = self._comp_prod(X,X2)/X_denom[:,None]/X2_denom[None,:] return self.variance*four_over_tau*np.arcsin(XTX) + @Cache_this(limit=20, ignore_args=()) def Kdiag(self, X): """Compute the diagonal of the covariance matrix for X.""" X_prod = self._comp_prod(X) @@ -73,6 +76,10 @@ class MLP(Kern): """Derivative of the covariance matrix with respect to X""" return self._comp_grads(dL_dK, X, X2)[3] + def gradients_X_X2(self, dL_dK, X, X2): + """Derivative of the covariance matrix with respect to X""" + return self._comp_grads(dL_dK, X, X2)[3:] + def gradients_X_diag(self, dL_dKdiag, X): """Gradient of diagonal of covariance with respect to X""" return self._comp_grads_diag(dL_dKdiag, X)[3] diff --git a/GPy/kern/_src/psi_comp/gaussherm.py b/GPy/kern/_src/psi_comp/gaussherm.py index afbca545..8e54e6a0 100644 --- a/GPy/kern/_src/psi_comp/gaussherm.py +++ b/GPy/kern/_src/psi_comp/gaussherm.py @@ -80,8 +80,9 @@ class PSICOMP_GH(PSICOMP): dL_dkfu = (dL_dpsi1+ 2.*Kfu.dot(dL_dpsi2))*self.weights[i] kern.update_gradients_full(dL_dkfu, X, Z) dtheta += kern.gradient - dX += kern.gradients_X(dL_dkfu, X, Z) - dZ += kern.gradients_X(dL_dkfu.T, Z, X) + dX_i, dZ_i = kern.gradients_X_X2(dL_dkfu, X, Z) + dX += dX_i + dZ += dZ_i dmu += dX dS += dX*self.locs[i]/(2.*S_sq) kern.gradient[:] = dtheta_old From c47c63b4088254755176e81259c071d56f190fdd Mon Sep 17 00:00:00 2001 From: Mike Croucher Date: Mon, 7 Sep 2015 14:07:09 +0100 Subject: [PATCH 2/6] Python 3 fixes --- GPy/core/sparse_gp.py | 4 ++-- GPy/inference/latent_function_inference/laplace.py | 2 +- GPy/likelihoods/gaussian.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GPy/core/sparse_gp.py b/GPy/core/sparse_gp.py index e227625d..9ce5c391 100644 --- a/GPy/core/sparse_gp.py +++ b/GPy/core/sparse_gp.py @@ -49,7 +49,7 @@ class SparseGP(GP): else: #inference_method = ?? raise NotImplementedError("what to do what to do?") - print("defaulting to ", inference_method, "for latent function inference") + print(("defaulting to ", inference_method, "for latent function inference")) self.Z = Param('inducing inputs', Z) self.num_inducing = Z.shape[0] @@ -159,7 +159,7 @@ class SparseGP(GP): mu = np.dot(psi1_star, la) # TODO: dimensions? if full_cov: - raise NotImplementedError, "Full covariance for Sparse GP predicted with uncertain inputs not implemented yet." + raise NotImplementedError("Full covariance for Sparse GP predicted with uncertain inputs not implemented yet.") var = np.empty((Xnew.shape[0], la.shape[1], la.shape[1])) di = np.diag_indices(la.shape[1]) else: diff --git a/GPy/inference/latent_function_inference/laplace.py b/GPy/inference/latent_function_inference/laplace.py index 00a2c2b0..2f089141 100644 --- a/GPy/inference/latent_function_inference/laplace.py +++ b/GPy/inference/latent_function_inference/laplace.py @@ -171,7 +171,7 @@ class Laplace(LatentFunctionInference): #define the objective function (to be maximised) def obj(Ki_f, f): ll = -0.5*np.sum(np.dot(Ki_f.T, f)) + np.sum(likelihood.logpdf(f, Y, Y_metadata=Y_metadata)) - print ll + print(ll) if np.isnan(ll): import ipdb; ipdb.set_trace() # XXX BREAKPOINT return -np.inf diff --git a/GPy/likelihoods/gaussian.py b/GPy/likelihoods/gaussian.py index 424a7f5a..e1299f73 100644 --- a/GPy/likelihoods/gaussian.py +++ b/GPy/likelihoods/gaussian.py @@ -48,7 +48,7 @@ class Gaussian(Likelihood): def betaY(self,Y,Y_metadata=None): #TODO: ~Ricardo this does not live here - raise RuntimeError, "Please notify the GPy developers, this should not happen" + raise RuntimeError("Please notify the GPy developers, this should not happen") return Y/self.gaussian_variance(Y_metadata) def gaussian_variance(self, Y_metadata=None): From 6f29c4646c38e4235aaa89d1db775165415ec82e Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Mon, 7 Sep 2015 14:09:55 +0100 Subject: [PATCH 3/6] [coverage] tests for coverage increase --- GPy/testing/cacher_tests.py | 37 ++++++++++++++ GPy/testing/gp_tests.py | 99 +++++++++++++++++++++++++++++++++++++ GPy/testing/model_tests.py | 48 +++++++++++++++++- GPy/testing/run_coverage.sh | 2 +- 4 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 GPy/testing/cacher_tests.py create mode 100644 GPy/testing/gp_tests.py diff --git a/GPy/testing/cacher_tests.py b/GPy/testing/cacher_tests.py new file mode 100644 index 00000000..60f79ba2 --- /dev/null +++ b/GPy/testing/cacher_tests.py @@ -0,0 +1,37 @@ +''' +Created on 4 Sep 2015 + +@author: maxz +''' +import unittest +from GPy.util.caching import Cacher +from pickle import PickleError + + +class Test(unittest.TestCase): + def setUp(self): + def op(x): + return x + self.cache = Cacher(op, 1) + + def test_pickling(self): + self.assertRaises(PickleError, self.cache.__getstate__) + self.assertRaises(PickleError, self.cache.__setstate__) + + def test_copy(self): + tmp = self.cache.__deepcopy__() + assert(tmp.operation is self.cache.operation) + self.assertEqual(tmp.limit, self.cache.limit) + + def test_reset(self): + self.cache.reset() + self.assertDictEqual(self.cache.cached_input_ids, {}, ) + self.assertDictEqual(self.cache.cached_outputs, {}, ) + self.assertDictEqual(self.cache.inputs_changed, {}, ) + + def test_name(self): + assert(self.cache.__name__ == self.cache.operation.__name__) + +if __name__ == "__main__": + #import sys;sys.argv = ['', 'Test.testName'] + unittest.main() \ No newline at end of file diff --git a/GPy/testing/gp_tests.py b/GPy/testing/gp_tests.py new file mode 100644 index 00000000..07aa31a3 --- /dev/null +++ b/GPy/testing/gp_tests.py @@ -0,0 +1,99 @@ +''' +Created on 4 Sep 2015 + +@author: maxz +''' +import unittest +import numpy as np, GPy +from GPy.core.parameterization.variational import NormalPosterior + +class Test(unittest.TestCase): + + + def setUp(self): + np.random.seed(12345) + self.N = 20 + self.N_new = 50 + self.D = 1 + self.X = np.random.uniform(-3., 3., (self.N, 1)) + self.Y = np.sin(self.X) + np.random.randn(self.N, self.D) * 0.05 + self.X_new = np.random.uniform(-3., 3., (self.N_new, 1)) + + + def test_setxy_bgplvm(self): + k = GPy.kern.RBF(1) + m = GPy.models.BayesianGPLVM(self.Y, 2, kernel=k) + mu, var = m.predict(m.X) + X = m.X.copy() + Xnew = NormalPosterior(m.X.mean[:10].copy(), m.X.variance[:10].copy()) + m.set_XY(Xnew, m.Y[:10]) + assert(m.checkgrad()) + m.set_XY(X, self.Y) + mu2, var2 = m.predict(m.X) + np.testing.assert_allclose(mu, mu2) + np.testing.assert_allclose(var, var2) + + def test_setxy_gplvm(self): + k = GPy.kern.RBF(1) + m = GPy.models.GPLVM(self.Y, 2, kernel=k) + mu, var = m.predict(m.X) + X = m.X.copy() + Xnew = X[:10].copy() + m.set_XY(Xnew, m.Y[:10]) + assert(m.checkgrad()) + m.set_XY(X, self.Y) + mu2, var2 = m.predict(m.X) + np.testing.assert_allclose(mu, mu2) + np.testing.assert_allclose(var, var2) + + def test_setxy_gp(self): + k = GPy.kern.RBF(1) + m = GPy.models.GPRegression(self.X, self.Y, kernel=k) + mu, var = m.predict(m.X) + X = m.X.copy() + m.set_XY(m.X[:10], m.Y[:10]) + assert(m.checkgrad()) + m.set_XY(X, self.Y) + mu2, var2 = m.predict(m.X) + np.testing.assert_allclose(mu, mu2) + np.testing.assert_allclose(var, var2) + + def test_mean_function(self): + from GPy.core.parameterization.param import Param + from GPy.core.mapping import Mapping + class Parabola(Mapping): + def __init__(self, variance, degree=2, name='parabola'): + super(Parabola, self).__init__(1, 1, name) + self.variance = Param('variance', np.ones(degree+1) * variance) + self.degree = degree + self.link_parameter(self.variance) + + def f(self, X): + p = self.variance[0] * np.ones(X.shape) + for i in range(1, self.degree+1): + p += self.variance[i] * X**(i) + return p + + def gradients_X(self, dL_dF, X): + grad = np.zeros(X.shape) + for i in range(1, self.degree+1): + grad += (i) * self.variance[i] * X**(i-1) + return grad + + def update_gradients(self, dL_dF, X): + for i in range(self.degree+1): + self.variance.gradient[i] = (dL_dF * X**(i)).sum(0) + X = np.linspace(-2, 2, 100)[:, None] + k = GPy.kern.RBF(1) + k.randomize() + p = Parabola(.3) + p.randomize() + Y = p.f(X) + np.random.multivariate_normal(np.zeros(X.shape[0]), k.K(X))[:,None] + np.random.normal(0, .1, (X.shape[0], 1)) + m = GPy.models.GPRegression(X, Y, mean_function=p) + m.randomize() + assert(m.checkgrad()) + _ = m.predict(m.X) + +if __name__ == "__main__": + #import sys;sys.argv = ['', 'Test.testName'] + unittest.main() \ No newline at end of file diff --git a/GPy/testing/model_tests.py b/GPy/testing/model_tests.py index 648e1174..75165c0e 100644 --- a/GPy/testing/model_tests.py +++ b/GPy/testing/model_tests.py @@ -55,13 +55,44 @@ class MiscTests(unittest.TestCase): np.testing.assert_allclose(mu1, (mu2*std)+mu) np.testing.assert_allclose(var1, var2) + q50n = m.predict_quantiles(m.X, (50,)) + q50 = m2.predict_quantiles(m2.X, (50,)) + np.testing.assert_allclose(q50n[0], (q50[0]*std)+mu) + + def check_jacobian(self): + try: + import autograd.numpy as np, autograd as ag, GPy, matplotlib.pyplot as plt + except: + raise self.skipTest("autograd not available to check gradients") + def k(X, X2, alpha=1., lengthscale=None): + if lengthscale is None: + lengthscale = np.ones(X.shape[1]) + exp = 0. + for q in range(X.shape[1]): + exp += ((X[:, [q]] - X2[:, [q]].T)/lengthscale[q])**2 + #exp = np.sqrt(exp) + return alpha * np.exp(-.5*exp) + dk = ag.elementwise_grad(lambda x, x2: k(x, x2, alpha=ke.variance.values, lengthscale=ke.lengthscale.values)) + dkdk = ag.elementwise_grad(dk, argnum=1) + + ke = GPy.kern.RBF(1, ARD=True) + #ke.randomize() + ke.variance = .2#.randomize() + ke.lengthscale[:] = .5 + ke.randomize() + X = np.linspace(-1, 1, 1000)[:,None] + X2 = np.array([[0.]]).T + np.testing.assert_allclose(ke.gradients_X([[1.]], X, X), dk(X, X)) + np.testing.assert_allclose(ke.gradients_XX([[1.]], X, X).sum(0), dkdk(X, X)) + np.testing.assert_allclose(ke.gradients_X([[1.]], X, X2), dk(X, X2)) + np.testing.assert_allclose(ke.gradients_XX([[1.]], X, X2).sum(0), dkdk(X, X2)) + def test_sparse_raw_predict(self): k = GPy.kern.RBF(1) m = GPy.models.SparseGPRegression(self.X, self.Y, kernel=k) m.randomize() Z = m.Z[:] - X = self.X[:] # Not easy to check if woodbury_inv is correct in itself as it requires a large derivation and expression Kinv = m.posterior.woodbury_inv @@ -147,11 +178,24 @@ class MiscTests(unittest.TestCase): m = BayesianGPLVMMiniBatch(Ymissing, Q, init="random", num_inducing=num_inducing, kernel=k, missing_data=True) assert(m.checkgrad()) + mul, varl = m.predict(m.X) k = kern.RBF(Q, ARD=True) + kern.White(Q, np.exp(-2)) # + kern.bias(Q) - m = BayesianGPLVMMiniBatch(Ymissing, Q, init="random", num_inducing=num_inducing, + m2 = BayesianGPLVMMiniBatch(Ymissing, Q, init="random", num_inducing=num_inducing, kernel=k, missing_data=True) assert(m.checkgrad()) + m2.kern.rbf.lengthscale[:] = 1e6 + m2.X[:] = m.X.param_array + m2.likelihood[:] = m.likelihood[:] + m2.kern.white[:] = m.kern.white[:] + mu, var = m.predict(m.X) + np.testing.assert_allclose(mul, mu) + np.testing.assert_allclose(varl, var) + + q50 = m.predict_quantiles(m.X, (50,)) + np.testing.assert_allclose(mul, q50[0]) + + def test_likelihood_replicate_kern(self): m = GPy.models.GPRegression(self.X, self.Y) diff --git a/GPy/testing/run_coverage.sh b/GPy/testing/run_coverage.sh index 6b6e8cb2..f2e52230 100755 --- a/GPy/testing/run_coverage.sh +++ b/GPy/testing/run_coverage.sh @@ -1 +1 @@ -nosetests . --with-coverage --cover-html --cover-html-dir=coverage --cover-package=GPy --cover-erase +nosetests . --with-coverage --logging-level=INFO --cover-html --cover-html-dir=coverage --cover-package=GPy --cover-erase From 63e1fa05e47f26a152b2fbfa78b3afb7b4105426 Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Mon, 7 Sep 2015 14:10:36 +0100 Subject: [PATCH 4/6] [mean func] added in GPRegression --- GPy/models/gp_regression.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GPy/models/gp_regression.py b/GPy/models/gp_regression.py index 7266ae92..157c0dc8 100644 --- a/GPy/models/gp_regression.py +++ b/GPy/models/gp_regression.py @@ -26,12 +26,12 @@ class GPRegression(GP): """ - def __init__(self, X, Y, kernel=None, Y_metadata=None, normalizer=None, noise_var=1.): + def __init__(self, X, Y, kernel=None, Y_metadata=None, normalizer=None, noise_var=1., mean_function=None): if kernel is None: kernel = kern.RBF(X.shape[1]) - + likelihood = likelihoods.Gaussian(variance=noise_var) - super(GPRegression, self).__init__(X, Y, kernel, likelihood, name='GP regression', Y_metadata=Y_metadata, normalizer=normalizer) + super(GPRegression, self).__init__(X, Y, kernel, likelihood, name='GP regression', Y_metadata=Y_metadata, normalizer=normalizer, mean_function=mean_function) From 78257d2314adc72c1adc957e69a4d4993e1bd06c Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Mon, 7 Sep 2015 14:11:01 +0100 Subject: [PATCH 5/6] [predict] using gp predict in sparse gp and predictive variable --- GPy/core/gp.py | 2 +- GPy/core/sparse_gp.py | 47 ++++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/GPy/core/gp.py b/GPy/core/gp.py index fc76ad68..ad082b3c 100644 --- a/GPy/core/gp.py +++ b/GPy/core/gp.py @@ -205,7 +205,7 @@ class GP(Model): if kern is None: kern = self.kern - Kx = kern.K(self.X, Xnew) + Kx = kern.K(self._predictive_variable, Xnew) mu = np.dot(Kx.T, self.posterior.woodbury_vector) if len(mu.shape)==1: mu = mu.reshape(-1,1) diff --git a/GPy/core/sparse_gp.py b/GPy/core/sparse_gp.py index e227625d..38c0d638 100644 --- a/GPy/core/sparse_gp.py +++ b/GPy/core/sparse_gp.py @@ -128,29 +128,30 @@ class SparseGP(GP): if kern is None: kern = self.kern if not isinstance(Xnew, VariationalPosterior): - Kx = kern.K(self._predictive_variable, Xnew) - mu = np.dot(Kx.T, self.posterior.woodbury_vector) - if full_cov: - Kxx = kern.K(Xnew) - if self.posterior.woodbury_inv.ndim == 2: - var = Kxx - np.dot(Kx.T, np.dot(self.posterior.woodbury_inv, Kx)) - elif self.posterior.woodbury_inv.ndim == 3: - var = np.empty((Kxx.shape[0],Kxx.shape[1],self.posterior.woodbury_inv.shape[2])) - for i in range(var.shape[2]): - var[:, :, i] = (Kxx - mdot(Kx.T, self.posterior.woodbury_inv[:, :, i], Kx)) - var = var - else: - Kxx = kern.Kdiag(Xnew) - if self.posterior.woodbury_inv.ndim == 2: - var = (Kxx - np.sum(np.dot(self.posterior.woodbury_inv.T, Kx) * Kx, 0))[:,None] - elif self.posterior.woodbury_inv.ndim == 3: - var = np.empty((Kxx.shape[0],self.posterior.woodbury_inv.shape[2])) - for i in range(var.shape[1]): - var[:, i] = (Kxx - (np.sum(np.dot(self.posterior.woodbury_inv[:, :, i].T, Kx) * Kx, 0))) - var = var - #add in the mean function - if self.mean_function is not None: - mu += self.mean_function.f(Xnew) + # Kx = kern.K(self._predictive_variable, Xnew) + # mu = np.dot(Kx.T, self.posterior.woodbury_vector) + # if full_cov: + # Kxx = kern.K(Xnew) + # if self.posterior.woodbury_inv.ndim == 2: + # var = Kxx - np.dot(Kx.T, np.dot(self.posterior.woodbury_inv, Kx)) + # elif self.posterior.woodbury_inv.ndim == 3: + # var = np.empty((Kxx.shape[0],Kxx.shape[1],self.posterior.woodbury_inv.shape[2])) + # for i in range(var.shape[2]): + # var[:, :, i] = (Kxx - mdot(Kx.T, self.posterior.woodbury_inv[:, :, i], Kx)) + # var = var + # else: + # Kxx = kern.Kdiag(Xnew) + # if self.posterior.woodbury_inv.ndim == 2: + # var = (Kxx - np.sum(np.dot(self.posterior.woodbury_inv.T, Kx) * Kx, 0))[:,None] + # elif self.posterior.woodbury_inv.ndim == 3: + # var = np.empty((Kxx.shape[0],self.posterior.woodbury_inv.shape[2])) + # for i in range(var.shape[1]): + # var[:, i] = (Kxx - (np.sum(np.dot(self.posterior.woodbury_inv[:, :, i].T, Kx) * Kx, 0))) + # var = var + # #add in the mean function + # if self.mean_function is not None: + # mu += self.mean_function.f(Xnew) + mu, var = super(SparseGP, self)._raw_predict(Xnew, full_cov, kern) else: psi0_star = kern.psi0(self._predictive_variable, Xnew) psi1_star = kern.psi1(self._predictive_variable, Xnew) From ec7334846c82634731a4054f3a292c6ca468df83 Mon Sep 17 00:00:00 2001 From: Mike Croucher Date: Mon, 7 Sep 2015 15:18:45 +0100 Subject: [PATCH 6/6] Python 3 fixes --- GPy/inference/optimization/stochastics.py | 4 ++-- GPy/plotting/matplot_dep/models_plots.py | 6 +++--- GPy/testing/misc_tests.py | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/GPy/inference/optimization/stochastics.py b/GPy/inference/optimization/stochastics.py index 0fc488a2..902c4290 100644 --- a/GPy/inference/optimization/stochastics.py +++ b/GPy/inference/optimization/stochastics.py @@ -40,7 +40,7 @@ class SparseGPMissing(StochasticStorage): bdict = {} #For N > 1000 array2string default crops opt = np.get_printoptions() - np.set_printoptions(threshold='nan') + np.set_printoptions(threshold=np.inf) for d in range(self.Y.shape[1]): inan = np.isnan(self.Y)[:, d] arr_str = np.array2string(inan, np.inf, 0, True, '', formatter={'bool':lambda x: '1' if x else '0'}) @@ -74,7 +74,7 @@ class SparseGPStochastics(StochasticStorage): bdict = {} if self.missing_data: opt = np.get_printoptions() - np.set_printoptions(threshold='nan') + np.set_printoptions(threshold=np.inf) for d in self.d: inan = np.isnan(self.Y[:, d]) arr_str = np.array2string(inan,np.inf, 0,True, '',formatter={'bool':lambda x: '1' if x else '0'}) diff --git a/GPy/plotting/matplot_dep/models_plots.py b/GPy/plotting/matplot_dep/models_plots.py index 87ffd740..3a5a01d2 100644 --- a/GPy/plotting/matplot_dep/models_plots.py +++ b/GPy/plotting/matplot_dep/models_plots.py @@ -3,7 +3,7 @@ import numpy as np from . import Tango -from base_plots import gpplot, x_frame1D, x_frame2D,gperrors +from .base_plots import gpplot, x_frame1D, x_frame2D,gperrors from ...models.gp_coregionalized_regression import GPCoregionalizedRegression from ...models.sparse_gp_coregionalized_regression import SparseGPCoregionalizedRegression from scipy import sparse @@ -186,8 +186,8 @@ def plot_fit(model, plot_limits=None, which_data_rows='all', #optionally plot some samples if samples: #NOTE not tested with fixed_inputs Ysim = model.posterior_samples(Xgrid, samples, Y_metadata=Y_metadata) - print Ysim.shape - print Xnew.shape + print(Ysim.shape) + print(Xnew.shape) for yi in Ysim.T: plots['posterior_samples'] = ax.plot(Xnew, yi[:,None], '#3300FF', linewidth=0.25) #ax.plot(Xnew, yi[:,None], marker='x', linestyle='--',color=Tango.colorsHex['darkBlue']) #TODO apply this line for discrete outputs. diff --git a/GPy/testing/misc_tests.py b/GPy/testing/misc_tests.py index caf98874..a0e2d949 100644 --- a/GPy/testing/misc_tests.py +++ b/GPy/testing/misc_tests.py @@ -1,3 +1,4 @@ +from __future__ import print_function import numpy as np import scipy as sp import GPy @@ -18,8 +19,8 @@ class MiscTests(np.testing.TestCase): assert np.isinf(np.exp(self._lim_val_exp + 1)) assert np.isfinite(GPy.util.misc.safe_exp(self._lim_val_exp + 1)) - print w - print len(w) + print(w) + print(len(w)) assert len(w)==1 # should have one overflow warning def test_safe_exp_lower(self):