From 616e8c9026941672b268e21a9b8c5194a07a1374 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Wed, 5 Jun 2013 18:01:53 +0100 Subject: [PATCH] Minor changes --- GPy/core/fitc.py | 3 ++- GPy/core/gp.py | 1 + GPy/core/sparse_gp.py | 2 +- GPy/models/fitc_classification.py | 4 ++-- GPy/testing/unit_tests.py | 14 ++++---------- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/GPy/core/fitc.py b/GPy/core/fitc.py index 604db5e8..515abc29 100644 --- a/GPy/core/fitc.py +++ b/GPy/core/fitc.py @@ -36,8 +36,9 @@ class FITC(SparseGP): For a Gaussian likelihood, no iteration is required: this function does nothing """ + self.likelihood.restart() self.likelihood.fit_FITC(self.Kmm,self.psi1,self.psi0) - self._set_params(self._get_params()) # update the GP + self._set_params(self._get_params()) def _compute_kernel_matrices(self): # kernel computations, using BGPLVM notation diff --git a/GPy/core/gp.py b/GPy/core/gp.py index 246b8cc9..115c8d0f 100644 --- a/GPy/core/gp.py +++ b/GPy/core/gp.py @@ -67,6 +67,7 @@ class GP(GPBase): For a Gaussian likelihood, no iteration is required: this function does nothing """ + self.likelihood.restart() self.likelihood.fit_full(self.kern.K(self.X)) self._set_params(self._get_params()) # update the GP diff --git a/GPy/core/sparse_gp.py b/GPy/core/sparse_gp.py index 2cfc8ae4..c1aed5d5 100644 --- a/GPy/core/sparse_gp.py +++ b/GPy/core/sparse_gp.py @@ -173,7 +173,7 @@ class SparseGP(GPBase): this function does nothing """ if not isinstance(self.likelihood, Gaussian): # Updates not needed for Gaussian likelihood - self.likelihood.restart() # TODO check consistency with pseudo_EP + self.likelihood.restart() if self.has_uncertain_inputs: Lmi = chol_inv(self.Lm) Kmmi = tdot(Lmi.T) diff --git a/GPy/models/fitc_classification.py b/GPy/models/fitc_classification.py index 4ff441c6..e2c48b69 100644 --- a/GPy/models/fitc_classification.py +++ b/GPy/models/fitc_classification.py @@ -26,7 +26,7 @@ class FITCClassification(FITC): """ - def __init__(self, X, Y=None, likelihood=None, kernel=None, normalize_X=False, normalize_Y=False, Z=None, M=10): + def __init__(self, X, Y=None, likelihood=None, kernel=None, normalize_X=False, normalize_Y=False, Z=None, num_inducing=10): if kernel is None: kernel = kern.rbf(X.shape[1]) + kern.white(X.shape[1],1e-3) @@ -38,7 +38,7 @@ class FITCClassification(FITC): raise Warning, 'likelihood.data and Y are different.' if Z is None: - i = np.random.permutation(X.shape[0])[:M] + i = np.random.permutation(X.shape[0])[:num_inducing] Z = X[i].copy() else: assert Z.shape[1]==X.shape[1] diff --git a/GPy/testing/unit_tests.py b/GPy/testing/unit_tests.py index 7ee9ef40..494ebf19 100644 --- a/GPy/testing/unit_tests.py +++ b/GPy/testing/unit_tests.py @@ -175,7 +175,6 @@ class GradientTests(unittest.TestCase): m.ensure_default_constraints() m.update_likelihood_approximation() self.assertTrue(m.checkgrad()) - # self.assertTrue(m.EPEM) def test_sparse_EP_DTC_probit(self): N = 20 @@ -194,17 +193,12 @@ class GradientTests(unittest.TestCase): N = 20 X = np.hstack([np.random.rand(N / 2) + 1, np.random.rand(N / 2) - 1])[:, None] k = GPy.kern.rbf(1) + GPy.kern.white(1) - Y = np.hstack([np.ones(N/2),-np.ones(N/2)])[:,None] - - distribution = GPy.likelihoods.likelihood_functions.Binomial() - likelihood = GPy.likelihoods.EP(Y, distribution) - #likelihood = GPy.inference.likelihoods.Binomial(Y) - m = GPy.models.generalized_FITC(X,likelihood,k,inducing=4) - m.constrain_positive('(var|len)') - m.approximate_likelihood() + Y = np.hstack([np.ones(N/2),np.zeros(N/2)])[:,None] + m = GPy.models.FITCClassification(X, Y=Y) + m.ensure_default_constraints() + m.update_likelihood_approximation() self.assertTrue(m.checkgrad()) - if __name__ == "__main__": print "Running unit tests, please be (very) patient..." unittest.main()