Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7:...

25
Sensor Fusion, 2014 Lecture 7: 1 Lecture 7: Whiteboard: I PF tuning and properties Slides: I Proposal densities and SIS PF I Marginalized PF (MPF) I Filterbanks

Transcript of Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7:...

Page 1: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 1

Lecture 7:

Whiteboard:I PF tuning and properties

Slides:I Proposal densities and SIS PFI Marginalized PF (MPF)I Filterbanks

Page 2: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 2

Lecture 6: SummaryBasic SIR PF algorithmChoose the number of particles N.Initialization: Generate x i

0 ∼ px0 , i = 1, . . . ,N, particles.Iterate for k = 1, 2, . . . , t:1. Measurement update: For k = 1, 2, . . . ,

w ik = w i

k−1p(yk |x ik).

2. Normalize: w ik := w i

k/∑

i wik .

3. Estimation: MMSE xk ≈∑N

i=1 w ikx i

k or MAP.4. Resampling: Bayesian bootstrap: Take N samples with

replacement from the set {x ik}Ni=1 where the probability to take

sample i is w ik . Let w i

k = 1/N.5. Prediction: Generate random process noise samples

v ik ∼ pvk x i

k+1 = f (x ik , v

ik).

Page 3: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 3

PF design

Design freedoms:1. Choice of N is a complexity vs performance trade-off.

Complexity is linear in N, while the error in theory is boundedas gk/N, where gk is polynomial in k but independent of nx .

2. Neff = 1∑i (w

ik)

2 controls how often to resample. Resample if

Neff < Nth. Nth = N gives SIR. Resampling increases variancein the weights, and thus the variance in the estimate, but it isneeded to avoid depletion.

3. The proposal density. An appropriate proposal makes theparticles explore the most critical regions, without wastingefforts on meaningless state regions.

4. Pretending the process (and measurement) noise is larger thanit is (dithering, jittering, roughening) is as for the EKF andUKF often a sound ad-hoc solution to avoid filter divergence.

Page 4: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 4

Common PF extensions

Main problem with basic SIR PF: depletion.

After a while, only one or a few particles are contributing to x .

The effective number of samples, Neff is a measure of this.Neff = N means that all particles contribute equally, and Neff = 1means that only one has a non-zero weight.Too few design parameters, more degrees of freedom:

I Sequential importance sampling: means that you onlyresample when needed, Neff < Nth.

I The theory allows for a general proposal distributionq(x i

k |x i0:k−1, y1:k) for how to sample a new state in the time

update. The “prior” q(x ik |x i

0:k−1, y1:k) = p(x ik |x i

k−1) is thestandard option, but there might be better ones.

Page 5: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 5

SIS PF algorithmChoose the number of particles N, a proposal densityq(x i

k |x i0:k−1, y1:k), and a threshold Nth (for instance Nth = 2N/3).

Initialization: Generate x i0 ∼ px0 , i = 1, . . . ,N.

Iterate for k = 1, 2, . . . :1. Measurement update: For i = 1, 2, . . . ,N,

w ik = w i

k−1p(yk |x i

k)p(xik |x i

k−1)

q(x ik |x i

k−1, yk).

2. Normalize: w ik := w i

k/∑

i wik .

3. Estimation: MMSE xk ≈∑N

i=1 w ikx i

k .4. Resampling: Resample with replacement when

Neff = 1∑i (w

ik)

2 < Nth.

5. Prediction: Generate samples x ik+1 ∈ q(xk |x i

k−1, yk).

Page 6: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 6

Sampling from proposal densitySIR PF samples from the prior x i

k+1 ∼ p(xk+1|x ik). In general, one

can sample from any proposal density,

x ik+1 ∼ q(xk+1|x i

k , yk+1).

Note that we are allowed to “cheat” and look at the nextmeasurement yk+1 when we sample. Note that the time updatecan be written

p(xk+1|y1:k) =

∫Rnx

q(xk+1|xk , yk+1)p(xk+1|xk)

q(xk+1|xk , yk+1)p(xk |y1:k) dxk .

The new approximation becomes

p(x1:k+1|y1:k) =N∑

i=1

p(x ik+1|x i

k)

q(x ik+1|x i

k , yk+1)w i

k|k︸ ︷︷ ︸w i

k+1|k

δ(x1:k+1 − x i1:k+1).

Page 7: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 7

Choice of proposal density

1. Factorized form

q(x0:k |y1:k) = q(xk |x0:k−1, y1:k)q(x0:k−1|y1:k),

In the original form, we sample trajectories.2. Approximate filter form

q(x0:k |y1:k) ≈ q(xk |x0:k−1, y1:k)

In the approximate form, we keep the previous trajectory and justappend xk .

Page 8: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 8

1. Optimal form

q(xk |x ik−1, yk) = p(xk |x i

k−1, yk) =p(yk |xk)p(xk |x i

k−1)

p(yk |x ik−1)

,

w ik = w i

k−1p(yk |xk−1).

Optimal since the sampling process of xk does not influence (thatis, increase variance of) the weights. Drawbacks:

