From d6bae3364e48a3a7da29de51b796bc7352e5e6e5 Mon Sep 17 00:00:00 2001 From: Arno Solin Date: Sun, 10 Nov 2013 20:38:41 +0000 Subject: [PATCH] Fixed bug in log_likelihood evaluation --- GPy/models/state_space.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GPy/models/state_space.py b/GPy/models/state_space.py index d19cdab7..6d9ddbff 100644 --- a/GPy/models/state_space.py +++ b/GPy/models/state_space.py @@ -182,6 +182,8 @@ class StateSpace(Model): MF[:,k] += K.dot(Y[:,k]-H.dot(MF[:,k])) PF[:,:,k] -= K.dot(H).dot(PF[:,:,k]) + print K + # Return values return (MF, PF) @@ -220,7 +222,7 @@ class StateSpace(Model): dt = np.empty(X.shape) dt[:,0] = X[:,1]-X[:,0] dt[:,1:] = np.diff(X) - + # Kalman filter for likelihood evaluation for k in range(0,Y.shape[1]): @@ -235,14 +237,15 @@ class StateSpace(Model): if not np.isnan(Y[:,k]): v = Y[:,k]-H.dot(m) LL, isupper = linalg.cho_factor(H.dot(P).dot(H.T) + R) - lik -= 0.5*np.sum(np.log(np.diag(LL))) + lik -= np.sum(np.log(np.diag(LL))) + lik -= 0.5*v.shape[0]*np.log(2*np.pi) lik -= 0.5*linalg.cho_solve((LL, isupper),v).dot(v) K = linalg.cho_solve((LL, isupper), H.dot(P.T)).T m += K.dot(v) P -= K.dot(H).dot(P) # Return likelihood - return lik + return lik[0,0] def simulate(self,F,L,Qc,Pinf,X): # Simulate a trajectory using the state space model