EM 算法 returns 使用 pykalman 的不同答案
EM algo returns different answers using pykalman
我在 Python 3.6.3
中使用 pykalman 0.9.5
时遇到问题
参考下面的代码,为什么kf2
和kf3
的结果不一样,而kf1
和kf3
的结果是一样的?
kf2
和kf3
过程的区别在于我只是将迭代分成运行 kf2
函数的2次。
感谢大家的关注。
>>>pri_mean[:10]
array([ 2827.2222, 2829.6 , 2831. , 2832.1 , 2833.1 , 2835.3 , 2833.9 ,
2833.8 , 2833.6 , 2833. ])
>>>kf1 = KalmanFilter()
>>>kf1 = kf1.em(pri_mean, 10, em_vars='all')
>>>print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
[[ 0.99741876]] [ 10.04426882] [[ 2896.92752373]]
>>>kf2 = kf1.em(pri_mean, 10, em_vars='all')
>>>print(kf2.transition_matrices, kf2.transition_offsets, kf2.transition_covariance)
[[ 0.99364606]] [ 20.02260806] [[ 2600.94151188]]
>>>kf3 = KalmanFilter()
>>>kf3 = kf3.em(pri_mean, 20, em_vars='all')
>>>print(kf3.transition_matrices, kf3.transition_offsets, kf3.transition_covariance)
[[ 0.99741876]] [ 10.04426882] [[ 2896.92752373]]
我编辑了答案,因为我误解了这个问题。我认为问题是您缺少关键字 n_iter
查看此代码:
kf1 = KalmanFilter()
kf1 = kf1.em(pri_mean, n_iter=10, em_vars='all')
print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
kf1 = kf1.em(pri_mean, n_iter=10, em_vars='all')
print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
kf1 = KalmanFilter()
kf1 = kf1.em(pri_mean, n_iter=20, em_vars='all')
print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
我通过 KalmanFilter()
创建一个过滤器,循环 10 次迭代并打印,然后再循环 10 次并打印。
这相当于直接调用 .em()
20 次迭代。
会产生以下输出
[[ 0.95500561]] [ 113.29118228] [[ 6431.66262464]]
[[ 0.93636512]] [ 119.32378005] [[ 249.67547612]]
[[ 0.93636512]] [ 119.32378005] [[ 249.67547612]]
我在 Python 3.6.3
pykalman 0.9.5
时遇到问题
参考下面的代码,为什么kf2
和kf3
的结果不一样,而kf1
和kf3
的结果是一样的?
kf2
和kf3
过程的区别在于我只是将迭代分成运行 kf2
函数的2次。
感谢大家的关注。
>>>pri_mean[:10]
array([ 2827.2222, 2829.6 , 2831. , 2832.1 , 2833.1 , 2835.3 , 2833.9 ,
2833.8 , 2833.6 , 2833. ])
>>>kf1 = KalmanFilter()
>>>kf1 = kf1.em(pri_mean, 10, em_vars='all')
>>>print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
[[ 0.99741876]] [ 10.04426882] [[ 2896.92752373]]
>>>kf2 = kf1.em(pri_mean, 10, em_vars='all')
>>>print(kf2.transition_matrices, kf2.transition_offsets, kf2.transition_covariance)
[[ 0.99364606]] [ 20.02260806] [[ 2600.94151188]]
>>>kf3 = KalmanFilter()
>>>kf3 = kf3.em(pri_mean, 20, em_vars='all')
>>>print(kf3.transition_matrices, kf3.transition_offsets, kf3.transition_covariance)
[[ 0.99741876]] [ 10.04426882] [[ 2896.92752373]]
我编辑了答案,因为我误解了这个问题。我认为问题是您缺少关键字 n_iter
查看此代码:
kf1 = KalmanFilter()
kf1 = kf1.em(pri_mean, n_iter=10, em_vars='all')
print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
kf1 = kf1.em(pri_mean, n_iter=10, em_vars='all')
print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
kf1 = KalmanFilter()
kf1 = kf1.em(pri_mean, n_iter=20, em_vars='all')
print(kf1.transition_matrices, kf1.transition_offsets, kf1.transition_covariance)
我通过 KalmanFilter()
创建一个过滤器,循环 10 次迭代并打印,然后再循环 10 次并打印。
这相当于直接调用 .em()
20 次迭代。
会产生以下输出
[[ 0.95500561]] [ 113.29118228] [[ 6431.66262464]]
[[ 0.93636512]] [ 119.32378005] [[ 249.67547612]]
[[ 0.93636512]] [ 119.32378005] [[ 249.67547612]]