Kalman Filter 16-385 Computer Vision (Kris Kitani) Carnegie Mellon - - PowerPoint PPT Presentation

kalman filter
SMART_READER_LITE
LIVE PREVIEW

Kalman Filter 16-385 Computer Vision (Kris Kitani) Carnegie Mellon - - PowerPoint PPT Presentation

Kalman Filter 16-385 Computer Vision (Kris Kitani) Carnegie Mellon University Examples up to now have been discrete (binary) random variables Kalman filtering can be seen as a special case of a temporal inference with continuous random


slide-1
SLIDE 1

Kalman Filter

16-385 Computer Vision (Kris Kitani)

Carnegie Mellon University

slide-2
SLIDE 2

Examples up to now have been discrete (binary) random variables Kalman ‘filtering’ can be seen as a special case of a temporal inference with continuous random variables

x0 x1 x2 x3 x4 e1 e2 e3 e4

x

e

P(e|x)

P(xt|xt−1)

Everything is continuous…

probability distributions are no longer tables but functions

P(x0)

slide-3
SLIDE 3

Making the connection to the ‘filtering’ equations P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) X

Xt

P(Xt+1|Xt)P(Xt|e1:t) P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) Z

xt

P(Xt+1|xt)P(xt|e1:t)dxt

belief motion model

  • bservation model

Gaussian Gaussian Gaussian integral because continuous PDFs Tables Tables Tables

Kalman Filtering (Discrete) Filtering

slide-4
SLIDE 4

x

Simple, 1D example…

slide-5
SLIDE 5

xt = xt−1 + s + rt

System (motion) model

s x1 r2 x2

know velocity noise

rt ∼ N(0, σR)

‘sampled from’

slide-6
SLIDE 6

P(xt|xt−1)

s x1 r2 x2

know velocity noise

How do you represent the motion model?

xt = xt−1 + s + rt

rt ∼ N(0, σR)

slide-7
SLIDE 7

s x1 r2 x2

know velocity noise

xt = xt−1 + s + rt

rt ∼ N(0, σR)

P(xt|xt−1) = N(xt; xt−1 + s, σr)

A linear Gaussian (continuous) transition model How can you visualize this distribution?

How do you represent the motion model?

mean standard deviation

slide-8
SLIDE 8

s x1 x2

know velocity

P(xt|xt−1) = N(xt; xt−1 + s, σr)

A linear Gaussian (continuous) transition model Why don’t we just use a table as before?

s, σr)

t; xt−1 + s,

slide-9
SLIDE 9

zt = xt + qt

x1 q1 z1

GPS

GPS measurement True position

Observation (measurement) model

sensor error

qt ∼ N(0, σQ)

sampled from a Gaussian

slide-10
SLIDE 10

zt = xt + qt

x1 q1 z1

GPS

GPS measurement True position sensor error

qt ∼ N(0, σQ)

How do you represent the observation (measurement) model?

P(e|x)

e represents z

slide-11
SLIDE 11

zt = xt + qt

x1 q1 z1

GPS

GPS measurement True position sensor error

qt ∼ N(0, σQ)

P(zt|xt) = N(zt; xt, σQ)

How do you represent the observation (measurement) model?

Also a linear Gaussian model

slide-12
SLIDE 12

zt = xt + qt

x1 z1

GPS

GPS measurement True position

qt ∼ N(0, σQ)

P(zt|xt) = N(zt; xt, σQ)

How do you represent the observation (measurement) model?

Also a linear Gaussian model

slide-13
SLIDE 13

x0 ˆ x0

Prior (initial) State

initial estimate initial estimate uncertainty true position

σ0

slide-14
SLIDE 14

x0 ˆ x0

initial estimate

How do you represent the prior state probability?

true position

slide-15
SLIDE 15

x0 ˆ x0

initial estimate

P(ˆ x0) = N(ˆ x0; x0, σ0)

true position

How do you represent the prior state probability?

Also a linear Gaussian model!

slide-16
SLIDE 16

x0 ˆ x0

initial estimate

P(ˆ x0) = N(ˆ x0; x0, σ0)

true position

How do you represent the prior state probability?

Also a linear Gaussian model

slide-17
SLIDE 17

