Skip to content

AutuanLiu/Kalman-Filter

Repository files navigation

Kalman filter estimation

Email: autuanliu@163.com

!!!本库的所有文件,作者保留一切版权,在未经作者许可,请不要擅自使用或者发表!!!

Build Status Sourcegraph

Notes: 所有的原始数据文件可以使用data目录下的matlab代码生成

  • 本库包含四种自回归模型系数估计的算法

    • FROLS
    • bi-KF
    • FROKF(暂未发表,但可用, 引用请联系作者)
    • bi-KF-SGD(暂未发表,但可用, 引用请联系作者)
  • 主题

    • 卡尔曼滤波器
    • 自回归模型
    • 系数估计
    • 格兰杰因果
    • FROLS(Forward-Regression Orthogonal Least Square)
    • FROKF(暂未发表,但可用, 引用请联系作者)
    • SGD
  • 编程语言

    • Matlab
    • Python
  • FROKF 系数估计

    FROKF

  • FROKF 效果示意

    • 估计系数的均值比较

    估计系数的均值比较

    • 估计系数的方差比较

      估计系数的方差比较

    • 估计系数的误差比较

      估计系数的误差比较

  • 安装

pip install kalman-estimation

1 Theory

1.1 线性一维系统

1.1.1 系统表示

$$x_k=ax_{k-1}+bu_k+w_k$$

$$z_k=cx_k+v_k$$

$$p(w)\sim\mathcal{N}(0, Q)$$

$$p(v)\sim\mathcal{N}(0, R)$$

1.1.2 计算过程

  • step 1: Predict

$$\hat{{x}k}=a\hat{{x}{k-1}}+bu_k$$

$$p_k=ap_{k-1}a + Q$$

  • step 2: Update

$$g_k=p_k c/(cp_k c+r)$$

$$\hat{x}_k\leftarrow \hat{x}_k+g_k(z_k-c\hat{x}_k)$$

$$p_k\leftarrow (1-g_k c)p_k$$ 以上的过程(step1 && step2)是在观测序列上递归计算的。以上为离散版本(一维)的kalman滤波。

1.2 线性多维系统

1.2.1 系统表示

$$x_k=Ax_{k-1}+Bu_k+w_k$$

$$z_k=Cx_k+v_k$$

1.2.2 计算过程

  • step 1: Predict

$$\hat{{x}k}=A\hat{{x}{k-1}}+Bu_k$$

$$P_k=AP_{k-1}A^T+Q$$

  • step 2: Update

$$G_k=P_k C^T(C{P_k} C^T+R)^{-1}$$

$$\hat{x}_k\leftarrow \hat{x}_k+G_k(z_k-C\hat{x}_k)$$

$$P_k\leftarrow (I-G_k C)P_k$$

这里的 $x$ 可以是向量 $\vec{x}$,用来表示多个信号。

1.3 非线性多维系统

1.3.1 系统表示

$$x_k=f(x_{k-1},u_k)+w_k$$

$$z_k=h(x_k)+v_k$$

1.3.2 计算过程

  • step 1: Predict

$$\hat{{x}k}=f(\hat{{x}{k-1}},u_k)$$

$$P_k=F_{k-1}P_{k-1}F_{k-1}^T+Q_{k-1}$$

  • step 2: Update

$$G_k=P_k H_k^T(H_k{P_k} H_k^T+R)^{-1}$$

$$\hat{x}_k\leftarrow \hat{x}_k+G_k(z_k-h(\hat{x}_k))$$

$$P_k\leftarrow (I-G_k H_k)P_k$$

这里 $F_{k-1}$, $H_k$ 分别表示非线性函数 $f$, $h$ 的雅克比矩阵。

Reference

  1. An implementation of kalman-filters for multivariate time-series in PyTorch
  2. Analysis of financial time series using Kalman filter.
  3. Self-Driving Car Nanodegree Program Starter Code for the Extended Kalman Filter Project
  4. Python Kalman filtering and optimal estimation library. Implements Kalman filter, particle filter, Extended Kalman filter, Unscented Kalman filter, g-h (alpha-beta), least squares, H Infinity, smoothers, and more. Has companion book 'Kalman and Bayesian Filters in Python'.
  5. FilterPy — FilterPy 1.4.4 documentation
  6. Kalman Filter book using Jupyter Notebook. Focuses on building intuition and experience, not formal proofs. Includes Kalman filters,extended Kalman filters, unscented Kalman filters, particle filters, and more. All exercises include solutions.
  7. Header-only C++11 Kalman Filtering Library (EKF, UKF) based on Eigen3
  8. The Extended Kalman Filter: An Interactive Tutorial
  9. Lightweight C/C++ Extended Kalman Filter with Python for prototyping
  10. CoursePack.book
  11. Kalman Filter: An Algorithm for making sense from the insights of various sensors fused together.
  12. kalman_intro_chinese.pdf
  13. autoregressive model - Different state-space representations for Auto-Regression and Kalman filter - Signal Processing Stack Exchange
  14. 14_state_space.pdf
  15. kalman.pdf
  16. Linderman, S. W., Johnson, M. J., Miller, A. C., Adams, R. P., Blei, D. M., & Paninski, L. (2017). Bayesian Learning and Inference in Recurrent Switching Linear Dynamical Systems. Proceedings of the 20th International Conference on Artificial Intelligence and Statistics, 54, 914–922.
  17. Sieb, M., Schultheis, M., & Szelag, S. (2018). Probabilistic Trajectory Segmentation by Means of Hierarchical Dirichlet Process Switching Linear Dynamical Systems. Retrieved from http://arxiv.org/abs/1806.06063
  18. E. B. Fox, “Bayesian nonparametric learning of com- plex dynamical phenomena,” 2009
  19. A. Fasoula, Y. Attal, and D. Schwartz, “Comparative performance evaluation of data-driven causality measures applied to brain networks,” J. Neurosci. Methods, vol. 215, no. 2, pp. 170–189, 2013.

Info

$ cloc .
      95 text files.
      91 unique files.                              
      37 files ignored.

github.com/AlDanial/cloc v 1.74  T=54.92 s (1.1 files/s, 98.8 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
MATLAB                          27            200            668           1336
Python                          22            502            813           1157
Markdown                         6            152              1            404
JSON                             3              0              0            131
YAML                             2             11              5             43
Bourne Shell                     1              0              0              3
-------------------------------------------------------------------------------
SUM:                            61            865           1487           3074
-------------------------------------------------------------------------------