예제 #1
0
 def test_smooth_mv(self):
     n_meas = np.random.randint(5) + 3
     n_state = n_meas + np.random.randint(5)
     mu_state_next = rand_vec(n_state)
     var_state_next = rand_mat(n_state)
     mu_state_filt = rand_vec(n_state)
     var_state_filt = rand_mat(n_state)
     mu_state_pred = rand_vec(n_state)
     var_state_pred = rand_mat(n_state)
     wgt_state = rand_mat(n_state, pd=False)
     # pure python
     KFS = KTV_py(n_meas, n_state)
     mu_state_smooth, var_state_smooth = KFS.smooth_mv(
         mu_state_next, var_state_next, mu_state_filt, var_state_filt,
         mu_state_pred, var_state_pred, wgt_state)
     # cython
     ktv = KalmanTV(n_meas, n_state)
     mu_state_smooth2 = np.empty(n_state)
     var_state_smooth2 = np.empty((n_state, n_state), order='F')
     ktv.smooth_mv(mu_state_smooth2, var_state_smooth2, mu_state_next,
                   var_state_next, mu_state_filt, var_state_filt,
                   mu_state_pred, var_state_pred, wgt_state)
     self.assertAlmostEqual(rel_err(mu_state_smooth, mu_state_smooth2), 0.0)
     self.assertAlmostEqual(rel_err(var_state_smooth, var_state_smooth2),
                            0.0)
예제 #2
0
 def test_pykalman_smooth_mv(self):
     # Turn off beign warning from older version of numpy
     warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
     n_meas = np.random.randint(5) + 3
     n_state = n_meas + np.random.randint(5)
     mu_state_next = rand_vec(n_state)
     var_state_next = rand_mat(n_state)
     mu_state_filt = rand_vec(n_state)
     var_state_filt = rand_mat(n_state)
     mu_state_pred = rand_vec(n_state)
     var_state_pred = rand_mat(n_state)
     wgt_state = rand_mat(n_state, pd=False)
     mu_state_smooth, var_state_smooth, _ = (pks._smooth_update(
         wgt_state, mu_state_filt, var_state_filt, mu_state_pred,
         var_state_pred, mu_state_next, var_state_next))
     ktv = KalmanTV(n_meas, n_state)
     mu_state_smooth2 = np.empty(n_state)
     var_state_smooth2 = np.empty((n_state, n_state), order='F')
     ktv.smooth_mv(mu_state_smooth2, var_state_smooth2, mu_state_next,
                   var_state_next, mu_state_filt, var_state_filt,
                   mu_state_pred, var_state_pred, wgt_state)
     self.assertAlmostEqual(rel_err(mu_state_smooth, mu_state_smooth2), 0.0)
     self.assertAlmostEqual(rel_err(var_state_smooth, var_state_smooth2),
                            0.0)