本文整理汇总了Python中statsmodels.tsa.statespace.kalman_filter.KalmanFilter.loglikeobs方法的典型用法代码示例。如果您正苦于以下问题:Python KalmanFilter.loglikeobs方法的具体用法?Python KalmanFilter.loglikeobs怎么用?Python KalmanFilter.loglikeobs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.tsa.statespace.kalman_filter.KalmanFilter
的用法示例。
在下文中一共展示了KalmanFilter.loglikeobs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_missing
# 需要导入模块: from statsmodels.tsa.statespace.kalman_filter import KalmanFilter [as 别名]
# 或者: from statsmodels.tsa.statespace.kalman_filter.KalmanFilter import loglikeobs [as 别名]
def test_missing():
# Datasets
endog = np.arange(10).reshape(10,1)
endog_pre_na = np.ascontiguousarray(np.c_[
endog.copy() * np.nan, endog.copy() * np.nan, endog, endog])
endog_post_na = np.ascontiguousarray(np.c_[
endog, endog, endog.copy() * np.nan, endog.copy() * np.nan])
endog_inject_na = np.ascontiguousarray(np.c_[
endog, endog.copy() * np.nan, endog, endog.copy() * np.nan])
# Base model
mod = KalmanFilter(np.ascontiguousarray(np.c_[endog, endog]), k_states=1,
initialization='approximate_diffuse')
mod['design', :, :] = 1
mod['obs_cov', :, :] = np.eye(mod.k_endog)*0.5
mod['transition', :, :] = 0.5
mod['selection', :, :] = 1
mod['state_cov', :, :] = 0.5
llf = mod.loglikeobs()
# Model with prepended nans
mod = KalmanFilter(endog_pre_na, k_states=1,
initialization='approximate_diffuse')
mod['design', :, :] = 1
mod['obs_cov', :, :] = np.eye(mod.k_endog)*0.5
mod['transition', :, :] = 0.5
mod['selection', :, :] = 1
mod['state_cov', :, :] = 0.5
llf_pre_na = mod.loglikeobs()
assert_allclose(llf_pre_na, llf)
# Model with appended nans
mod = KalmanFilter(endog_post_na, k_states=1,
initialization='approximate_diffuse')
mod['design', :, :] = 1
mod['obs_cov', :, :] = np.eye(mod.k_endog)*0.5
mod['transition', :, :] = 0.5
mod['selection', :, :] = 1
mod['state_cov', :, :] = 0.5
llf_post_na = mod.loglikeobs()
assert_allclose(llf_post_na, llf)
# Model with injected nans
mod = KalmanFilter(endog_inject_na, k_states=1,
initialization='approximate_diffuse')
mod['design', :, :] = 1
mod['obs_cov', :, :] = np.eye(mod.k_endog)*0.5
mod['transition', :, :] = 0.5
mod['selection', :, :] = 1
mod['state_cov', :, :] = 0.5
llf_inject_na = mod.loglikeobs()
assert_allclose(llf_inject_na, llf)