Kalman filtering & smoothing - Sharif
Transcript of Kalman filtering & smoothing - Sharif
Kalman filtering & smoothing
40-957 Special Topics in Artificial Intelligence:
Probabilistic Graphical Models
Sharif University of Technology
Soleymani
Spring 2014
From latent variable models to dynamic
models
2
Two categories of latent variable models that we have seen in
previous lectures:
Discrete latent variable
Mixture models
Continuous latent variable
Factor analysis
Dynamical models
Mixture models -> HMM
HMM as dynamical generalization of mixture models
latent variables are discrete but with arbitrary emission probability distributions.
Factor Analysis -> Kalman Filter
Kalman filter as dynamical generalization of factor analysis
State-Space Model (SSM)
3
The latent variables ๐1, โฆ , ๐๐ are form a chain.
Independence relationships (the same as HMM):
Given the state at one moment in the time, the states in the future are conditionally independent of those in the past.
The observation of the observation nodes fails to separate any of the state nodes.
๐1 ๐2 ๐๐
๐1 ๐2 ๐๐
โฆ ๐๐โ1
๐๐โ1
Linear Dynamical System (LDS)
4
๐1 = ๐ ๐๐ก~๐ฉ(๐, ๐บ0)
๐๐ก+1 = ๐จ๐๐ก + ๐ฎ๐๐ก+1 ๐๐ก~๐ฉ(๐, ๐ธ)
๐๐ก = ๐ช๐๐ก + ๐๐ก ๐๐ก~๐ฉ(๐, ๐น)
๐ ๐1 = ๐ฉ(๐1|๐, ๐บ0) ๐ ๐๐ก+1|๐๐ก = ๐ฉ ๐๐ก+1|๐จ๐๐ก , ๐ฎ๐ธ๐ฎ๐
๐ ๐๐ก|๐๐ก = ๐ฉ ๐๐ก|๐ช๐๐ก, ๐น
Linear Gaussian model
๐1 ๐2 ๐๐
๐1 ๐2 ๐๐
โฆ ๐๐โ1
๐๐โ1
๐๐ก+1 = ๐(๐๐ก) + ๐ฎ๐๐ก+1 ๐๐ก~๐ฉ(๐, ๐ธ)
๐๐ก = ๐(๐๐ก) + ๐๐ก ๐๐ก~๐ฉ(๐, ๐น)
General state space model:
Kalman filter applications
5
The Kalman filter has been widely used in many real-time
tracking applications.
Many other applications such as:
Navigation and guidance system (Simultaneous Localization
And Mapping)
Control systems
Time-series processing
Inference in LDS
6
Calculation of the posterior probability of the states given
an observation sequence
We will see two types of inference problems on LDS:
Filtering
๐ ๐๐ก|๐1, โฆ , ๐๐ก
Smoothing
๐ ๐๐ก|๐1, โฆ , ๐๐
Online inference
Offline inference
Inference in LDS
7
The graphical model of LDS is tree-structured and inference
can be solved efficiently using the sum-product algorithm:
Filtering: The forward recursions, analogous to ๐ผ messages of HMM, are
known as Kalman filter equations
Smoothing: The backward recursions, analogous to ๐ฝ messages, are
known as the Kalman smoother equations
Inference algorithms on SSM are similar to the inference
algorithms on HMM
Message passing
8
Joint distribution (on a linear-Gaussian network) is multi-
variate Gaussian
Thus, marginal and conditional distributions will also be
Gaussian.
We can use message-passing in Gaussian networks to
solve inference problems of LDS
We will focus on only mean and variance computations
Kalman filter: messages
9
Filtering is similar to (but not the same as) forward algorithm in
HMM:
๐ผ ๐ก ๐๐ก = ๐ ๐๐ก|๐1, โฆ , ๐๐ก =๐ ๐๐ก , ๐1, โฆ , ๐๐ก
๐ ๐1, โฆ , ๐๐ก=
๐ผ๐ก ๐๐ก
๐ ๐1, โฆ , ๐๐ก
The distribution ๐ ๐๐ก|๐1, โฆ , ๐๐ก is ๐ฉ ๐๐ก|๐๐๐ก|๐1:๐ก, ๐ฎ๐๐ก|๐1:๐ก
Assume that we have calculated ๐ผ ๐ก ๐๐ก we need to calculate
๐ผ ๐ก+1 ๐๐ก+1 = ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก+1
๐1 ๐2 ๐๐
๐1 ๐2 ๐๐
โฆ ๐๐โ1
๐๐โ1
๐ผ 1(. ) ๐ผ 2(. ) ๐ผ ๐โ1(. ) ๐ผ ๐(. )
Kalman filter
10
To find ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก+1 , we use two recursive
updates:
Predict step (time update): best guess before seeing
measurement
Compute ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก from ๐ ๐๐ก|๐1, โฆ , ๐๐ก
Measurement update step: after measurement, we find the
new posterior in which ๐๐ก+1 is also given as evidence
Compute ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก+1 from ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก
Kalman filter: prediction step
11
In thus step, we have ๐ ๐๐ก|๐1, โฆ , ๐๐ก = ๐ฉ ๐๐ก|๐๐ก|๐ก, ๐ฎ๐ก|๐ก and we
find ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก and ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก :
๐ ๐๐ก+1|๐1, โฆ , ๐๐ก = ๐ฉ ๐๐ก|๐๐ก+1|๐ก , ๐ฎ๐ก+1|๐ก
๐๐ก+1|๐ก โก ๐๐๐ก+1|๐1:๐ก
= ๐ธ๐๐ก+1|๐1:๐ก๐๐ก+1 = ๐ธ ๐ด๐๐ก + ๐๐ก+1|๐1:๐ก
= ๐จ๐๐๐ก|๐1:๐ก
๐ฎ๐ก+1|๐ก โก ๐บ๐๐ก+1|๐1:๐ก= ๐ธ๐๐ก+1|๐1:๐ก
๐๐ก+1 โ ๐๐ก+1|๐ก ๐๐ก+1 โ ๐๐ก+1|๐ก๐
= ๐ธ ๐ด๐๐ก + ๐ฎ๐๐ก+1 โ ๐๐ก+1|๐ก ๐ด๐๐ก + ๐ฎ๐๐ก+1 โ ๐๐ก+1|๐ก๐|๐1:๐ก
= ๐จ๐ฎ๐ก|๐ก๐จ๐ + ๐ฎ๐ธ๐ฎ๐
๐ฎ๐ก|๐ก โก ๐ฎ๐๐ก|๐1:๐ก
๐๐ก|๐ก โก ๐๐๐ก|๐1:๐ก
Kalman filter: prediction step
12
๐ ๐๐ก+1|๐1, โฆ , ๐๐ก = ๐ฉ ๐๐ก+1|๐๐๐ก+1|๐1:๐ก, ๐ฎ๐๐ก+1|๐1:๐ก
๐๐๐ก+1|๐1:๐ก
= ๐ธ๐๐ก+1|๐1:๐ก๐๐ก+1 = ๐ธ ๐ช๐๐ก+1 + ๐๐ก+1|๐1:๐ก = ๐ช๐๐ก+1|๐ก
๐ฎ๐๐ก+1|๐1:๐ก= ๐ธ๐๐ก+1|๐1:๐ก
๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก
๐
= ๐ธ ๐ช๐๐ก+1 + ๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก๐ช๐๐ก+1 + ๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก
๐|๐1:๐ก
= ๐ช๐ฎ๐ก+1|๐ก๐ช๐ + ๐น
๐ฎ๐ก|๐ก โก ๐ฎ๐๐ก|๐1:๐ก
๐๐ก|๐ก โก ๐๐๐ก|๐1:๐ก
Kalman filter: measurement update
13
We want to find ๐ ๐๐ก+1|๐1, โฆ , ๐๐ก , ๐๐ก+1 and for this purpose we
first find the joint distribution ๐ ๐๐ก+1, ๐๐ก+1|๐1, โฆ , ๐๐ก :
๐ฎ๐๐ก+1,๐๐ก+1|๐1:๐ก= ๐ธ๐๐ก+1,๐๐ก+1|๐1:๐ก
๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก
๐
= ๐ธ ๐ช๐๐ก+1 + ๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก๐๐ก+1 โ ๐๐๐ก+1|๐1:๐ก
๐|๐1:๐ก = ๐ช๐ฎ๐ก+1|๐ก
๐ ๐๐ก+1, ๐๐ก+1|๐1, โฆ , ๐๐ก
= ๐ฉ ๐๐ก+1, ๐๐ก+1
๐๐ก+1|๐ก
๐ช๐๐ก+1|๐ก,
๐ฎ๐ก+1|๐ก ๐ฎ๐ก+1|๐ก๐ช๐
๐ช๐ฎ๐ก+1|๐ก ๐ช๐ฎ๐ก+1|๐ก๐ช๐ + ๐น
๐ฎ๐ก|๐ก โก ๐ฎ๐๐ก|๐1:๐ก
๐๐ก|๐ก โก ๐๐๐ก|๐1:๐ก
Kalman filter: measurement update
14
๐ ๐๐ก+1, ๐๐ก+1|๐1, โฆ , ๐๐ก
= ๐ฉ ๐๐ก+1, ๐๐ก+1
๐๐ก+1|๐ก
๐ถ๐๐ก+1|๐ก,
๐ฎ๐ก+1|๐ก ๐ฎ๐ก+1|๐ก๐ช๐
๐ช๐ฎ๐ก+1|๐ก ๐ช๐ฎ๐ก+1|๐ก๐ช๐ + ๐น
Conditional distribution from the above joint distribution: ๐๐ก+1|๐ก+1 โก ๐๐๐ก+1|๐1:๐ก+1
= ๐๐ก+1|๐ก + ๐ฎ๐ก+1|๐ก๐ช๐ ๐ช๐ฎ๐ก+1|๐ก๐ช
๐ + ๐นโ1
๐๐ก+1 โ ๐ช๐๐ก+1|๐ก
๐ฎ๐ก+1|๐ก+1 โก ๐ฎ๐๐ก+1|๐1:๐ก+1
= ๐ฎ๐ก+1|๐ก โ ๐ฎ๐ก+1|๐ก๐ช๐ ๐ช๐ฎ๐ก+1|๐ก๐ช
๐ + ๐นโ1
๐ช๐ฎ๐ก+1|๐ก
๐ฎ๐ก|๐ก โก ๐ฎ๐๐ก|๐1:๐ก
๐๐ก|๐ก โก ๐๐๐ก|๐1:๐ก
๐ ๐1, ๐2 = ๐ฉ๐1
๐2
๐1
๐2,
๐ฎ11 ๐ฎ12
๐ฎ๐1 ๐ฎ22
โ ๐ ๐1|๐2 = ๐ฉ ๐1|๐1|2, ๐ฎ1|2
๐1|2 = ๐1 + ๐ฎ12๐ฎ22โ1 ๐2 โ ๐2
๐ฎ1|2 = ๐ฎ11 โ ๐ฎ12๐ฎ22โ1๐ฎ21
Kalman filter: measurement update
15
๐ ๐๐ก+1, ๐๐ก+1|๐1, โฆ , ๐๐ก
= ๐ฉ ๐๐ก+1, ๐๐ก+1
๐๐ก+1|๐ก
๐ถ๐๐ก+1|๐ก,
๐ฎ๐ก+1|๐ก ๐ฎ๐ก+1|๐ก๐ช๐
๐ช๐ฎ๐ก+1|๐ก ๐ช๐ฎ๐ก+1|๐ก๐ช๐ + ๐น
Conditional distribution from the above joint distribution: ๐๐ก+1|๐ก+1 โก ๐๐๐ก+1|๐1:๐ก+1
= ๐๐ก+1|๐ก + ๐ฎ๐ก+1|๐ก๐ช๐ ๐ช๐ฎ๐ก+1|๐ก๐ช
๐ + ๐นโ1
๐๐ก+1 โ ๐ช๐๐ก+1|๐ก
๐ฎ๐ก+1|๐ก+1 โก ๐ฎ๐๐ก+1|๐1:๐ก+1
= ๐ฎ๐ก+1|๐ก โ ๐ฎ๐ก+1|๐ก๐ช๐ ๐ช๐ฎ๐ก+1|๐ก๐ช
๐ + ๐นโ1
๐ช๐ฎ๐ก+1|๐ก
We also have found in the time update:
๐๐ก+1|๐ก = ๐จ๐๐ก|๐ก
๐ฎ๐ก+1|๐ก = ๐จ๐ฎ๐ก|๐ก๐จ๐ + ๐ฎ๐ธ๐ฎ๐
๐ฎ๐ก|๐ก โก ๐ฎ๐๐ก|๐1:๐ก
๐๐ก|๐ก โก ๐๐๐ก|๐1:๐ก
๐1|0 = ๐0
๐ฎ1|0 = ๐ฎ0
Kalman filter: measurement update
16
Updates based on Kalman gain matrix:
๐๐ก+1|๐ก+1 = ๐๐ก+1|๐ก + ๐ฒ๐ก+1 ๐๐ก+1 โ ๐ช๐๐ก+1|๐ก
๐ฎ๐ก+1|๐ก+1 = ๐ฎ๐ก+1|๐ก โ ๐ฒ๐ก+1๐ช๐ฎ๐ก+1|๐ก = ๐ฐ โ ๐ฒ๐ก+1๐ช ๐ฎ๐ก+1|๐ก
Update takes linear combination of predicted mean ๐ช๐๐ก+1|๐ก and
observation ๐๐ก+1, weighted by predicted covariance
Kalman filter as a process of making successive predictions ๐ช๐๐ก+1|๐ก and then
correcting these predictions in the light of the new observations ๐๐ก+1.
Covariance update is independent of observed measurements
Only depends on LDS parameters and can be computed offline
Kalman gain matrix
๐ฒ๐ก+1 โก ๐ฎ๐ก+1|๐ก๐ช๐ ๐ช๐ฎ๐ก+1|๐ก๐ช
๐ + ๐นโ1
Kalman filter: update equations
17
๐๐ก+1|๐ก+1 = ๐๐ก+1|๐ก + ๐ฒ๐ก+1 ๐๐ก+1 โ ๐ช๐๐ก+1|๐ก
๐ฎ๐ก+1|๐ก+1 = ๐ฎ๐ก+1|๐ก โ ๐ฒ๐ก+1๐ช๐ฎ๐ก+1|๐ก = ๐ฐ โ ๐ฒ๐ก+1๐ช ๐ฎ๐ก+1|๐ก
๐๐ก+1|๐ก = ๐จ๐๐ก|๐ก
๐ฎ๐ก+1|๐ก = ๐จ๐ฎ๐ก|๐ก๐จ๐ + ๐ฎ๐ธ๐ฎ๐
๐๐ก+1|๐ก+1 = ๐จ๐๐ก|๐ก + ๐ฒ๐ก+1 ๐๐ก+1 โ ๐ช๐จ๐๐ก|๐ก
๐ฎ๐ก+1|๐ก+1 = ๐ฐ โ ๐ฒ๐ก+1๐ช ๐จ๐ฎ๐ก|๐ก๐จ
๐ + ๐ฎ๐ธ๐ฎ๐
Smoothing
18
Off-line inference in an LDS
Combine forward recursion with a backward recursion
It is the Gaussian analog of the forwards-backwards (alpha-
gamma) algorithm on an HMM
Rauch-Tung-Striebel (RTS) smoother
19
Messages in the backward pass are ๐ ๐๐ก|๐๐ก+1, ๐1, โฆ , ๐๐ก and
first we find ๐ ๐๐ก, ๐๐ก+1|๐1, โฆ , ๐๐ก to compute the messages as
conditional of this joint distribution:
๐ ๐๐ก|๐1, โฆ , ๐๐ก = ๐ฉ ๐๐ก|๐๐ก|๐ก , ๐ฎ๐ก|๐ก
๐ ๐๐ก+1|๐1, โฆ , ๐๐ก = ๐ฉ ๐๐ก+1|๐๐ก+1|๐ก, ๐ฎ๐ก+1|๐ก
๐บ๐๐ก,๐๐ก+1|๐1:๐ก= ๐ธ๐๐ก,๐๐ก+1|๐1:๐ก
๐๐ก โ ๐๐ก|๐ก ๐๐ก+1 โ ๐๐ก+1|๐ก๐
= ๐ฎ๐ก|๐ก๐จ๐
๐ ๐๐ก, ๐๐ก+1|๐1, โฆ , ๐๐ก = ๐ฉ๐๐ก|๐ก
๐๐ก+1|๐ก
๐ฎ๐ก|๐ก ๐ฎ๐ก|๐ก๐จ๐
๐จ๐ฎ๐ก|๐ก ๐ฎ๐ก+1|๐ก
All of the above quantities are available after a forward pass (Kalman filter)
Rauch-Tung-Striebel (RTS) smoother
20
We find the conditional distribution ๐ ๐๐ก|๐๐ก+1, ๐1, โฆ , ๐๐ก from
the joint distribution introduced in the previous slide:
๐ ๐๐ก|๐๐ก+1, ๐1, โฆ , ๐๐ก = ๐ฉ ๐๐ก|๐๐๐ก|๐๐ก+1,๐1:๐ก
, ๐บ๐๐ก|๐๐ก+1,๐1:๐ก
๐๐๐ก|๐๐ก+1,๐1:๐ก= ๐๐ก|๐ก + ๐ณ๐ก ๐๐ก+1 โ ๐๐ก+1|๐ก
๐บ๐๐ก|๐๐ก+1,๐1:๐ก= ๐ฎ๐ก|๐ก โ ๐ณ๐ก๐ฎ๐ก+1|๐ก๐ณ๐ก
๐
๐ณ๐ก โก ๐ฎ๐ก|๐ก๐จ๐๐ฎ๐ก+1|๐ก
โ1
๐ ๐1|๐2 = ๐ฉ ๐1|๐1|2, ๐ฎ1|2
๐1|2 = ๐1 + ๐ฎ12๐ฎ22โ1 ๐2 โ ๐2
๐ฎ1|2 = ๐ฎ11 โ ๐ฎ12๐ฎ22โ1๐ฎ21
Rauch-Tung-Striebel (RTS) smoother
21
We find the conditional distribution ๐ ๐๐ก|๐๐ก+1, ๐1, โฆ , ๐๐ก from
the joint:
๐ ๐๐ก|๐๐ก+1, ๐1, โฆ , ๐๐ก = ๐ฉ ๐๐ก|๐๐๐ก|๐๐ก+1,๐1:๐ก, ๐บ๐๐ก|๐๐ก+1,๐1:๐ก
๐๐๐ก|๐๐ก+1,๐1:๐ก= ๐๐ก|๐ก + ๐ณ๐ก ๐๐ก+1 โ ๐๐ก+1|๐ก
๐บ๐๐ก|๐๐ก+1,๐1:๐ก= ๐ฎ๐ก|๐ก โ ๐ณ๐ก๐ฎ๐ก+1|๐ก๐ณ๐ก
๐
Also, according to the structure of the model:
๐ ๐๐ก|๐๐ก+1, ๐1, โฆ , ๐๐ก = ๐ ๐๐ก|๐๐ก+1, ๐1, โฆ , ๐๐
๐ณ๐ก โก ๐ฎ๐ก|๐ก๐จ๐๐ฎ๐ก+1|๐ก
โ1
RTS smoother: update equations
22
๐ ๐๐ก|๐1, โฆ , ๐๐ = ๐ฉ ๐๐ก|๐ , ๐บ๐ก|๐
๐๐ก|๐ = ๐๐ก|๐ก + ๐ณ๐ก ๐๐ก+1|๐ โ ๐๐ก+1|๐ก
๐บ๐ก|๐ = ๐บ๐ก|๐ก + ๐ณ๐ก ๐บ๐ก+1|๐ โ ๐บ๐ก+1|๐ก ๐ณ๐ก๐
Derivation for mean: ๐๐ก|๐ = ๐ธ ๐๐ก ๐1:๐ = ๐ธ ๐ธ[๐๐ก|๐๐ก+1, ๐1:๐ก]|๐1:๐
= ๐ธ ๐๐ก|๐ก + ๐ณ๐ก ๐๐ก+1 โ ๐๐ก+1|๐ก |๐1:๐
= ๐๐ก|๐ก + ๐ณ๐ก ๐๐ก+1|๐ โ ๐๐ก+1|๐ก
๐บ๐ก|๐ can be found similarly
๐ธ ๐ ๐ = ๐ธ ๐ธ[๐|๐, ๐]|๐
๐๐๐ ๐ ๐ = ๐๐๐ ๐ธ[๐|๐, ๐]|๐ + ๐ธ[๐๐๐[๐|๐, ๐]|๐]
๐๐|๐ and ๐บ๐|๐ are initialized from the filtering pass
๐ณ๐ก โก ๐ฎ๐ก|๐ก๐จ๐๐ฎ๐ก+1|๐ก
โ1
Example
23
In LDS, the sequence of individually most probable values of latent variables is the same as the most probable latent sequence.
No need to use the analogue of the Viterbi algorithm for the LDS.
Thus, red crosses show the most probable sequences obtained using filtering (b) and smoothing (c) algorithms
[Murphy]
Learning of LDS
24
Learning โ EM algorithm
E-step: expected sufficient statistics are found
๐ธ[๐๐ก]
๐ธ[๐๐ก๐๐ก๐]
๐ธ[๐๐ก๐๐กโ1๐ ]
M-step:
update of ๐ช and ๐น is similar to the M-step of factor analysis
LDS: summary
25
SSMs are dynamical models that allows continuous states
(latent variables)
LDS is a linear-Gaussian SSM
Inference problems in LDS can be solved using message
passing:
Kalman filter can be used to solve the filtering problem
RTS smoother can be used to solve the smoothing problem