卡尔曼滤波器 2d 与 pykalman

kalman filter 2d with pykalman

我正在尝试在 GPS 数据集上使用卡尔曼滤波器来降低噪声。为此,我检查了是否已经有在线实现并找到了 pykalman。我正在尝试使用它,但出于某种原因,我不知道我应该如何正确分配矩阵。当我尝试 运行 它时,它告诉我尺寸错误。 所以首先,我正在尝试 do/get: 我希望卡尔曼滤波器用旧位置 + 速度 * t 来估计下一个时间步长的位置。下一步的速度只是旧速度。每个时间步长正好为 1 秒。 我在 x 和 y 方向上进行了测量,并且 x_t、y_t、vx_t、vy_t 转换矩阵应该看起来像这样(我认为):

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)
    

尝试 运行 最后一部分会出现以下错误:

shapes (2,1) and (2,) not aligned: 1 (dim 1) != 2 (dim 0)

据我所知,所使用的矩阵没有正确的尺寸可以相互使用。 总的来说,我对矩阵的理解非常有限。 我希望有人能帮助我。

根据您的模型,您的状态向量如下:[x, y, v_x, v_y] 并且您仅观察(测量)[x, y]。因此,您还需要正确定义测量矩阵 H,它将真实状态 space 映射到观察到的 space: z=Hx + noise。所以在你的情况下,这很简单:

observation_matrix = np.array(
    [[1, 0, 0, 0],
     [0, 1, 0, 0]]
)

这将正常工作:

kf = pykalman.KalmanFilter(
    transition_matrices=transition_matrix,
    observation_matrices=observation_matrix
)