From c598dca830747406b974e0027c624f5503049f50 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Tue, 4 Jun 2013 17:23:46 +0100 Subject: [PATCH 1/5] match_moments function passes transformed values --- GPy/likelihoods/EP.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GPy/likelihoods/EP.py b/GPy/likelihoods/EP.py index 5b538b92..9f410bc1 100644 --- a/GPy/likelihoods/EP.py +++ b/GPy/likelihoods/EP.py @@ -110,7 +110,7 @@ class EP(likelihood): self.tau_[i] = 1./Sigma[i,i] - self.eta*self.tau_tilde[i] self.v_[i] = mu[i]/Sigma[i,i] - self.eta*self.v_tilde[i] #Marginal moments - self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self.data[i],self.tau_[i],self.v_[i]) + self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self._transf_data[i],self.tau_[i],self.v_[i]) #Site parameters update Delta_tau = self.delta/self.eta*(1./sigma2_hat[i] - 1./Sigma[i,i]) Delta_v = self.delta/self.eta*(mu_hat[i]/sigma2_hat[i] - mu[i]/Sigma[i,i]) @@ -200,7 +200,7 @@ class EP(likelihood): self.tau_[i] = 1./Sigma_diag[i] - self.eta*self.tau_tilde[i] self.v_[i] = mu[i]/Sigma_diag[i] - self.eta*self.v_tilde[i] #Marginal moments - self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self.data[i],self.tau_[i],self.v_[i]) + self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self._transf_data[i],self.tau_[i],self.v_[i]) #Site parameters update Delta_tau = self.delta/self.eta*(1./sigma2_hat[i] - 1./Sigma_diag[i]) Delta_v = self.delta/self.eta*(mu_hat[i]/sigma2_hat[i] - mu[i]/Sigma_diag[i]) @@ -295,7 +295,7 @@ class EP(likelihood): self.tau_[i] = 1./Sigma_diag[i] - self.eta*self.tau_tilde[i] self.v_[i] = mu[i]/Sigma_diag[i] - self.eta*self.v_tilde[i] #Marginal moments - self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self.data[i],self.tau_[i],self.v_[i]) + self.Z_hat[i], mu_hat[i], sigma2_hat[i] = self.likelihood_function.moments_match(self._transf_data[i],self.tau_[i],self.v_[i]) #Site parameters update Delta_tau = self.delta/self.eta*(1./sigma2_hat[i] - 1./Sigma_diag[i]) Delta_v = self.delta/self.eta*(mu_hat[i]/sigma2_hat[i] - mu[i]/Sigma_diag[i]) From 6d64559f1f020570bfd01b2a15daa4b7fad127af Mon Sep 17 00:00:00 2001 From: James Hensman Date: Tue, 4 Jun 2013 17:38:05 +0100 Subject: [PATCH 2/5] re-merged. only RA's errors (probit?) remain --- GPy/core/model.py | 4 ++-- GPy/testing/prior_tests.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/GPy/core/model.py b/GPy/core/model.py index da06dee8..3a1d08e9 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -20,7 +20,7 @@ from GPy.core.domains import POSITIVE, REAL class model(parameterised): def __init__(self): parameterised.__init__(self) - self.priors = [None for i in range(self._get_params().size)] + self.priors = None self.optimization_runs = [] self.sampling_runs = [] self.preferred_optimizer = 'tnc' @@ -55,7 +55,7 @@ class model(parameterised): if self.priors is None: self.priors = [None for i in range(self._get_params().size)] - which = self.grep_param_names(which) + which = self.grep_param_names(regexp) # check tied situation tie_partial_matches = [tie for tie in self.tied_indices if (not set(tie).isdisjoint(set(which))) & (not set(tie) == set(which))] diff --git a/GPy/testing/prior_tests.py b/GPy/testing/prior_tests.py index b3e3a440..d3269560 100644 --- a/GPy/testing/prior_tests.py +++ b/GPy/testing/prior_tests.py @@ -15,12 +15,12 @@ class PriorTests(unittest.TestCase): X, y = X[:, None], y[:, None] m = GPy.models.GP_regression(X, y) m.ensure_default_constraints() - lognormal = GPy.priors.log_Gaussian(1, 2) + lognormal = GPy.priors.LogGaussian(1, 2) m.set_prior('rbf', lognormal) m.randomize() self.assertTrue(m.checkgrad()) - def test_gamma(self): + def test_Gamma(self): xmin, xmax = 1, 2.5*np.pi b, C, SNR = 1, 0, 0.1 X = np.linspace(xmin, xmax, 500) @@ -29,8 +29,8 @@ class PriorTests(unittest.TestCase): X, y = X[:, None], y[:, None] m = GPy.models.GP_regression(X, y) m.ensure_default_constraints() - gamma = GPy.priors.gamma(1, 1) - m.set_prior('rbf', gamma) + Gamma = GPy.priors.Gamma(1, 1) + m.set_prior('rbf', Gamma) m.randomize() self.assertTrue(m.checkgrad()) From 7396e5ad214822917289c62f0a3a06ef13d5f95f Mon Sep 17 00:00:00 2001 From: Ricardo Date: Tue, 4 Jun 2013 17:39:38 +0100 Subject: [PATCH 3/5] unit_tests corrected --- GPy/likelihoods/link_functions.py | 8 +++++--- GPy/testing/unit_tests.py | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/GPy/likelihoods/link_functions.py b/GPy/likelihoods/link_functions.py index 28beac71..f3b48d21 100644 --- a/GPy/likelihoods/link_functions.py +++ b/GPy/likelihoods/link_functions.py @@ -19,8 +19,6 @@ class link_function(object): def __init__(self): pass - - class identity(link_function): def transf(self,mu): return mu @@ -53,6 +51,10 @@ class log_ex_1(link_function): return np.log(np.log(np.exp(f)+1)) class probit(link_function): - pass + def inv_transf(self,f): + return std_norm_cdf(f) + + def log_inv_transf(self,f): + return np.log(std_norm_cdf(f)) diff --git a/GPy/testing/unit_tests.py b/GPy/testing/unit_tests.py index 4bdbdca8..9f8eb000 100644 --- a/GPy/testing/unit_tests.py +++ b/GPy/testing/unit_tests.py @@ -169,7 +169,7 @@ class GradientTests(unittest.TestCase): X = np.hstack([np.random.normal(5,2,N/2),np.random.normal(10,2,N/2)])[:,None] Y = np.hstack([np.ones(N/2),np.zeros(N/2)])[:,None] kernel = GPy.kern.rbf(1) - distribution = GPy.likelihoods.likelihood_functions.probit() + distribution = GPy.likelihoods.likelihood_functions.binomial() likelihood = GPy.likelihoods.EP(Y, distribution) m = GPy.core.GP(X, likelihood, kernel) m.ensure_default_constraints() @@ -183,7 +183,7 @@ class GradientTests(unittest.TestCase): Y = np.hstack([np.ones(N/2),np.zeros(N/2)])[:,None] Z = np.linspace(0,15,4)[:,None] kernel = GPy.kern.rbf(1) - distribution = GPy.likelihoods.likelihood_functions.probit() + distribution = GPy.likelihoods.likelihood_functions.binomial() likelihood = GPy.likelihoods.EP(Y, distribution) m = GPy.core.sparse_GP(X, likelihood, kernel,Z) m.ensure_default_constraints() @@ -196,7 +196,7 @@ class GradientTests(unittest.TestCase): 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] - likelihood = GPy.inference.likelihoods.probit(Y) + likelihood = GPy.inference.likelihoods.binomial(Y) m = GPy.models.generalized_FITC(X,likelihood,k,inducing=4) m.constrain_positive('(var|len)') m.approximate_likelihood() From 2e6bbbf12b659b3642aed9ac7c0f3aeba67898ca Mon Sep 17 00:00:00 2001 From: Ricardo Date: Tue, 4 Jun 2013 17:41:03 +0100 Subject: [PATCH 4/5] FITC test not skipped any more --- GPy/testing/unit_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/GPy/testing/unit_tests.py b/GPy/testing/unit_tests.py index 9f8eb000..b2c8196b 100644 --- a/GPy/testing/unit_tests.py +++ b/GPy/testing/unit_tests.py @@ -190,7 +190,6 @@ class GradientTests(unittest.TestCase): m.update_likelihood_approximation() self.assertTrue(m.checkgrad()) - @unittest.skip("FITC will be broken for a while") def test_generalized_FITC(self): N = 20 X = np.hstack([np.random.rand(N/2)+1,np.random.rand(N/2)-1])[:,None] From 6196ed794eb510f6b8af5a028db090182c1fdf9d Mon Sep 17 00:00:00 2001 From: James Hensman Date: Tue, 4 Jun 2013 17:54:36 +0100 Subject: [PATCH 5/5] fixed printing, some example --- GPy/core/model.py | 5 ++++- GPy/examples/regression.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/GPy/core/model.py b/GPy/core/model.py index 3a1d08e9..2acb9963 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -316,7 +316,10 @@ class model(parameterised): def __str__(self): s = parameterised.__str__(self).split('\n') # add priors to the string - strs = [str(p) if p is not None else '' for p in self.priors] + if self.priors is not None: + strs = [str(p) if p is not None else '' for p in self.priors] + else: + strs = ['']*len(self._get_params()) width = np.array(max([len(p) for p in strs] + [5])) + 4 log_like = self.log_likelihood() diff --git a/GPy/examples/regression.py b/GPy/examples/regression.py index 2a9d2b00..3992085d 100644 --- a/GPy/examples/regression.py +++ b/GPy/examples/regression.py @@ -275,7 +275,7 @@ def sparse_GP_regression_1D(N = 400, M = 5, max_nb_eval_optim=100): # create simple GP model m = GPy.models.sparse_GP_regression(X, Y, kernel, M=M) - m.constrain_positive('(variance|lengthscale|precision)') + m.ensure_default_constraints() m.checkgrad(verbose=1) m.optimize('tnc', messages = 1, max_f_eval=max_nb_eval_optim)