当前位置: 首页>>代码示例>>Python>>正文


Python KalmanFilter.rts_smoother方法代码示例

本文整理汇总了Python中filterpy.kalman.KalmanFilter.rts_smoother方法的典型用法代码示例。如果您正苦于以下问题:Python KalmanFilter.rts_smoother方法的具体用法?Python KalmanFilter.rts_smoother怎么用?Python KalmanFilter.rts_smoother使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在filterpy.kalman.KalmanFilter的用法示例。


在下文中一共展示了KalmanFilter.rts_smoother方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rts

# 需要导入模块: from filterpy.kalman import KalmanFilter [as 别名]
# 或者: from filterpy.kalman.KalmanFilter import rts_smoother [as 别名]
def test_rts():
    fk = KalmanFilter(dim_x=2, dim_z=1)

    fk.x = np.array([-1., 1.])    # initial state (location and velocity)

    fk.F = np.array([[1.,1.],
                     [0.,1.]])      # state transition matrix

    fk.H = np.array([[1.,0.]])      # Measurement function
    fk.P = .01                     # covariance matrix
    fk.R = 5                       # state uncertainty
    fk.Q = 0.001                   # process uncertainty


    zs = [t + random.randn()*4 for t in range(40)]

    mu, cov, _, _ = fk.batch_filter (zs)
    mus = [x[0] for x in mu]

    M, P, _, _ = fk.rts_smoother(mu, cov)

    if DO_PLOT:
        p1, = plt.plot(zs,'cyan', alpha=0.5)
        p2, = plt.plot(M[:,0],c='b')
        p3, = plt.plot(mus,c='r')
        p4, = plt.plot([0, len(zs)], [0, len(zs)], 'g') # perfect result
        plt.legend([p1, p2, p3, p4],
                   ["measurement", "RKS", "KF output", "ideal"], loc=4)

        plt.show()
开发者ID:poeticcapybara,项目名称:filterpy,代码行数:32,代码来源:test_rts.py

示例2: one_run_test_fls

# 需要导入模块: from filterpy.kalman import KalmanFilter [as 别名]
# 或者: from filterpy.kalman.KalmanFilter import rts_smoother [as 别名]
def one_run_test_fls():
    fls = FixedLagSmoother(dim_x=2, dim_z=1)

    fls.x = np.array([0., .5])
    fls.F = np.array([[1.,1.],
                      [0.,1.]])

    fls.H = np.array([[1.,0.]])
    fls.P *= 200
    fls.R *= 5.
    fls.Q *= 0.001

    kf = KalmanFilter(dim_x=2, dim_z=1)

    kf.x = np.array([0., .5])
    kf.F = np.array([[1.,1.],
                     [0.,1.]])
    kf.H = np.array([[1.,0.]])
    kf.P *= 2000
    kf.R *= 1.
    kf.Q *= 0.001

    N = 4 # size of lag

    nom =  np.array([t/2. for t in range (0,40)])
    zs = np.array([t + random.randn()*1.1 for t in nom])

    xs, x = fls.smooth_batch(zs, N)

    M, P, *_ = kf.batch_filter(zs)
    rts_x, *_ = kf.rts_smoother(M, P)

    xfl = xs[:,0].T[0]
    xkf = M[:,0].T[0]

    fl_res = abs(xfl-nom)
    kf_res = abs(xkf-nom)

    if DO_PLOT:
        plt.cla()
        plt.plot(zs,'o', alpha=0.5, marker='o', label='zs')
        plt.plot(x[:,0], label='FLS')
        plt.plot(xfl, label='FLS S')
        plt.plot(xkf, label='KF')
        plt.plot(rts_x[:,0], label='RTS')
        plt.legend(loc=4)
        plt.show()


        print(fl_res)
        print(kf_res)

        print('std fixed lag:', np.mean(fl_res[N:]))
        print('std kalman:', np.mean(kf_res[N:]))

    return np.mean(fl_res) <= np.mean(kf_res)
开发者ID:BrianGasberg,项目名称:filterpy,代码行数:58,代码来源:test_fls.py

示例3: one_run_test_fls

# 需要导入模块: from filterpy.kalman import KalmanFilter [as 别名]
# 或者: from filterpy.kalman.KalmanFilter import rts_smoother [as 别名]
def one_run_test_fls():
    fls = FixedLagSmoother(dim_x=2, dim_z=1)

    fls.x = np.array([0., .5])
    fls.F = np.array([[1.,1.],
                      [0.,1.]])

    fls.H = np.array([[1.,0.]])
    fls.P *= 200
    fls.R *= 5.
    fls.Q *= 0.001

    kf = KalmanFilter(dim_x=2, dim_z=1)

    kf.x = np.array([0., .5])
    kf.F = np.array([[1.,1.],
                     [0.,1.]])
    kf.H = np.array([[1.,0.]])
    kf.P *= 2000
    kf.R *= 1.
    kf.Q *= 0.001

    N = 4 # size of lag

    nom =  np.array([t/2. for t in range (0,40)])
    zs = np.array([t + random.randn()*1.1 for t in nom])

    xs, x = fls.smooth_batch(zs, N)

    M,P,_,_ = kf.batch_filter(zs)
    rts_x,_,_ = kf.rts_smoother(M, P)

    xfl = xs[:,0].T[0]
    xkf = M[:,0].T[0]

    fl_res = abs(xfl-nom)
    kf_res = abs(xkf-nom)
    return np.mean(fl_res) <= np.mean(kf_res)
开发者ID:Censio,项目名称:filterpy,代码行数:40,代码来源:test_fls.py

示例4: range

# 需要导入模块: from filterpy.kalman import KalmanFilter [as 别名]
# 或者: from filterpy.kalman.KalmanFilter import rts_smoother [as 别名]
    fk.F = np.array([[1.,1.],
                     [0.,1.]])      # state transition matrix

    fk.H = np.array([[1.,0.]])      # Measurement function
    fk.P = .01                     # covariance matrix
    fk.R = 5                       # state uncertainty
    fk.Q = 0.001                   # process uncertainty


    zs = [t + random.randn()*4 for t in range (40)]

    mu, cov, _, _ = fk.batch_filter (zs)
    mus = [x[0] for x in mu]

    M,P,C = fk.rts_smoother(mu, cov)



    # plot data
    p1, = plt.plot(zs,'cyan', alpha=0.5)
    p2, = plt.plot (M[:,0],c='b')
    p3, = plt.plot (mus,c='r')
    p4, = plt.plot ([0,len(zs)],[0,len(zs)], 'g') # perfect result
    plt.legend([p1,p2, p3, p4],
               ["measurement", "RKS", "KF output", "ideal"], loc=4)


    plt.show()

开发者ID:BrianGasberg,项目名称:filterpy,代码行数:30,代码来源:test_rts.py


注:本文中的filterpy.kalman.KalmanFilter.rts_smoother方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。