Inference

So how do you do temporal filtering with the KL?

slide-18
SLIDE 18

Recall: the first step of filtering was the ‘prediction step’ P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) Z

xt

P(Xt+1|xt)P(xt|e1:t)dxt

prediction step

belief motion model

compute this! It’s just another Gaussian

need to compute the ‘prediction’ mean and variance…

slide-19
SLIDE 19

How would you predict given ?

ˆ x0 ˆ x1

ˆ x1 = ˆ x0 + s

(This is the mean)

σ2

1 = σ2 0 + σ2 r

(This is the variance)

Prediction

(Using the motion model)

using this ‘cap’ notation to denote ‘estimate’

slide-20
SLIDE 20

P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) Z

xt

P(Xt+1|xt)P(xt|e1:t)dxt

prediction step

belief motion model

the second step after prediction is …

slide-21
SLIDE 21

… update step!

prediction

  • bservation

P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) Z

xt

P(Xt+1|xt)P(xt|e1:t)dxt

compute this (using results of the prediction step)

slide-22
SLIDE 22

sensor estimate system prediction

z1 ˆ x1 In the update step, the sensor measurement corrects the system prediction

Which estimate is correct? Is there a way to know?

ˆ x0

initial estimate

σ2

1

σ2

q

uncertainty uncertainty

Is there a way to merge this information?

slide-23
SLIDE 23

So we want a weighted state estimate correction Intuitively, the smaller variance mean less uncertainty.

sensor estimate system prediction σ2

1

σ2

q

ˆ x+

1 =

σ2

q

σ2

1 + σ2 q

ˆ x1 + σ2

1

σ2

1 + σ2 q

z1

This happens naturally in the Bayesian filtering (with Gaussians) framework!

something like this…

slide-24
SLIDE 24

P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) Z

xt

P(Xt+1|xt)P(xt|e1:t)dxt

  • ne step motion prediction
  • bservation

Recall the filtering equation:

Gaussian Gaussian

What is the product of two Gaussians?

slide-25
SLIDE 25

… a product of two Gaussians

µ = µ1σ2

2 + µ2σ2 1

σ2

2 + σ2 1

σ = σ2

1σ2 2

σ2

1 + σ2 2

✓ ◆

When we multiply the prediction (Gaussian) with the

  • bservation model (Gaussian) we get …

applied to the filtering equation… Recall …

slide-26
SLIDE 26

P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) Z

xt

P(Xt+1|xt)P(xt|e1:t)dxt mean: variance: mean: variance: σ1 ˆ x1 z1 σq new mean: new variance: ˆ x+

1 = ˆ

x1σ2

q + z1σ2 1

σ2

q + σ2 1

ˆ σ2+

1

= σ2

qσ2 1

σ2

q + σ2 1

‘plus’ sign means post ‘update’ estimate

slide-27
SLIDE 27

sensor estimate system prediction σ2

1

σ2

q

ˆ x+

1 = ˆ

x1σ2

q + z1σ2 1

σ2

q + σ2 1

= ˆ x1 σ2

q

σ2

q + σ2 1

+ z1 σ2

1

σ2

q + σ2 1

With a little algebra…

We get a weighted state estimate correction!

slide-28
SLIDE 28

Kalman gain notation

σ+

1 =

σ2

1σ2 q

σ2

1 + σ2 q

= ✓ 1 − σ2

1

σ2

1 + σ2 q

◆ σ2

1 = (1 − K) σ2 1

ˆ x+

1 = ˆ

x1 + σ2

1

σ2

q + σ2 1

(z1 − ˆ x1) = ˆ x1 + K(z1 − ˆ x1)

With a little algebra… ‘Kalman gain’ ‘Innovation’ With a little algebra…

slide-29
SLIDE 29

ˆ x+

1 = ˆ

x1 + σ2

1

σ2

1 + σ2 q

(z1 − ˆ x1) ˆ x+

1 = ˆ

x1 + K(z1 − ˆ x1)

Summary (1D Kalman Filtering)

‘Kalman gain’ K = σ2

1

σ2

1 + σ2 q

mean of the new Gaussian variance of the new Gaussian

σ2+

1

= σ2

1 −

σ2

1

σ2

1 + σ2 q

σ2

1

σ2+

1

= σ2

1 − Kσ2 1

P(Xt+1|e1:t+1) ∝ P(et+1|Xt+1) Z

xt

P(Xt+1|xt)P(xt|e1:t)dxt

To solve this… Compute this…

slide-30
SLIDE 30

[x p] = KF(x,v,z) x = x + s; v = v + q; K = v/(v + r); x = x + K * (z - x); p = v - K * v;

Simple 1D Implementation Just 5 lines of code!

slide-31
SLIDE 31

[x P] = KF(x,v,z) x = (x+s)+(v+q)/((v+q)+r)*(z-(x+s)); p = (v+q)-(v+q)/((v+q)+r)*v;

  • r just 2 lines
slide-32
SLIDE 32

¯ µt = Atµt1 + But ¯ Σt = AtΣt1A>

t + R

Kt = ¯ ΣtC>

t (Ct ¯

ΣtC>

t + Qt)1

µt = ¯ µt + Kt(zt − Ct¯ µt) Σt = (I − KtCt) ¯ Σt

KalmanFilter(µt−1, Σt−1, ut, zt)

Prediction Gain Update

Bare computations (algorithm) of Bayesian filtering:

prediction mean prediction covariance motion control ‘old’ mean Gaussian noise ‘old’ covariance

  • bservation model

update mean update covariance

slide-33
SLIDE 33

[x P] = KF(x,P,z) x = A*x; P = A*P*A' + Q; K = P*C'/(C*P*C' + R); x = x + K*(z - C*x); P = (eye(size(K,1))-K*C)*P;

Simple Multi-dimensional Implementation (also 5 lines of code!)

slide-34
SLIDE 34

2D Example

slide-35
SLIDE 35

x =  x y

  • z =

 x y

  • xt = Axt−1 + But + ✏t

state measurement Constant position Motion Model x y

slide-36
SLIDE 36

x =  x y

  • z =

 x y

  • xt = Axt−1 + But + ✏t

state measurement Constant position Motion Model

A =  1 1

  • Constant position

Bu =  0

  • ✏t ∼ N(0, R)

system noise

R =  σ2

r

σ2

r

  • x

y

slide-37
SLIDE 37

x =  x y

  • z =

 x y

  • state

measurement Measurement Model

zt = Ctxt + δt

x y

slide-38
SLIDE 38

x =  x y

  • z =

 x y

  • state

measurement Measurement Model

zero-mean measurement noise

zt = Ctxt + δt

C =  1 1

  • δt ∼ N(0, Q)

Q =  σ2

q

σ2

q

  • x

y

slide-39
SLIDE 39

¯ µt = Atµt1 + But ¯ Σt = AtΣt1A>

t + R

Kt = ¯ ΣtC>

t (Ct ¯

ΣtC>

t + Qt)1

µt = ¯ µt + Kt(zt − Ct¯ µt) Σt = (I − KtCt) ¯ Σt

General Case ¯ xt = xt−1 ¯ Σt = Σt−1 + R Kt = ¯ Σt( ¯ Σt + Q)−1 xt = ¯ xt + Kt(zt − ¯ xt) Σt = (I − Kt) ¯ Σt Constant position Model

A =  1 1

  • C =

 1 1

  • motion model
  • bservation model

Algorithm for the 2D object tracking example

slide-40
SLIDE 40

[x P] = KF_constPos(x,P,z) P = P + Q; K = P / (P + R); x = x + K * (z - x); P = (eye(size(K,1))-K) * P;

Just 4 lines of code Where did the 5th line go?

slide-41
SLIDE 41

¯ µt = Atµt1 + But ¯ Σt = AtΣt1A>

t + R

Kt = ¯ ΣtC>

t (Ct ¯

ΣtC>

t + Qt)1

µt = ¯ µt + Kt(zt − Ct¯ µt) Σt = (I − KtCt) ¯ Σt

General Case ¯ xt = xt−1 ¯ Σt = Σt−1 + R Kt = ¯ Σt( ¯ Σt + Q)−1 xt = ¯ xt + Kt(zt − ¯ xt) Σt = (I − Kt) ¯ Σt Constant position Model