首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >卡尔曼滤波的置信区间估计

卡尔曼滤波的置信区间估计
EN

Stack Overflow用户
提问于 2014-06-25 01:25:50
回答 3查看 5.2K关注 0票数 5

我一直在努力实现一个卡尔曼滤波器,以搜索异常的二维数据集。非常类似于我在这里找到的优秀帖子。作为下一步,我想预测置信区间(例如,95%对下限和上限值的置信度),我预测的下一个值将下降。因此,除了下面这条线之外,我还想生成两条额外的线,它们代表95%的信心,认为下一个值将在地板或天花板以下。

我假设我将使用由Kalman滤波器生成的每个预测返回的不确定性协方差矩阵(P),但我不确定它是否正确。任何指导或参考如何做到这一点,将不胜感激!

python中的kalman 2d滤波器

上述文章中的代码会随着时间的推移生成一组测量值,并使用卡尔曼滤波来平滑结果。

代码语言:javascript
运行
复制
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.matrix('''
                  1. 0. 1. 0.;
                  0. 1. 0. 1.;
                  0. 0. 1. 0.;
                  0. 0. 0. 1.
                  '''),
              H = np.matrix('''
                  1. 0. 0. 0.;
                  0. 1. 0. 0.'''))

def kalman(x, P, measurement, R, motion, Q, F, H):
    '''
    Parameters:
    x: initial state
    P: initial uncertainty convariance matrix
    measurement: observed position (same shape as H*x)
    R: measurement noise (same shape as H)
    motion: external motion added to state vector x
    Q: motion noise (same shape as P)
    F: next state function: x_prime = F*x
    H: measurement function: position = H*x

    Return: the updated and predicted new values for (x, P)

    See also http://en.wikipedia.org/wiki/Kalman_filter

    This version of kalman can be applied to many different situations by
    appropriately defining F and H 
    '''
    # UPDATE x, P based on measurement m    
    # distance between measured and current position-belief
    y = np.matrix(measurement).T - H * x
    S = H * P * H.T + R  # residual convariance
    K = P * H.T * S.I    # Kalman gain
    x = x + K*y
    I = np.matrix(np.eye(F.shape[0])) # identity matrix
    P = (I - K*H)*P

    # PREDICT x, P based on motion
    x = F*x + motion
    P = F*P*F.T + Q

    return x, P

def demo_kalman_xy():
    x = np.matrix('0. 0. 0. 0.').T 
    P = np.matrix(np.eye(4))*1000 # initial uncertainty

    N = 20
    true_x = np.linspace(0.0, 10.0, N)
    true_y = true_x**2
    observed_x = true_x + 0.05*np.random.random(N)*true_x
    observed_y = true_y + 0.05*np.random.random(N)*true_y
    plt.plot(observed_x, observed_y, 'ro')
    result = []
    R = 0.01**2
    for meas in zip(observed_x, observed_y):
        x, P = kalman_xy(x, P, meas, R)
        result.append((x[:2]).tolist())
    kalman_x, kalman_y = zip(*result)
    plt.plot(kalman_x, kalman_y, 'g-')
    plt.show()

demo_kalman_xy()
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-06-28 14:07:35

1西格玛间期的二维推广是以方程(x-mx).T P^{-1}.(x-mx)==1为特征的置信椭圆,其中x为参数2D -向量,mx为2D均值或椭圆中心,P^{-1}为逆协方差矩阵。关于如何绘制一个图,请参阅此回答。与西格玛间隔一样,椭圆面积对应于真实值在此范围内的固定概率。通过使用因子n (缩放间隔长度或椭圆半径)进行缩放,可以获得更高的置信度。请注意,因子n在一维和二维上有不同的概率:

代码语言:javascript
运行
复制
|`n` | 1D-Intverval | 2D Ellipse |
==================================
  1  |  68.27%      |  39.35%    
  2  |  95.5%       |  86.47%
  3  |  99.73%      |  98.89%

在2D中计算这些值有点复杂,不幸的是,我没有公开引用它。

票数 4
EN

Stack Overflow用户

发布于 2014-07-21 06:53:03

如果您想要95%的区间来预测下一个值,那么您需要一个预测区间,而不是置信区间(间隔)。

对于二维(三维)数据,通过计算数据的协方差矩阵的特征值和调整半轴的大小,可以得到椭圆(椭球体)的半轴,从而计算出必要的预测概率。

有关计算95%的预测椭圆或椭球的代码,请参见预测椭圆和预测椭球。这可能会帮助您计算数据的预测椭圆。

票数 1
EN

Stack Overflow用户

发布于 2015-01-17 15:37:38

因为你的统计数据当然是从一个样本中得到的,所以人口统计量大于2西格玛标准差的概率是0.5。因此,如果你没有应用2x标准偏差的上置信度因子,那么我会考虑考虑是否有一个很好的预测值的重要性,如果你没有应用2x标准偏差的上置信度因子,那么下一个测度的概率将低于0.95。这一因素的大小将取决于得出0.5人口概率所使用的样本大小。求协方差矩阵的样本规模越小,求出0.95概率的因子越大,总体0.95统计量就越小。

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

https://stackoverflow.com/questions/24398811

复制
相关文章

相似问题

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