I It is generally hard to sample from this proposal density.I It is generally hard to compute the weight update needed for

this proposal density, since it would require to integrate overthe whole state space to obtain something computablep(yk |xk−1) =

∫p(yk |xk)p(xk |xk−1) dx .

For linear (linearized) Gaussian likelihood and additive Gaussianprocess noise, the integral can be solved, leading to a (extended)KF time update.

Page 9: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 9

2. Prior

q(xk |x ik−1, yk) = p(xk |x i

k−1),

w ik = w i

k−1p(yk |x ik).

The absolutely simplest and most common choice.

Page 10: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 10

3. Likelihood

q(xk |x ik−1, yk) = p(yk |xk),

w ik = w i

k−1p(xk |x ik−1).

Good in high SNR applications, when the likelihood contains moreinformation about x than the prior.Drawback: the likelihood is not always invertible in x .

Page 11: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 11

Marginalized Particle Filter

Objectives: decrease the number of particles for large state spaces(say nx > 3) by utilizing partial linear Gaussian substructures.The task of nonlinear filtering can be split into two parts:1. representation of the filtering probability density function2. propagation of this density during the time and measurement

update stagesPossible to mix a parametric distribution in some dimensions withgrid/particle represention in the other dimensions.

True Particle Mixed

−20

24

−2

0

2

4

0

0.05

0.1

0.15

x1x2

−2 −1 0 1 2 3 4 5−2

−1

0

1

2

3

4

5

x1

x2

−20

24

−2

0

2

4

0

0.05

0.1

0.15

x1x2

Page 12: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 12

Marginalized particle filter

Model

xnk+1 = f n

k (xnk )+F n

k (xnk )x

lk+Gn

k (xnk )w

nk ,

x lk+1 = f l

k (xnk )+F l

k(xnk )x

lk +G l

k(xnk )w

lk ,

yk = hk(xnk )+Hk(xn

k )xlk+ek .

All of wn, w l , e and xk0 are Gaussian. xn

0 can be general.Basic factorization holds: conditioned on xn

1:k , the model is linearand Gaussian.This framework covers many navigation, tracking and SLAMproblem formulations! Typically, position is the non-linear state,while all other ones are (almost) linear where the (extended) KF isused.

Page 13: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 13

Key factorization

Split the state vector into two parts (’linear’ and ’non-linear’)

xk =

(xnk

x lk

),

The key idea in the MPF is the factorization

p(x lk , x

n1:k |y1:k) = p(x l

k |xn1:k , y1:k)p(xn

1:k |y1:k).

Page 14: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 14

Factorization

KF factor provided by the Kalman filter

p(x lk |xn

1:k , y1:k) = N (x lk|k ,P

lk|k).

PF factor given by marginalization procedure

p(xn1:k+1|y1:k) = p(xn

k+1|xn1:k , y1:k)p(xn

1:k |y1:k)

= p(xn1:k |y1:k)

∫p(xn

k+1|x lk , x

n1:k , y1:k)p(x l

k |xn1:k , y1:k)dx l

k

= p(xn1:k |y1:k)

∫p(xn

k+1|x lk , x

n1:k , y1:k)N (x l

k|k ,Plk|k)dx l

k .

Page 15: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 15

ExampleTerrain navigation in 1D. Unknown velocity considered as a state.

xk+1 = xk + uk +T 2

s2

vk ,

uk+1 = uk + Tsvk ,

yk = h(xk) + ek ,

Conditional on trajectory x1:k , the velocity is given by a linear andGaussian model

uk+1 = uk + Tsvk , dynamics

xk+1 − xk = uk +T 2

s2

vk measurement.

Given this trajectory, KF time updates linear part

xk+1 = xk + uk|k +T 2

s2

vk , Cov(uk) = Pk|k

yk = h(xk) + ek .

Page 16: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 16

Principal MPF Algorithm

1. PF time update using where x lk is intepreted as process noise.

2. KF time update using for each particle xn,i1:k .

3. KF extra measurement update using for each particle xn,i1:k .

4. PF measurement update and resampling where x lk is intepreted

as measurement noise.5. KF measurement update for each particle xn,i

1:k .

If there is no linear term in the measurement equation, the KFmeasurement update in 5 disappears, and the Ricatti equation forP becomes the same for all sequences xn

1:k . That is, only oneKalman gain for all particles!

Page 17: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 17

Information flow

There are five indeces k in the right hand side factorization of theprior.Each index is stepped up separately.The order is important!Prior p(x l

k , xp1:k |y1:k) = p(x l

k |xp1:k , y1:k)p(x

p1:k |y1:k)

1. PF TU p(xp1:k |y1:k) ⇒ p(xp

1:k+1|y1:k)2. KF TU p(x l

k |xp1:k , y1:k) ⇒ p(x l

k+1|xp1:k , y1:k)

3. KF dyn MU p(x lk+1|x

p1:k , y1:k) ⇒ p(x l

k+1|xp1:k+1, y1:k)

4. PF MU p(xp1:k+1|y1:k) ⇒ p(xp

1:k+1|y1:k+1)5. KF obs MU p(x l

k+1|xp1:k+1, y1:k) ⇒ p(x l

k+1|xp1:k+1, y1:k+1)

Posterior p(x lk+1, x

p1:k+1|y1:k+1) = p(x l

k+1|xp1:k+1, y1:k+1)p(x

p1:k+1|y1:k+1)

Page 18: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 18

Properties

MPF compared to full PF givesI Fewer particles needed.I Less variance.I Less risk of divergence.I Less tuning of importance density and resampling needed.

at the cost of a more complex algorithm.

Page 19: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 19

The variance formula

The law of total variance says that

Cov (U) = Cov (E(U|V )) + E (Cov(U|V )) .

Example: x ∈ 0.5N (−1, 1) + 0.5N (1, 1). Let U = N (0, 1) and Vthe mode ±1. Then

E(x) = 0,

Var(x) = 1+(0.5 · (1− 0)20.5 · (−1− 0)2

)= 2

Page 20: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 20

Property: variance reduction

Letting U = x lk and V = xn

1:k gives the following decomposition ofthe variance of the PF:

Cov(x lk)︸ ︷︷ ︸

PF

= Cov(E(x l

k |xn1:k))+ E

(Cov(x l

k |xn1:k))

= Cov(x lk|k(x

n,i1:k))

︸ ︷︷ ︸MPF

+N∑

i=1

w ik Pk|k(x

n,i1:k)︸ ︷︷ ︸

KF

.

Page 21: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 21

Decreasing variance or N

102

103

104

105

0

2

4

6

8

10

12

N

Pl

Covariance for linear states

MPF

PF

KF

Schematic view of how the covariance of the linear part of the statevector depends on the number of particles for the PF and MPF,respectively. The gain in MPF is given by the Kalman filtercovariance.

Page 22: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 22

Jump Markov Linear ModelGeneral linear model with discrete mode parameter ξ, which takeson values 1, 2, . . .m:

xk+1 = F (ξk)xk + vk(ξk),

yk = H(ξk)xk + ek(ξk),

vk(ξk) ∈ N (µv (ξk),Q(ξk)),

ek(ξk) ∈ N (µe(ξk),R(ξk)),

x0(ξk) ∈ N (µx0(ξk),Px0(ξk)).

I Noises belong to a Gaussian mixture model.I A Gaussian mixture can approximate any PDF arbitrarily well.I The model is conditionally linear and Gaussian, so given the

sequence ξ1:k , the posterior is Gaussian and computed by theKalman filter(

xk |y1:k , ξ1:k)∈ N (xk|k(ξ1:k),Pk|k(ξ1:k)).

Page 23: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 23

The Gaussian mixture filterThe posterior is given by a Gaussian mixture (GM)

p(xk |y1:k) =

∑ξ1:k

p(ξ1:k |y1:k)p(xk |y1:k , ξ1:k)∑ξ1:k

p(ξ1:k |y1:k)

=

∑ξ1:k

p(ξ1:k |y1:k)N(xk|k(ξ1:k),Pk|k(ξ1:k)

)∑ξ1:k

p(ξ1:k |y1:k),

=∑

i

w (i)k|kN

(xk|k(ξ1:k),Pk|k(ξ1:k)

).

where the number of mixture components ξ1:k increasesexponentially in time.The weight update is similar to the PF

wk|k ∝ wk|k−1p(yk |ξ1:k , y1:k−1)

= wk|k−1N(yk − yk|k−1(ξ1:k), Sk|k−1(ξ1:k)

).

Page 24: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 24

MPF as a filter bank

Denoting xnk = ξk and x l

k = xk , we have a formal relationshipbetween the KF bank and MPF. They both compute theconditional distribution(

xk |y1:k , ξ1:k)∈ N (xk|k(ξ1:k),Pk|k(ξ1:k)),

using a KF.For a finite state space of ξk ∈ [1, 2, . . . ,M], there are moreintelligent algorithms than just sampling. However, the PF can stillbe used to get a unified and simple filter framework.

Page 25: Lecture7 - Automatic Controlfredrik/edu/sensorfusion/lecture7.pdf · Sensor Fusion, 2014 Lecture 7: 3 PFdesign Designfreedoms: 1.ChoiceofN isacomplexityvsperformancetrade-off. ComplexityislinearinN,whiletheerrorintheoryisbounded

Sensor Fusion, 2014 Lecture 7: 25

Filter SummaryI Approximate the model to a case where an optimal algorithm

exists.I EKF1 approximates the model with a linear one.I UKF and EKF2 apply higher order approximations.

Gives an approximate Gaussian posterior.I Approximate the optimal nonlinear filter for the original model.

I Point-mass filter (PMF) which uses a regular grid of the statespace and applies the Bayesian recursion.

I Particle filter (PF) which uses a random grid of the state spaceand applies the Bayesian recursion.

Gives a sample-based numerical approximation of the posteriorI Restrict model class to JML models with Gaussian mixture

(GM) noises.I Mitigate exponential complexity with merging (IMM).I Mitigate exponential complexity with pruning (link to PF).

Gives a GM-based numerical approximation of the posterior.I MPF is a hybrid method!