def test_LDL_first_missing(ft_mvar, theta_mvar_diffuse, Yt_mvar, Xt_mvar): """ Test when first measurement is missing """ kf = Filter(ft_mvar, Yt_mvar, Xt_mvar, for_smoother=True) kf.init_attr(theta_mvar_diffuse) Y_t, H_t, D_t, R_t, L_t, L_inv = kf._LDL(1) assert kf.n_t[1] == 2 R_t_move = np.array([[4, 3, 2], [3, 6, 1], [2, 1, 3]]) L_t_expected, R_t_expected, _ = linalg.ldl(R_t_move) L_inv_expected, _ = linalg.lapack.dtrtri(L_t_expected, lower=True) np.testing.assert_array_equal(L_t, L_t_expected) np.testing.assert_array_equal(R_t, R_t_expected) Y_t_expected = linalg.pinv(L_t_expected).dot( np.array([2.2, 3, 0]).reshape(-1, 1)) np.testing.assert_array_almost_equal(Y_t, Y_t_expected) H_t_expected = L_inv_expected.dot(np.array([2, 2.4, 1]).reshape(-1, 1)) np.testing.assert_array_almost_equal(H_t, H_t_expected) expected_partitioned_index = np.array([1, 2, 0]) np.testing.assert_array_equal(kf.partitioned_index[1], expected_partitioned_index)
def test_LDL(ft_mvar, theta_mvar_diffuse, Yt_mvar, Xt_mvar): """ Test normal run """ kf = Filter(ft_mvar, Yt_mvar, Xt_mvar, for_smoother=True) kf.init_attr(theta_mvar_diffuse) Y_t, H_t, D_t, R_t, L_t, L_inv = kf._LDL(0) assert kf.n_t[0] == 3 R_t_move = np.array([[3, 2, 1], [2, 4, 3], [1, 3, 6]]) L_t_expected, R_t_expected, _ = linalg.ldl(R_t_move) L_inv_expected, _ = linalg.lapack.dtrtri(L_t_expected, lower=True) np.testing.assert_array_equal(L_t, L_t_expected) np.testing.assert_array_equal(R_t, R_t_expected) Y_t_expected = linalg.pinv(L_t_expected).dot( np.array([1, 2, 2.1]).reshape(-1, 1)) np.testing.assert_array_almost_equal(Y_t, Y_t_expected) H_t_expected = L_inv_expected.dot(np.array([1, 2, 2.4]).reshape(-1, 1)) np.testing.assert_array_almost_equal(H_t, H_t_expected) expected_partitioned_index = np.array([0, 1, 2]) np.testing.assert_array_equal(kf.partitioned_index[0], expected_partitioned_index)