当前位置: 首页>>代码示例>>Python>>正文


Python KalmanFilter.transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])]方法代码示例

本文整理汇总了Python中statsmodels.tsa.statespace.kalman_filter.KalmanFilter.transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])]方法的典型用法代码示例。如果您正苦于以下问题:Python KalmanFilter.transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])]方法的具体用法?Python KalmanFilter.transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])]怎么用?Python KalmanFilter.transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在statsmodels.tsa.statespace.kalman_filter.KalmanFilter的用法示例。


在下文中一共展示了KalmanFilter.transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_kalman_filter_pickle

# 需要导入模块: from statsmodels.tsa.statespace.kalman_filter import KalmanFilter [as 别名]
# 或者: from statsmodels.tsa.statespace.kalman_filter.KalmanFilter import transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])] [as 别名]
def test_kalman_filter_pickle(data):
    # Construct the statespace representation
    true = results_kalman_filter.uc_uni
    k_states = 4
    model = KalmanFilter(k_endog=1, k_states=k_states)
    model.bind(data['lgdp'].values)

    model.design[:, :, 0] = [1, 1, 0, 0]
    model.transition[([0, 0, 1, 1, 2, 3],
                      [0, 3, 1, 2, 1, 3],
                      [0, 0, 0, 0, 0, 0])] = [1, 1, 0, 0, 1, 1]
    model.selection = np.eye(model.k_states)

    # Update matrices with given parameters
    (sigma_v, sigma_e, sigma_w, phi_1, phi_2) = np.array(
        true['parameters']
    )
    model.transition[([1, 1], [1, 2], [0, 0])] = [phi_1, phi_2]
    model.state_cov[
        np.diag_indices(k_states) + (np.zeros(k_states, dtype=int),)] = [
        sigma_v ** 2, sigma_e ** 2, 0, sigma_w ** 2
    ]

    # Initialization
    initial_state = np.zeros((k_states,))
    initial_state_cov = np.eye(k_states) * 100

    # Initialization: modification
    initial_state_cov = np.dot(
        np.dot(model.transition[:, :, 0], initial_state_cov),
        model.transition[:, :, 0].T
    )
    model.initialize_known(initial_state, initial_state_cov)
    pkl_mod = cPickle.loads(cPickle.dumps(model))

    results = model.filter()
    pkl_results = pkl_mod.filter()

    assert_allclose(results.llf_obs[true['start']:].sum(),
                    pkl_results.llf_obs[true['start']:].sum())
    assert_allclose(results.filtered_state[0][true['start']:],
                    pkl_results.filtered_state[0][true['start']:])
    assert_allclose(results.filtered_state[1][true['start']:],
                    pkl_results.filtered_state[1][true['start']:])
    assert_allclose(results.filtered_state[3][true['start']:],
                    pkl_results.filtered_state[3][true['start']:])
开发者ID:kshedden,项目名称:statsmodels,代码行数:48,代码来源:test_pickle.py


注:本文中的statsmodels.tsa.statespace.kalman_filter.KalmanFilter.transition[([0,0,1,1,2,3],[0,3,1,2,1,3],[0,0,0,0,0,0])]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。