首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >卡尔曼滤波一维Python

卡尔曼滤波一维Python
EN

Stack Overflow用户
提问于 2018-05-07 15:20:49
回答 1查看 1.6K关注 0票数 0

我尝试使用卡尔曼滤波对我的一维数据。因此,假设我有以下数据集:

代码语言:javascript
复制
 Variable
 250.1
 248.5
 262.3
 265.3
 270.2

我确实知道我的数据中存在噪声,因此,我想使用卡尔曼滤波来清除这些数据。哪种方法能给我带来最有效的结果?

我运行以下代码:

代码语言: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([(250.1),(248.5),(262.3),(265.3), (270.2)])
 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)

正如您所看到的,我尝试使用pykalman,但是我无法安装这个模块。我尝试使用easy_install pykalman方向,错误是无效语法。另一个问题是,我有一个庞大的数据集,所以我的变量列中有超过10万行。所以,我不能一个一个地写出所有的观察结果。

EN

回答 1

Stack Overflow用户

发布于 2018-05-08 15:46:46

为了安装pykalman,我使用了:

代码语言:javascript
复制
pip install pykalman --user

--用户标志安装到我的主目录,避免使用sudo安装.有人告诉我枕叶不见了,所以我也安装了它。在项目github页面上有一个依赖库列表,因此可能会要求您安装其中任何一个库。

您正在使用单个值为您的每一个读数。大多数例子有更多的,例如每次阅读的位置和速度。为了得到你所提供的过渡矩阵和观察矩阵的图,我在你的每个度量中增加了第二个假读数'1‘。下面的木星笔记本脚本将产生一个图表,但输出很差,因为矩阵值需要为您的数据集进行调整。

代码语言:javascript
复制
%matplotlib inline
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([(250.1),(248.5),(262.3),(265.3), (270.2)])
measurements = np.array([[250.1,1],[248.5,1],[262.3,1],[265.3,1], [270.2,1]])
kf = kf.em(measurements, n_iter=5)
filtered_state_estimates = kf.filter(measurements)[0]
(smoothed_state_estimates, smoothed_state_covariances)=kf.smooth(measurements)
# draw estimates
pl.figure()
lines_true = pl.plot(measurements, color='b')
lines_filt = pl.plot(filtered_state_estimates, color='r')
lines_smooth = pl.plot(smoothed_state_estimates, color='g')
pl.legend((lines_true[0], lines_filt[0], lines_smooth[0]),
          ('true', 'filt', 'smooth'),
          loc='lower right'
)
pl.show()

对于您建议的数据集,一种快速和更简单的产生过滤输出的方法是使用一个减α滤波器。有关此类型筛选器的更多详细信息,请查看此链接:http://stats.stackexchange.com/questions/44650/a-simpler-way-to-calculate-exponentially-weighted-moving-average

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

https://stackoverflow.com/questions/50217553

复制
相关文章

相似问题

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