我可以运行pykalman documentation中给出的简单pykalman卡尔曼滤波器示例:
import pykalman
import numpy as np
kf = pykalman.KalmanFilter(transition_matrices = [[1, 1], [0, 1]], observation_matrices = [[0.1, 0.5], [-0.3, 0.0]])
measurements = np.asarray([[1,0], [0,0], [0,1]]) # 3 observations
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
print filtered_state_means
这正确地返回状态估计值(每个观察值一个):
[[ 0.07285974 0.39708561]
[ 0.30309693 0.2328318 ]
[-0.5533711 -0.0415223 ]]
但是,如果我只提供一次观察,则代码会失败:
import pykalman
import numpy as np
kf = pykalman.KalmanFilter(transition_matrices = [[1, 1], [0, 1]], observation_matrices = [[0.1, 0.5], [-0.3, 0.0]])
measurements = np.asarray([[1,0]]) # 1 observation
(filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
print filtered_state_means
出现以下错误:
ValueError: could not broadcast input array from shape (2,2) into shape (2,1)
如何使用pykalman仅使用一次观察来更新初始状态和初始协方差?
答案 0 :(得分:2)
来自http://pykalman.github.io/#kalmanfilter
的文档TreeView
这在时间t接受filtered_state_mean和filtered_state_covariance,在t + 1接受观察,并在t + 1返回状态均值和状态协方差(用于下一次更新)
答案 1 :(得分:1)
如果我正确理解卡尔曼滤波算法,您只需一次观察即可预测状态。但是,增益和协方差将会偏离,预测将无法接近实际状态。 您需要为卡尔曼滤波器提供一些观察结果作为训练集以达到稳定状态