我可以运行 pykalman documentation 中给出的简单 pykalman Kalman Filter 示例:
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 仅使用单个观察来更新初始状态和初始协方差?
最佳答案
来自文档:http://pykalman.github.io/#kalmanfilter
filter_update(filtered_state_mean, filtered_state_covariance, observation=None, transition_matrix=None, transition_offset=None, transition_covariance=None, observation_matrix=None, observation_offset=None, observation_covariance=None)
这将在时间 t 接收filtered_state_mean 和filtered_state_covariance,以及在t+1 处的观察,并返回t+1 处的状态均值和状态协方差(用于下一次更新)
关于python - 如何在单个观察中运行 pykalman Kalman Filter? (Python),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27056691/