Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a...

7
1 Lecture 7: Kalman Filters CS 395T: Intelligent Robotics Benjamin Kuipers Stochastic Models of an Uncertain World Actions are uncertain. Observations are uncertain. ε i ~ N(0,σ i ) are random variables ˙ x = F( x , u) y = G( x) " ˙ x = F( x , u ,# 1 ) y = G( x , # 2 ) Observers The state x is unobservable. The sense vector y provides noisy information about x. • An observer is a process that uses sensory history to estimate x. Then a control law can be written u = H i x ) ˙ x = F( x , u ," 1 ) y = G( x , " 2 ) ˆ x = Obs (y) Kalman Filter: Optimal Observer (Maybeck’s introduction) u x y ˆ x " 2 " 1 ˙ x = F( x , u ," 1 ) y = G( x , " 2 ) Estimates and Uncertainty Conditional probability density function Gaussian (Normal) Distribution Completely described by N(μ,σ 2 ) – Mean μ – Standard deviation σ, variance σ 2 1 " 2# e $( x$ μ ) 2 /2 " 2

Transcript of Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a...

Page 1: Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a stream of observations, and a dynamical model. •At each step, a weighted average

1

Lecture 7:Kalman Filters

CS 395T: Intelligent RoboticsBenjamin Kuipers

Stochastic Models of anUncertain World

• Actions are uncertain.• Observations are uncertain.• εi ~ N(0,σi) are random variables

!

˙ x = F(x,u)

y = G(x)"

˙ x = F(x,u,#1)

y = G(x,#2)

Observers

• The state x is unobservable.• The sense vector y provides noisy information

about x.• An observer is a process that

uses sensory history to estimate x.• Then a control law can be written

!

u = Hi(ˆ x )

!

˙ x = F(x,u,"1)

y = G(x,"2)

!

ˆ x =Obs(y)

Kalman Filter: Optimal Observer(Maybeck’s introduction)

!

u

!

x

!

y

!

ˆ x

!

"2

!

"1

!

˙ x = F(x,u,"1)

y = G(x,"2)

Estimates and Uncertainty• Conditional probability density function

Gaussian (Normal) Distribution• Completely described by N(µ,σ2)

– Mean µ– Standard deviation σ, variance σ 2

!

1

" 2#e$( x$µ )2 / 2" 2

Page 2: Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a stream of observations, and a dynamical model. •At each step, a weighted average

2

The Central Limit Theorem

• The sum of many random variables– with the same mean, but– with arbitrary conditional density functions,

converges to a Gaussian density function.

• If a model omits many small unmodeledeffects, then the resulting error shouldconverge to a Gaussian density function.

Illustrating the Central Limit Thm– Add 1, 2, 3, 4 variables from the same distribution.

Estimating a Value• Suppose there is a constant value x.

– Distance to wall; angle to wall; etc.• At time t1, observe value z1 with variance• The optimal estimate is with

variance

!

"1

2

!

ˆ x (t1) = z

1

!

"1

2

A Second Observation• At time t2, observe value z2 with variance

!

"2

2

Merged Evidence Update Mean and Variance• Weighted average of estimates.

• The weights come from the variances.– Smaller variance = more certainty

!

ˆ x (t2) = Az

1+ Bz

2

!

ˆ x (t2) =

"2

2

"1

2+"

2

2

#

$ % %

&

' ( ( z

1+

"1

2

"1

2+ "

2

2

#

$ % %

&

' ( ( z

2

!

1

"2(t2)

=1

"1

2+1

"2

2

!

A + B =1

Page 3: Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a stream of observations, and a dynamical model. •At each step, a weighted average

3

From Weighted Averageto Predictor-Corrector

• Weighted average:

• Predictor-corrector:

• This version can be applied “recursively”.

!

ˆ x (t2) = Az

1+ Bz

2= (1" K)z

1+ Kz

2

!

ˆ x (t2) = z

1+ K(z

2" z

1)

!

= ˆ x (t1) + K(z

2" ˆ x (t

1))

Predictor-Corrector• Update best estimate given new data

• Update variance:

!

ˆ x (t2) = ˆ x ( t

1) + K(t

2)(z

2" ˆ x ( t

1))

!

K(t2) =

"1

2

"1

2+"

2

2

!

"2(t2) ="

2( t1) # K(t

2)"

2( t1)

!

= (1"K( t2))#

2( t1)

Static to Dynamic• Now suppose x changes according to

!

˙ x = F(x,u,") = u +" (N (0,#" ))

Dynamic Prediction

• At t2 we know• At t3 after the change, before an observation.

• Next, we correct this prediction with theobservation at time t3.

!

ˆ x (t3

") = ˆ x ( t

2) + u[ t

3" t

2]

!

"2(t3

#) = "

2( t2) + "$

2[t3# t

2]

!

ˆ x (t2) "

2(t

2)

Dynamic Correction• At time t3 we observe z3 with variance• Combine prediction with observation.

!

"3

2

!

ˆ x (t3) = ˆ x ( t

3

") + K( t

3)(z

3" ˆ x (t

3

"))

!

K(t3) =

" 2( t3

#)

"2( t3

#) + "

3

2

!

"2(t3) = (1# K(t

3))"

2(t3

#)

Qualitative Properties

• Suppose measurement noise is large.– Then K(t3) approaches 0, and the measurement

will be mostly ignored.• Suppose prediction noise is large.

– Then K(t3) approaches 1, and the measurementwill dominate the estimate.

!

K(t3) =

" 2( t3

#)

"2( t3

#) + "

3

2

!

ˆ x (t3) = ˆ x ( t

3

") + K( t

3)(z

3" ˆ x (t

3

"))

!

"3

2

!

"2(t3

#)

Page 4: Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a stream of observations, and a dynamical model. •At each step, a weighted average

4

Kalman Filter• Takes a stream of observations, and a

dynamical model.• At each step, a weighted average between

– prediction from the dynamical model– correction from the observation.

• The Kalman gain K(t) is the weighting,– based on the variances and

• With time, K(t) and tend to stabilize.

!

"2(t)

!

"#2

!

"2(t)

Simplifications• We have introduced Kalman filters using a

one-dimensional system.– Most applications are higher dimensional.

• We have assumed the state variable isobservable.– In general, sense data give indirect evidence.

• We will discuss the more complex case next.

!

˙ x = F(x,u,"1) = u +"

1

!

z =G(x,"2) = x +"

2

Up To Higher Dimensions(the Welch & Bishop version of the story)

• Our previous Kalman Filter discussion wasof a simple one-dimensional model.

• Now we go up to higher dimensions:– State vector:– Sense vector:– Motor vector:

• First, a little statistics.

!

x "#n

!

z "#m

!

u" #l

Expectations• Let x be a random variable.• The expected value E[x] is the mean:

– The probability-weighted mean of all possiblevalues. The sample mean approaches it.

• Expected value of a vector x is by component.!

E[x] = x p(x) dx" # x =1

Nxi

1

N

$

!

E[x] = x = [x 1,Lx

n]T

Variance and Covariance• The variance is E[ (x-E[x])2 ]

• Covariance matrix is E[ (x-E[x])(x-E[x])T ]

– Divide by N−1 to make the sample variance anunbiased estimator for the population variance.

!

"2

= E[(x # x )2] =

1

N(x

i# x )

2

1

N

$

!

Cij =1

N(xik " x i)(x jk " x j)

k =1

N

#

Biased and Unbiased Estimators• Strictly speaking, the sample variance

is a biased estimate of the populationvariance. An unbiased estimator is:

• But: “If the difference between N and N−1ever matters to you, then you are probablyup to no good anyway …” [Press, et al]

!

"2

= E[(x # x )2] =

1

N(x

i# x )

2

1

N

$

!

s2

=1

N "1(x

i" x )

2

1

N

#

Page 5: Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a stream of observations, and a dynamical model. •At each step, a weighted average

5

Covariance Matrix• Along the diagonal, Cii are variances.• Off-diagonal Cij are essentially correlations.

!

C1,1

="1

2C1,2

C1,N

C2,1

C2,2

="2

2

O M

CN ,1

L CN ,N

="N

2

#

$

% % % %

&

'

( ( ( (

Independent Variation• x and y are

Gaussian randomvariables (N=100)

• Generated withσx=1 σy=3

• Covariance matrix:

!

Cxy =0.90 0.44

0.44 8.82

"

# $

%

& '

Dependent Variation• c and d are random

variables.• Generated with

c=x+y d=x-y• Covariance matrix:

!

Ccd

=10.62 "7.93

"7.93 8.84

#

$ %

&

' (

Discrete Kalman Filter• Estimate the state x ∈ ℜn of a linear

stochastic difference equation

– process noise w is drawn from N(0,Q), withcovariance matrix Q.

• with a measurement z ∈ ℜm

– measurement noise v is drawn from N(0,R), withcovariance matrix R.

• A, Q are n×n. B is n×l. R is m×m. H is m×n.

!

xk

=Axk"1 + Bu

k+w

k"1

!

zk

=Hxk

+ vk

Estimates and Errors• is the estimated state at time-step k.• after prediction, before observation.• Errors:

• Error covariance matrices:

• Kalman Filter’s task is to update

!

ˆ x k"#

n

!

ˆ x k

"# $

n

!

ek

" = xk" ˆ x

k

"

ek

= xk" ˆ x

k

!

Pk

"= E[e

k

"ek

"T

]

Pk

= E[ekek

T]

!

ˆ x k

Pk

Time Update (Predictor)• Update expected value of x

• Update error covariance matrix P

• Previous statements were simplifiedversions of the same idea:

!

ˆ x k

"= Aˆ x

k"1 + Buk

!

Pk

"=AP

k"1AT

+Q

!

ˆ x (t3

") = ˆ x ( t

2) + u[ t

3" t

2]

!

"2(t3

#) = "

2( t2) + "$

2[t3# t

2]

Page 6: Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a stream of observations, and a dynamical model. •At each step, a weighted average

6

Measurement Update (Corrector)

• Update expected value

– innovation is• Update error covariance matrix

• Compare with previous form

!

ˆ x k

= ˆ x k

"+ K

k(z

k"Hˆ x

k

")

!

zk"Hˆ x

k

"

!

Pk

= (I"KkH)P

k

"

!

ˆ x (t3) = ˆ x ( t

3

") + K( t

3)(z

3" ˆ x (t

3

"))

!

"2(t3) = (1# K(t

3))"

2(t3

#)

The Kalman Gain• The optimal Kalman gain Kk is

• Compare with previous form

!

Kk

= Pk

"H

T(HP

k

"H

T+R)

"1

!

=Pk

"H

T

HPk

"H

T+R

!

K(t3) =

" 2( t3

#)

"2( t3

#) + "

3

2

Extended Kalman Filter• Suppose the state-evolution and

measurement equations are non-linear:

– process noise w is drawn from N(0,Q), withcovariance matrix Q.

– measurement noise v is drawn from N(0,R),with covariance matrix R.

!

x k = f (x k"1,uk ) +wk"1

!

zk

= h(xk) + v

k

The Jacobian Matrix• For a scalar function y=f(x),

• For a vector function y=f(x),

!

"y = # f (x)"x

!

"y = J"x =

"y1

M

"yn

#

$

% % %

&

'

( ( (

=

)f1

)x1

(x) L)f1

)xn(x)

M M

)fn)x1

(x) L)fn)xn

(x)

#

$

% % % % % %

&

'

( ( ( ( ( (

*

"x1

M

"xn

#

$

% % %

&

'

( ( (

Linearize the Non-Linear

• Let A be the Jacobian of f with respect to x.

• Let H be the Jacobian of h with respect to x.

• Then the Kalman Filter equations arealmost the same as before!

!

A ij ="f i

"x j

(x k#1,uk)

!

H ij ="hi

"x j

(x k)

EKF Update Equations• Predictor step:

• Kalman gain:

• Corrector step:

!

ˆ x k"

= f (ˆ x k"1,uk )

!

Pk

"=AP

k"1AT

+Q

!

Kk

= Pk

"H

T(HP

k

"H

T+R)

"1

!

ˆ x k

= ˆ x k

"+ K

k(z

k" h(ˆ x

k

"))

!

Pk

= (I"KkH)P

k

"

Page 7: Kalman Filter: Optimal Observerkuipers/handouts/S07/L7 Kalman filters.pdf4 Kalman Filter •Takes a stream of observations, and a dynamical model. •At each step, a weighted average

7

What Have We Got?• If we have a stochastic dynamical model of

how a system behaves, and• If we have a stream of data about the

system, and• If we can represent uncertainty (in the

model and in the data) with Gaussiandistributions, then

• We can merge data with predictions in agood (sometimes optimal) way.

TTD

• Intuitive explanations for APAT and HPHT

in the update equations.