没有合适的资源?快使用搜索试试~ 我知道了~
首页Kalman_and_Bayesian_Filters_in_Python
资源详情
资源评论
资源推荐
Kalman and Bayesian Filters in Python
Roger R Labbe Jr
August 9, 2015
2
Contents
Preface 11
0.1 Kalman and Bayesian Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
0.2 Motivation for this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
0.3 Reading Online . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
0.4 Host the Book Online for Free at SageMath . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
0.4.1 Installation Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
0.4.2 Reading/Using Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
0.5 PDF Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
0.6 Downloading the book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
0.7 Installation and Software Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
0.8 My Libraries and Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
0.9 Thoughts on Python and Coding Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
0.10 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
0.11 Contact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
0.12 Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1 The g-h Filter 17
1.1 Building Intuition via Thought Experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.2 The g-h Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
1.3 Notation and Nomenclature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.4 NumPy arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
1.4.1 Excercise - Create arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.4.2 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
1.5 Exercise: Write Generic Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.5.1 Solution and Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
1.6 Choice of g and h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.7 Exercise: create measurement function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
1.7.1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.7.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.8 Exercise: Bad Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.8.1 Solution and Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.9 Exercise: Extreme Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.9.1 Solution and Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.10 Exercise: The Effect of Acceleration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1.10.1 Solution and Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1.11 Exercise: Varying g . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.11.1 Solution and Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.12 Varying h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.13 Interactive Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
1.14 Don’t Lie to the Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
1.15 Tracking a Train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
1.16 g-h Filters with FilterPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3
4 CONTENTS
1.17 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
1.18 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
2 Discrete Bayes Filter 49
2.1 Tracking a Dog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
2.2 Extracting Information from Multiple Sensor Readings . . . . . . . . . . . . . . . . . . . . . . 51
2.3 Noisy Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
2.4 Incorporating Movement Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
2.5 Adding Noise to the Prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.6 Generalizing with Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.7 Integrating Measurements and Movement Updates . . . . . . . . . . . . . . . . . . . . . . . . 59
2.8 The Effect of Bad Sensor Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.9 Drawbacks and Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.10 Tracking and Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.10.1 Simulating the Train Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
2.11 Bayes Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.12 Total Probability Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
2.13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.14 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3 Gaussian Probabilities 73
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.2 Mean, Variance, and Standard Deviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.2.1 Random Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.2.2 The Mean of a Random Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.2.3 Standard Deviation of a Random Variable . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.2.4 Variance of a Random Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.2.5 Why the Square of the Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.3 Gaussians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.4 Nomenclature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.5 Gaussian Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
3.6 The Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.7 Interactive Gaussians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.8 Computational Properties of the Gaussian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.9 Computing Probabilities with scipy.stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
3.10 Fat Tails . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
3.11 Summary and Key Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.12 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4 One Dimensional Kalman Filters 91
4.1 One Dimensional Kalman Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2 Tracking A Dog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2.1 Simulating the Sensor Measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.2.2 Simulating the Dog’s movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.2.3 Implemention in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.3 Math with Gaussians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.3.1 Interactive Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.4 Implementing the Update Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
4.5 Implementing Predictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
4.5.1 Animating the Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
4.6 The Kalman Filter is a g-h Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
4.7 Fixed Gain Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
4.8 Implementation in a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
4.9 Full Description of the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
CONTENTS 5
4.9.1 Exercise: Modify Variance Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
4.10 Introduction to Designing a Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
4.10.1 Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
4.11 Exercise(optional): . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
4.11.1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
4.11.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
4.12 Example: Extreme Amounts of Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
4.13 Example: Incorrect Process Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
4.14 Example: Bad Initial Estimate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
4.15 Example: Large Noise and Bad Initial Estimate . . . . . . . . . . . . . . . . . . . . . . . . . . 122
4.16 Exercise: Interactive Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
4.16.1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
4.17 Exercise - Nonlinear Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
4.17.1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
4.17.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
4.18 Exercise - Noisy Nonlinear Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
4.18.1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
4.18.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
4.19 Derivation From Bayes Theorem (Optional) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
4.20 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
5 Multivariate Gaussians - Modeling Uncertainty in Multiple Dimensions 131
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
5.2 Multivariate Normal Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
5.3 Using Correlations to Improve Estimates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
5.4 Multiplying Multidimensional Gaussians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
5.5 Hidden Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
5.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
6 Multivariate Kalman Filters - Working with Multiple State Variables 151
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
6.2 Newton’s Equations of Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
6.3 Linear Algebra with NumPy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
6.4 Kalman Filter Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
6.5 Tracking a Dog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
6.6 Initialization - Choose State Variables and Set Initial Conditions . . . . . . . . . . . . . . . . 154
6.6.1 Step 1: Design State Variable as a Multivariate Gaussian . . . . . . . . . . . . . . . . 154
6.7 Predict Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
6.7.1 Step 2: Design the State Transition Function . . . . . . . . . . . . . . . . . . . . . . 156
6.7.2 Step 3: Design the Process Noise Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 158
6.7.3 Step 4: Design the Control Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
6.7.4 Prediction: Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
6.8 Update Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
6.8.1 Step 5: Design the Measurement Function . . . . . . . . . . . . . . . . . . . . . . . . 160
6.8.2 Step 6: Design the Measurement Noise Matrix . . . . . . . . . . . . . . . . . . . . . . 161
6.9 Implementing the Kalman Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
6.10 The Kalman Filter Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
6.10.1 Prediction Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
6.10.2 Update Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
6.10.3 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
6.11 Exercise: Show Effect of Hidden Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
6.11.1 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
6.11.2 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
6.12 Adjusting the Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
剩余453页未读,继续阅读
gregmankiw
- 粉丝: 29
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0