本文整理汇总了Python中statsmodels.tsa.statespace.kalman_filter.KalmanFilter.design方法的典型用法代码示例。如果您正苦于以下问题:Python KalmanFilter.design方法的具体用法?Python KalmanFilter.design怎么用?Python KalmanFilter.design使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.tsa.statespace.kalman_filter.KalmanFilter
的用法示例。
在下文中一共展示了KalmanFilter.design方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cython
# 需要导入模块: from statsmodels.tsa.statespace.kalman_filter import KalmanFilter [as 别名]
# 或者: from statsmodels.tsa.statespace.kalman_filter.KalmanFilter import design [as 别名]
def test_cython():
# Test the cython _kalman_filter creation, re-creation, calling, etc.
# Check that datatypes are correct:
for prefix, dtype in tools.prefix_dtype_map.items():
endog = np.array(1.0, ndmin=2, dtype=dtype)
mod = KalmanFilter(k_endog=1, k_states=1, dtype=dtype)
# Bind data and initialize the ?KalmanFilter object
mod.bind(endog)
mod._initialize_filter()
# Check that the dtype and prefix are correct
assert_equal(mod.prefix, prefix)
assert_equal(mod.dtype, dtype)
# Test that a dKalmanFilter instance was created
assert_equal(prefix in mod._kalman_filters, True)
kf = mod._kalman_filters[prefix]
assert_equal(isinstance(kf, tools.prefix_kalman_filter_map[prefix]), True)
# Test that the default returned _kalman_filter is the above instance
assert_equal(mod._kalman_filter, kf)
# Check that upcasting datatypes / ?KalmanFilter works (e.g. d -> z)
mod = KalmanFilter(k_endog=1, k_states=1)
# Default dtype is float
assert_equal(mod.prefix, "d")
assert_equal(mod.dtype, np.float64)
# Prior to initialization, no ?KalmanFilter exists
assert_equal(mod._kalman_filter, None)
# Bind data and initialize the ?KalmanFilter object
endog = np.ascontiguousarray(np.array([1.0, 2.0], dtype=np.float64))
mod.bind(endog)
mod._initialize_filter()
kf = mod._kalman_filters["d"]
# Rebind data, still float, check that we haven't changed
mod.bind(endog)
mod._initialize_filter()
assert_equal(mod._kalman_filter, kf)
# Force creating new ?Statespace and ?KalmanFilter, by changing the
# time-varying character of an array
mod.design = np.zeros((1, 1, 2))
mod._initialize_filter()
assert_equal(mod._kalman_filter == kf, False)
kf = mod._kalman_filters["d"]
# Rebind data, now complex, check that the ?KalmanFilter instance has
# changed
endog = np.ascontiguousarray(np.array([1.0, 2.0], dtype=np.complex128))
mod.bind(endog)
assert_equal(mod._kalman_filter == kf, False)