def test_learn_KPM(self): kpm=scipy.io.loadmat(pkg_resources.resource_filename(__name__,'kpm_learn_results')) y = kpm['y'].T # data vector is transposed from KPM F1 = kpm['F1'] H1 = kpm['H1'] Q1 = kpm['Q1'] R1 = kpm['R1'] initx1 = kpm['initx'] initV1 = kpm['initV'] max_iter = kpm['max_iter'] F2, H2, Q2, R2, initx2, initV2, LL = adskalman.learn_kalman(y, F1, H1, Q1, R1, initx1, initV1, max_iter) assert numpy.allclose(F2,kpm['F2']) assert numpy.allclose(H2,kpm['H2']) assert numpy.allclose(Q2,kpm['Q2']) assert numpy.allclose(R2,kpm['R2']) assert numpy.allclose(initx2,kpm['initx2']) assert numpy.allclose(initV2,kpm['initV2']) #print numpy.ravel(LL),kpm['LL'] assert numpy.allclose(LL,kpm['LL'])
def _test_kalman_murphy_EM(self): # temporarily disabled def returnC(orig): return self.C def returnQ(orig): return self.Q def returnR(orig): return self.R constr_fun_dict = { 'C':returnC, #'Q':returnQ, #'R':returnR, } if 1: print '-'*80,'Murphy' Alearn, Clearn, Qlearn, Rlearn, initx2, initV2, LL = adskalman.learn_kalman( self.Y, self.Abad, self.C, self.Q, self.R, self.x0, self.P0, max_iter=500, verbose=2, constr_fun_dict=constr_fun_dict, thresh=1e-5, ) xsmooth, Vsmooth, VVsmooth, loglik = adskalman.kalman_smoother( self.Y,self.A,self.C,self.Q,self.R,self.x0,self.P0, full_output=True) if 1: print 'best LL',loglik print print '*'*80,'Murphy' print 'A' print self.A print 'Alearn' print Alearn print 'Clearn' print Clearn print 'Qlearn' print Qlearn print 'Rlearn' print Rlearn print '*'*80,'Murphy'
def test_kalman__murphy1(self): def returnC(orig): return self.C def returnQ(orig): return self.Q def returnR(orig): return self.R constr_fun_dict = { 'C':returnC, 'Q':returnQ, 'R':returnR, } print '-'*80,'Murphy' Alearn, Clearn, Qlearn, Rlearn, initx2, initV2, LL = adskalman.learn_kalman( self.Y, self.Abad, self.C, self.Q, self.R, self.x0, self.P0, max_iter=150, verbose=2, constr_fun_dict=constr_fun_dict, ) xsmooth, Vsmooth, VVsmooth, loglik = adskalman.kalman_smoother( self.Y,self.A,self.C,self.Q,self.R,self.x0,self.P0, full_output=True) print 'best LL',loglik print print '*'*80,'Murphy' print 'A' print self.A print 'Alearn' print Alearn print 'Clearn' print Clearn print 'Qlearn' print Qlearn print 'Rlearn' print Rlearn print '*'*80,'Murphy'