我一直在努力实现卡尔曼滤波器来搜索二维数据集中的异常.非常类似于我在这里找到的优秀帖子.作为下一步,我想预测下一个值将落入的置信区间(例如,对于最低值和上限值的95%置信度).所以除了下面的行之外,我还想成为能够生成两条额外的线,这些线代表95%的置信度,即下一个值将高于最低值或低于最高值.
我假设我想要使用由卡尔曼滤波器生成的每个预测返回的不确定性协方差矩阵(P),但我不确定它是否正确.任何指导或参考如何做到这一点将不胜感激!
上面帖子中的代码随着时间的推移生成一组测量值,并使用卡尔曼滤波器来平滑结果.
import numpy as np
import matplotlib.pyplot as plt
def kalman_xy(x, P, measurement, R,
motion = np.matrix('0. 0. 0. 0.').T,
Q = np.matrix(np.eye(4))):
"""
Parameters:
x: initial state 4-tuple of location and velocity: (x0, x1, x0_dot, x1_dot)
P: initial uncertainty convariance matrix
measurement: observed position
R: measurement noise
motion: external motion added to state vector x
Q: motion noise (same shape as P)
"""
return kalman(x, P, measurement, R, motion, Q,
F = np.matri