python - 如何在单次观察中运行 pykalman 卡尔曼滤波器? (Python)

标签 python kalman-filter pykalman

我可以运行 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 仅通过一次观察来更新初始状态和初始协方差?

最佳答案

来自文档: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 卡尔曼滤波器? (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27056691/

相关文章:

python - sqlite3 从打印数据中删除括号

python - 我想按住按钮持续移动,但即使我不抬起按键,KEYUP 的读数也是 true

python - 卡尔曼滤波器总是预测原点

C++/OpenCV - 用于视频稳定的卡尔曼滤波器

python - OpenCV卡尔曼滤波器python

python - Python中的TypeError在反射(reflect)的数字仿真器(例如__radd__)中使用PyAny作为Rust pyo3 pyclass结构

python - Python中车辆位置估计的卡尔曼滤波器参数定义

python - 卡尔曼滤波随着时间的推移改变已知方差?

python - 我如何使用 Python 获取包含特定文件(即'__main__.py)的子目录列表