mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-06-05 14:55:15 +02:00
Fixed bug in smoother. Now working.
This commit is contained in:
parent
d6bae3364e
commit
1b0cb8fd77
1 changed files with 9 additions and 9 deletions
|
|
@ -21,7 +21,7 @@ from .. import kern
|
||||||
|
|
||||||
class StateSpace(Model):
|
class StateSpace(Model):
|
||||||
def __init__(self, X, Y, kernel=None):
|
def __init__(self, X, Y, kernel=None):
|
||||||
super(StateSpace, self).__init__()
|
super(StateSpace, self).__init__()
|
||||||
self.num_data, input_dim = X.shape
|
self.num_data, input_dim = X.shape
|
||||||
assert input_dim==1, "State space methods for time only"
|
assert input_dim==1, "State space methods for time only"
|
||||||
num_data_Y, self.output_dim = Y.shape
|
num_data_Y, self.output_dim = Y.shape
|
||||||
|
|
@ -92,6 +92,8 @@ class StateSpace(Model):
|
||||||
# Run the Rauch-Tung-Striebel smoother
|
# Run the Rauch-Tung-Striebel smoother
|
||||||
(M, P) = self.rts_smoother(F,L,Qc,X.T,M,P)
|
(M, P) = self.rts_smoother(F,L,Qc,X.T,M,P)
|
||||||
|
|
||||||
|
#raise NameError('HiThere')
|
||||||
|
|
||||||
# Put the data back in the original order
|
# Put the data back in the original order
|
||||||
M = M[:,return_inverse]
|
M = M[:,return_inverse]
|
||||||
P = P[:,:,return_inverse]
|
P = P[:,:,return_inverse]
|
||||||
|
|
@ -127,7 +129,7 @@ class StateSpace(Model):
|
||||||
|
|
||||||
# Reorder X values
|
# Reorder X values
|
||||||
sort_index = np.argsort(X[:,0])
|
sort_index = np.argsort(X[:,0])
|
||||||
X = X[sort_index]
|
X = X[sort_index]
|
||||||
|
|
||||||
# Get the model matrices from the kernel
|
# Get the model matrices from the kernel
|
||||||
(F,L,Qc,H,Pinf) = self.kern.sde()
|
(F,L,Qc,H,Pinf) = self.kern.sde()
|
||||||
|
|
@ -182,8 +184,6 @@ class StateSpace(Model):
|
||||||
MF[:,k] += K.dot(Y[:,k]-H.dot(MF[:,k]))
|
MF[:,k] += K.dot(Y[:,k]-H.dot(MF[:,k]))
|
||||||
PF[:,:,k] -= K.dot(H).dot(PF[:,:,k])
|
PF[:,:,k] -= K.dot(H).dot(PF[:,:,k])
|
||||||
|
|
||||||
print K
|
|
||||||
|
|
||||||
# Return values
|
# Return values
|
||||||
return (MF, PF)
|
return (MF, PF)
|
||||||
|
|
||||||
|
|
@ -202,10 +202,10 @@ class StateSpace(Model):
|
||||||
(A, Q) = self.lti_disc(F,L,Qc,dt[:,1-k])
|
(A, Q) = self.lti_disc(F,L,Qc,dt[:,1-k])
|
||||||
|
|
||||||
# Smoothing step
|
# Smoothing step
|
||||||
LL = linalg.cho_factor(A.dot(PS[:,:,-k].dot(A.T))+Q)
|
LL = linalg.cho_factor(A.dot(PS[:,:,-k]).dot(A.T)+Q)
|
||||||
G = linalg.cho_solve(LL,A.dot(PS[:,:,-k])).T
|
G = linalg.cho_solve(LL,A.dot(PS[:,:,-k])).T
|
||||||
MS[:,-k] += G.dot(MS[:,1-k]-A.dot(MS[:,-k]))
|
MS[:,-k] += G.dot(MS[:,1-k]-A.dot(MS[:,-k]))
|
||||||
PS[:,:,-k] += G.dot(PS[:,:,1-k]-A.dot(PS[:,:,-k].dot(A.T)-Q)).dot(G.T)
|
PS[:,:,-k] += G.dot(PS[:,:,1-k]-A.dot(PS[:,:,-k]).dot(A.T)-Q).dot(G.T)
|
||||||
|
|
||||||
# Return
|
# Return
|
||||||
return (MS, PS)
|
return (MS, PS)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue