From fc59ef4baf8044eb9496ef9b6d5919f8cadd9d57 Mon Sep 17 00:00:00 2001 From: Alan Saul Date: Mon, 28 Oct 2013 15:42:25 +0000 Subject: [PATCH] Tidying up and fixed objective being vector --- GPy/likelihoods/laplace.py | 8 ++++---- GPy/likelihoods/noise_models/exponential_noise.py | 7 ++++--- GPy/likelihoods/noise_models/gamma_noise.py | 6 ++++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/GPy/likelihoods/laplace.py b/GPy/likelihoods/laplace.py index 8a11b146..7e570e52 100644 --- a/GPy/likelihoods/laplace.py +++ b/GPy/likelihoods/laplace.py @@ -340,8 +340,8 @@ class Laplace(likelihood): Ki_f = old_Ki_f + step_size*dKi_f f = np.dot(K, Ki_f) # This is nasty, need to set something within an optimization though - self.Ki_f = Ki_f.copy() - self.f = f.copy() + self.tmp_Ki_f = Ki_f.copy() + self.tmp_f = f.copy() return -obj(Ki_f, f) i_o = partial_func(inner_obj, old_Ki_f=old_Ki_f, dKi_f=dKi_f, K=K) @@ -349,8 +349,8 @@ class Laplace(likelihood): #The tolerance and maxiter matter for speed! Seems to be best to keep them low and make more full #steps than get this exact then make a step, if B was bigger it might be the other way around though new_obj = sp.optimize.minimize_scalar(i_o, method='brent', tol=1e-4, options={'maxiter':5}).fun - f = self.f.copy() - Ki_f = self.Ki_f.copy() + f = self.tmp_f.copy() + Ki_f = self.tmp_Ki_f.copy() #Optimize without linesearch #f_old = f.copy() diff --git a/GPy/likelihoods/noise_models/exponential_noise.py b/GPy/likelihoods/noise_models/exponential_noise.py index 8e916353..e637cc02 100644 --- a/GPy/likelihoods/noise_models/exponential_noise.py +++ b/GPy/likelihoods/noise_models/exponential_noise.py @@ -40,7 +40,8 @@ class Exponential(NoiseDistribution): :rtype: float """ assert np.atleast_1d(link_f).shape == np.atleast_1d(y).shape - return np.exp(np.sum(np.log(link_f*np.exp(-y*link_f)))) + log_objective = link_f*np.exp(-y*link_f) + return np.exp(np.sum(np.log(log_objective))) #return np.exp(np.sum(-y/link_f - np.log(link_f) )) def logpdf_link(self, link_f, y, extra_data=None): @@ -60,9 +61,9 @@ class Exponential(NoiseDistribution): """ assert np.atleast_1d(link_f).shape == np.atleast_1d(y).shape - logpdf_link = np.sum(np.log(link_f) - y*link_f) + log_objective = np.log(link_f) - y*link_f #logpdf_link = np.sum(-np.log(link_f) - y/link_f) - return logpdf_link + return np.sum(log_objective) def dlogpdf_dlink(self, link_f, y, extra_data=None): """ diff --git a/GPy/likelihoods/noise_models/gamma_noise.py b/GPy/likelihoods/noise_models/gamma_noise.py index 2e4e7d15..2be3106a 100644 --- a/GPy/likelihoods/noise_models/gamma_noise.py +++ b/GPy/likelihoods/noise_models/gamma_noise.py @@ -44,7 +44,8 @@ class Gamma(NoiseDistribution): assert np.atleast_1d(link_f).shape == np.atleast_1d(y).shape #return stats.gamma.pdf(obs,a = self.gp_link.transf(gp)/self.variance,scale=self.variance) alpha = link_f*self.beta - return (y**(alpha - 1.) * np.exp(-self.beta*y) * self.beta**alpha)/ special.gamma(alpha) + objective = (y**(alpha - 1.) * np.exp(-self.beta*y) * self.beta**alpha)/ special.gamma(alpha) + return np.exp(np.sum(np.log(objective))) def logpdf_link(self, link_f, y, extra_data=None): """ @@ -67,7 +68,8 @@ class Gamma(NoiseDistribution): #alpha = self.gp_link.transf(gp)*self.beta #return (1. - alpha)*np.log(obs) + self.beta*obs - alpha * np.log(self.beta) + np.log(special.gamma(alpha)) alpha = link_f*self.beta - return alpha*np.log(self.beta) - np.log(special.gamma(alpha)) + (alpha - 1)*np.log(y) - self.beta*y + log_objective = alpha*np.log(self.beta) - np.log(special.gamma(alpha)) + (alpha - 1)*np.log(y) - self.beta*y + return np.sum(log_objective) def dlogpdf_dlink(self, link_f, y, extra_data=None): """