【发布时间】:2021-05-06 11:51:38
【问题描述】:
我正在尝试对 GPS 数据集使用卡尔曼滤波器来降低噪音。为此,我检查了是否已经有在线实现并找到了 pykalman。我正在尝试使用它,但由于某种原因,我没有得到我应该如何正确分配矩阵。当我尝试运行它时,它告诉我我有尺寸错误。 所以首先,我想要做什么/得到什么: 我希望卡尔曼滤波器用旧位置 + 速度 * t 估计下一个时间步的位置。下一步的速度就是旧的速度。每个时间步长是 1 秒。 我在 x 和 y 方向上进行了测量,对于 x_t,y_t,vx_t,vy_t,Transition 矩阵应该看起来像这样(我认为):
transition_matrix = np.array([[1, 0,1,0],
[0, 1,0,1],
[0,0,1,0],
[0,0,0,1]])
我的测量结果如下:
[[ 7.616984 47.53661 ]
[ 7.616999 47.536629]
[ 7.616997 47.536635]
...
[ 7.617117 47.536999]
[ 7.617117 47.536999]
[ 7.617117 47.536999]]
到目前为止我尝试了什么: 我试图从各种在线资源中拼凑出它是如何工作的,并想出了这个:
import numpy as np
import pykalman
import geopandas
measurments= np.asarray(gdf[["Longitude_deg", "Latitude_deg"]])
#gdf is a geopandas dataframe, but no i'm not currently using the geometry of it.
transition_matrix = np.array([[1, 0,1,0],
[0, 1,0,1],
[0,0,1,0],
[0,0,0,1]])
#the pykalman documentation says the model parameter can but don't have to be specified and it will simply use defaults for unspecified parameters:
kf = pykalman.KalmanFilter(
transition_matrices =transition_matrix
)
(smoothed_state_means, smoothed_state_covariances) = kf.smooth(measurments)
尝试运行最后一部分会给我以下错误:
形状 (2,1) 和 (2,) 未对齐:1 (dim 1) != 2 (dim 0)
据我所知,所使用的矩阵没有正确的尺寸可以相互使用。 一般来说,我对矩阵的理解非常有限。 我希望有人可以帮助我。
【问题讨论】: