首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用pykalman

使用pykalman
EN

Stack Overflow用户
提问于 2019-06-26 03:08:34
回答 1查看 2.6K关注 0票数 0

我想尝试使用pykalman对来自传感器变量的数据应用卡尔曼滤波器。现在,我对观察的数据有了疑问。在该示例中,3个观测值是在3个时刻测量的两个变量,或者是在某个时刻测量的3个变量

代码语言:javascript
复制
from pykalman import KalmanFilter
>>> import numpy as np
>>> kf = 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
>>> kf = kf.em(measurements, n_iter=5)
>>> (filtered_state_means, filtered_state_covariances) = kf.filter(measurements)
>>> (smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurements)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-27 16:04:03

让我们看看:

transition_matrices = [[1, 1], [0, 1]]

手段

因此,您的状态向量由2个元素组成,例如:

observation_matrices = [[0.1, 0.5], [-0.3, 0.0]]

手段

观察矩阵的维数应为[n_dim_obs, n_dim_state]。所以你的测量向量也由2个元素组成。

结论:该代码具有3 observations of two variables measured at 3 different points in time

您可以更改给定的代码,以便它可以在一个时间步中处理每个度量。您可以对每个测量使用kf.filter_update(),而不是一次性对所有测量使用kf.filter()

代码语言:javascript
复制
from pykalman import KalmanFilter
import numpy as np
kf = 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
kf = kf.em(measurements, n_iter=5)

filtered_state_means = kf.initial_state_mean
filtered_state_covariances = kf.initial_state_covariance

for m in measurements:

    filtered_state_means, filtered_state_covariances = (
        kf.filter_update(
            filtered_state_means,
            filtered_state_covariances,
            observation = m)
        )

print(filtered_state_means);

输出:

代码语言:javascript
复制
[-1.69112511  0.30509999]

结果与使用kf.filter()时略有不同,因为此函数不会对第一次测量执行预测,但我认为它应该执行预测。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56760583

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档