免费建站免费二级,数据库策略网站推广的有效方法有,吴江建设局网站,手机免费建站系统我需要Kalman 现在#xff0c;主要是用来处理检测问题情况里的漏检#xff0c;因为模拟了一段2D#xff0c; #xff08;x#xff0c;y#xff09;的数据#xff0c;为了看效果#xff0c;画的线尽量简单一点#xff1a;
import numpy as np
import matplotlib.pyplo…我需要Kalman 现在主要是用来处理检测问题情况里的漏检因为模拟了一段2D xy的数据为了看效果画的线尽量简单一点
import numpy as np
import matplotlib.pyplot as pltdef generate_trace(initial_position, velocity, acceleration, num_points, noise_std):x np.zeros(num_points)y np.zeros(num_points)x[0], y[0] initial_positionfor i in range(1, num_points):x[i] x[i - 1] velocity[0] 0.5 * acceleration[0] * i ** 2y[i] y[i - 1] velocity[1] 0.5 * acceleration[1] * i ** 2x[i] np.random.normal(0, noise_std)y[i] np.random.normal(0, noise_std)return x, ydef add_missing_points(trace, missing_percentage):num_missing int(len(trace) * missing_percentage)missing_indices np.random.choice(len(trace), num_missing, replaceFalse)print(missing_indices)return missing_indicesinitial_position (0, 0)
velocity (5, 3)
acceleration (0.2, 0.1)
num_points 20
noise_std 10
missing_percentage 0.3x, y generate_trace(initial_position, velocity, acceleration, num_points, noise_std)
plt.figure(figsize(12, 6))
plt.plot(x, y, go, labelOriginal Trace)missing_pos add_missing_points(x.copy(), missing_percentage)plt.plot(x[missing_pos], y[missing_pos], rx, labelMissing Points)x[missing_pos] np.nan
y[missing_pos] np.nan
plt.plot(x, y, y--, labelOriginal Trace)
trace np.vstack((x, y)).T
np.savetxt(car_trace.csv, trace, delimiter,)plt.xlabel(X Position)
plt.ylabel(Y Position)
plt.title(Traces)
plt.legend()
plt.savefig(car_trace.png)
plt.show()绿色点理想情况能检测到每个位置 红色×假设的漏检情况 接下来就看KF 、 UKF怎么处理我的漏检了这取决于它们的predict
Prior
Ok在deep diveUKF KF 前有一些参数的definition需要我们的大脑建立一下短暂的存储我经常分不清字母谁是谁…那我们就全程围绕filterpy这个库吧
class KF:def __init__(self, dt):self.dt dtself.dim_x 6 # x, y, vx, vy, ax, ayself.dim_z 2 # Measurements: x, yself.kf KalmanFilter(dim_xself.dim_x, dim_zself.dim_z)self.kf.F np.array([[1, 0, dt, 0, 0.5*dt**2, 0],[0, 1, 0, dt, 0, 0.5*dt**2],[0, 0, 1, 0, dt, 0],[0, 0, 0, 1, 0, dt],[0, 0, 0, 0, 1, 0],[0, 0, 0, 0, 0, 1]])self.kf.H np.array([[1, 0, 0, 0, 0, 0],[0, 1, 0, 0, 0, 0]])self.kf.P * 1.0q 0.1self.kf.Q np.array([[q, 0, 0, 0, 0, 0],[0, q, 0, 0, 0, 0],[0, 0, q, 0, 0, 0],[0, 0, 0, q, 0, 0],[0, 0, 0, 0, q, 0],[0, 0, 0, 0, 0, q]])r 0.5**2self.kf.R np.array([[r, 0],[0, r]])class EUKF:def __init__(self, dt):self.dt dtself.dim_x 6 # x, y, vx, vy, ax, ayself.dim_z 2 # Measurements: x, yself.points MerweScaledSigmaPoints(nself.dim_x, alpha0.001, beta2.0, kappa0)self.ukf UKF(dim_xself.dim_x, dim_zself.dim_z, fxself.f_process, hxself.h_measurement,dtself.dt, pointsself.points)self.ukf.P np.diag([1.0, 1.0, 100.0, 100.0, 1000.0, 1000.0])self.ukf.Q np.diag([0.1, 0.1, 0.1, 0.1, 0.05, 0.05])self.ukf.R np.diag([0.5**2, 0.5**2])两个算法的common 参数如下 dim_x : 这个代表你的feature维度这个看需要设置比如我的states是x, y, vx, vy, ax, ay那么这里就是6 dim_z这个代表你的目标输出维度比如我需要追踪那么位置x,y是我的目标输出这里就是2 dt这个代表standard unit物理上为1我们常说的每秒个单位长度在CV处理上我们是1秒30帧因为处理的是图像信息所以我们的标准单位应该是基于frame的秒1个frame为1/30 秒的处理单位时长,这里一般赋值1/30
以下三个大写字母都是各种covariance Pcovariance estimate matrix表示对状态估计的不确定性
Qprocess noise matrix影响滤波器在预测步骤中对过程模型的信任程度。较大的Q值表示滤波器认为过程模型的不确定性较大从而对预测结果的置信度降低
Rmeasurement noise matrix表示测量中的噪声,较大的R值表示滤波器认为测量数据的不确定性较大从而对测量更新的影响减小
Tips
通常来说P在用UKF/KF 过程用不停的输入来调整自己。而QR是初始后就不变的。
KF使用线性状态转移矩阵 F。状态预测由矩阵乘法完成 UKF使用非线性状态转移函数 f_process。通过对 sigma 点进行无迹变换实现状态预测。