+ All Categories
Home > Documents > The Particle Filter - TUM

The Particle Filter - TUM

Date post: 27-Feb-2022
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
55
PD Dr. Rudolph Triebel Computer Vision Group Machine Learning for Computer Vision Non-parametric implementation of Bayes filter Represents the belief (posterior) by a set of random state samples. This representation is approximate. Can represent distributions that are not Gaussian. Can model non-linear transformations. Basic principle: • Set of state hypotheses (“particles”) • Survival-of-the-fittest The Particle Filter 1
Transcript
Page 1: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

•Non-parametric implementation of Bayes filter

•Represents the belief (posterior) by a set of

random state samples.

•This representation is approximate.

•Can represent distributions that are not Gaussian.

•Can model non-linear transformations.

Basic principle:

•Set of state hypotheses (“particles”)

•Survival-of-the-fittest

The Particle Filter

1

Page 2: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Algorithm Bayes_filter :

1. if is a sensor measurement then

2.

3. for all do

4.

5.

6. for all do

7. else if is an action then

8. for all do

9. return

Machine Learning for Computer Vision

The Bayes Filter Algorithm (Rep.)

2

Page 3: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Set of weighted samples:

Mathematical Description

The samples represent the probability distribution:

State hypotheses Importance weights

Point mass distribution (“Dirac” )

3

Page 4: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

The Particle Filter Algorithm

Algorithm Particle_filter :

1.

2. for to do

3.

4.

5.

6. for to do

7. return

Sample from proposal

Compute sample weights

Resampling

4

Page 5: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Localization with Particle Filters

•Each particle is a potential pose of the robot

•Proposal distribution is the motion model of the robot

(prediction step)

•The observation model is used to compute the

importance weight (correction step)

Randomized algorithms are usually called Monte Carlo

algorithms, therefore we call this:

Monte-Carlo Localization

5

Page 6: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

A Simple Example

• The initial belief is a uniform distribution (global localization).

• This is represented by an (approximately) uniform sampling of initial particles.

6

Page 7: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Sensor Information

The sensor model is used to compute the new importance weights:

7

Page 8: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Robot Motion

After resampling and applying the motion model the particles are distributed more densely at three locations.

8

Page 9: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Again, we set the new importance weights equal to the sensor model.

Sensor Information

9

Page 10: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Resampling and application of the motion model:

One location of dense particles is left.

The robot is localized.

Robot Motion

10

Page 11: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

A Closer Look at the Algorithm…

Algorithm Particle_filter :

1.

2. for to do

3.

4.

5.

6. for to do

7. return

Sample from proposal

Compute sample weights

Resampling

11

Page 12: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Sampling from Proposal

This can be done in the following ways:

• Adding the motion vector to each particle directly (this assumes perfect motion)

• Sampling from the motion model , e.g. for a 2D motion with translation velocity v and rotation velocity w we have:

Position

Orientation

12

Page 13: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Start

Motion Model Sampling (Example)

13

Page 14: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Computation of the sample weights:

• Proposal distribution:(we sample from that using the motion model)

• Target distribution (new belief):(we can not directly sample from that → importance sampling)

• Computation of importance weights:

Computation of Importance Weights

14

Page 15: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Proximity Sensor Models

• How can we obtain the sensor model ?

• Sensor Calibration:

Laser sensor Sonar sensor

15

Page 16: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

• Given: Set of weighted samples.

• Wanted : Random sample, where the probability of drawing xi is equal to wi.

• Typically done M times with replacement to generate new sample set .

Resampling

for to do

16

Page 17: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

w2

w3

w1wn

Wn-1

Resampling

w2

w3

w1wn

Wn-1

•Standard n-times sampling results in high variance

•This requires more particles

•O(nlog n) complexity

• Instead: low variance sampling only samples once

• Linear time complexity

• Easy to implement

17

Page 18: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Sample-based Localization (sonar)

18

Page 19: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Initial Distribution

19

Page 20: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

After Ten Ultrasound Scans

20

Page 21: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

After 65 Ultrasound Scans

21

Page 22: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Estimated Path

22

Page 23: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Kidnapped Robot Problem

The approach described so far is able to

• track the pose of a mobile robot and to

• globally localize the robot.

• How can we deal with localization errors (i.e., the kidnapped robot problem)?

Idea: Introduce uniform samples at every resampling step

• This adds new hypotheses

23

Page 24: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Summary

• There are mainly 4 different types of sampling methods: Transformation method, rejections sampling, importance sampling and MCMC

• Transformation only rarely applicable

• Rejection sampling is often very inefficient

• Importance sampling is used in the particle filter which can be used for robot localization

• An efficient implementation of the resampling step is the low variance sampling

24

Page 25: The Particle Filter - TUM

Computer Vision Group Prof. Daniel Cremers

Markov Chain Monte Carlo

Page 26: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Markov Chain Monte Carlo

• In high-dimensional spaces, rejection sampling and importance sampling are very inefficient

• An alternative is Markov Chain Monte Carlo (MCMC)

• It keeps a record of the current state and the proposal depends on that state

• Most common algorithms are the Metropolis-Hastings algorithm and Gibbs Sampling

26

Page 27: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Markov Chains Revisited

A Markov Chain is a distribution over discrete-state random variables so that

The graphical model of a Markov chain is this:

We will denote as a row vector

A Markov chain can also be visualized as a state transition diagram.

27

x1, . . . ,xM

p(x1, . . . ,xT ) = p(x1)p(x2 | x1) · · · = p(x1)TY

t=2

p(xt | xt�1)

p(xt | xt�1) ⇡t

T

Page 28: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

The State Transition Diagram

A33 A33

A11 A11k=1

k=2

k=3

time

t-2 t-1 t

28

states

Page 29: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Some Notions

• The Markov chain is said to be homogeneous if the transitions probabilities are all the same at every time step t (here we only consider homogeneous Markov chains)

• The transition matrix is row-stochastic, i.e. all entries are between 0 and 1 and all rows sum up to 1

• Observation: the probabilities of reaching the states can be computed using a vector-matrix multiplication

29

Page 30: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

The Stationary Distribution

The probability to reach state k is

Or, in matrix notation:

We say that is stationary if

Questions:

•How can we know that a stationary distributions exists?

•And if it exists, how do we know that it is unique?

30

⇡t = ⇡t�1A

⇡k,t =KX

i=1

⇡i,t�1Aik

⇡t = ⇡t�1⇡t

Page 31: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

The Stationary Distribution (Existence)

To find a stationary distribution we need to solve the eigenvector problem

The stationary distribution is then where is the eigenvector for which the eigenvalue is 1.

This eigenvector needs to be normalized so that it is a valid distribution.

Theorem (Perron-Frobenius): Every row-stochastic matrix has such an eigen vector, but this vector may not be unique.

31

ATv = v

⇡ = vT v

Page 32: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Stationary Distribution (Uniqueness)

• A Markov chain can have many stationary distributions

• Sufficient for a unique stationary distribution: we can reach every state from any other state in finite steps at non-zero probability (i.e. the chain is ergodic)

• This is equivalent to the property that the transition matrix is irreducible:

32

1 2 3 4

0.9

0.90.5 0.5

1.00.10.1

8i, j 9m (Am)ij > 0

Page 33: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Main Idea of MCMC

• So far, we specified the transition probabilities and analysed the resulting distribution

• This was used, e.g. in HMMs

Now:

• We want to sample from an arbitrary distribution

• To do that, we design the transition probabilities so that the resulting stationary distribution is our desired (target) distribution!

33

Page 34: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Detailed Balance

34

Definition: A transition distribution satisfies the property of detailed balance if

The chain is then said to be reversible.

⇡t

⇡iAij = ⇡jAji

⇡1

⇡3 ⇡1A13 + · · ·

⇡3A31 + · · ·

A31

t-1 t

A13

Page 35: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Making a Distribution Stationary

Theorem: If a Markov chain with transition matrix

A is irreducible and satisfies detailed balance wrt. the distribution , then is a stationary distribution of the chain.

Proof:

it follows .

This is a sufficient, but not necessary condition.

35

⇡ ⇡

KX

i=1

⇡iAij =KX

i=1

⇡jAji = ⇡j

KX

i=1

Aji = ⇡j 8j

⇡ = ⇡A

Page 36: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Sampling with a Markov Chain

The idea of MCMC is to sample state transitions based on a proposal distribution q.

The most widely used algorithm is the Metropolis-Hastings (MH) algorithm.

In MH, the decision whether to stay in a given state is based on a given probability.

If the proposal distribution is , then we stay in state with probability

36

q(x0 | x)x

0

min

✓1,

p̃(x0)q(x | x0)

p̃(x)q(x0 | x)

Unnormalized target distribution

Page 37: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

The Metropolis-Hastings Algorithm

• Initialize

• for

•define

•sample

•compute acceptance probability

•compute

•sample

•set new sample to

37

x

0

s = 0, 1, 2, . . .

x = x

s

x

0 ⇠ q(x0 | x)

↵ =p̃(x0)q(x | x0)

p̃(x)q(x0 | x)r = min(1,↵)

u ⇠ U(0, 1)

x

s+1 =

(x

0 if u < r

x

s if u � r

Page 38: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Why Does This Work?

We have to prove that the transition probability of the MH algorithm satisfies detailed balance wrt the target distribution.

Theorem: If is the transition probability of the MH algorithm, then

Proof:

38

pMH(x0 | x)

p(x)pMH(x0 | x) = p(x0)pMH(x | x0)

Page 39: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Why Does This Work?

We have to prove that the transition probability of the MH algorithm satisfies detailed balance wrt the target distribution.

Theorem: If is the transition probability of the MH algorithm, then

Note: All formulations are valid for discrete and for continuous variables!

39

pMH(x0 | x)

p(x)pMH(x0 | x) = p(x0)pMH(x | x0)

Page 40: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Choosing the Proposal

• A proposal distribution is valid if it gives a non-zero probability of moving to the states that have a non-zero probability in the target.

• A good proposal is the Gaussian, because it has a non-zero probability for all states.

• However: the variance of the Gaussian is important!

•with low variance, the sampler does not explore sufficiently, e.g. it is fixed to a particular mode

•with too high variance, the proposal is rejected too often, the samples are a bad approximation

40

Page 41: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Example

Target is a mixture of 2 1D Gaussians.

Proposal is a Gaussian with different variances.

41

0

200

400

600

800

1000 −100

−50

0

50

100

0

0.1

0.2

Samples

MH with N(0,1.0002) proposal

Iterations

0

200

400

600

800

1000 −100

−50

0

50

100

0

0.01

0.02

0.03

Samples

MH with N(0,8.0002) proposal

Iterations

0

200

400

600

800

1000 −100

−50

0

50

100

0

0.02

0.04

0.06

Samples

MH with N(0,500.0002) proposal

Iterations

Page 42: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Gibbs Sampling

• Initialize

• For

•Sample

•Sample

•...

•Sample

Idea: sample from the full conditional

This can be obtained, e.g. from the Markov blanket in graphical models.

42

{zi : i = 1, . . . ,M}⌧ = 1, . . . , T

z(⌧+1)1 ⇠ p(z1 | z(⌧)2 , . . . , z(⌧)M )

z(⌧+1)2 ⇠ p(z2 | z(⌧+1)

1 , . . . , z(⌧)M )

z(⌧+1)M ⇠ p(zM | z(⌧+1)

1 , . . . , z(⌧+1)M�1 )

Page 43: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Gibbs Sampling: Example

• Use an MRF on a binary image with edge potentials (“Ising model”) and node potentials

43

(xt) = N (yt | xt,�2)

(xs, xt) = exp(Jxsxt)

xt

yt

xs

xt 2 {�1, 1}

Page 44: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Gibbs Sampling: Example

• Use an MRF on a binary image with edge potentials (“Ising model”) and node potentials

• Sample each pixel in turn

44

(xt) = N (yt | xt,�2)

sample 1, Gibbs

−1

−0.5

0

0.5

1sample 5, Gibbs

−1

−0.5

0

0.5

1mean after 15 sweeps of Gibbs

−1

−0.5

0

0.5

1

(xs, xt) = exp(Jxsxt)

After 1 sample After 5 samples Average after 15 samples

Page 45: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Gibbs Sampling is a Special Case of MH

• The proposal distribution in Gibbs sampling is

• This leads to an acceptance rate of:

• Although the acceptance is 100%, Gibbs sampling does not converge faster, as it only updates one variable at a time.

45

q(x0 | x) = p(x0i | x�i)I(x0

�i = x�i)

↵ =p(x0)q(x | x0)

p(x)q(x0 | x) =p(x0

i | x0�i)p(x

0�i)p(xi | x0

�i)

p(xi | x�i)p(x�i)p(x0i | x�i)

= 1

Page 46: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Summary

• Markov Chain Monte Carlo is a family of sampling algorithms that can sample from arbitrary distributions by moving in state space

• Most used methods are the Metropolis-Hastings (MH) and the Gibbs sampling method

• MH uses a proposal distribution and accepts a proposed state randomly

• Gibbs sampling does not use a proposal distribution, but samples from the full conditionals

46

Page 47: The Particle Filter - TUM

Computer Vision Group Prof. Daniel Cremers

11. Variational Inference

Page 48: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Motivation

•A major task in probabilistic reasoning is to evaluate the posterior distribution of a

set of latent variables Z given data X (inference)

However: This is often not tractable, e.g. because the latent space is high-dimensional

•Two different solutions are possible: sampling methods and variational methods.

•In variational optimization, we seek a tractable

distribution q that approximates the posterior.

•Optimization is done using functionals.

48

p(Z | X)

Page 49: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Motivation

•A major task in probabilistic reasoning is to evaluate the posterior distribution of a

set of latent variables Z given data X (inference)

•However: This is often not tractable, e.g. because the latent space is high-dimensional

•Two different solutions are possible: sampling methods and variational methods.

•In variational optimization, we seek a tractable

distribution q that approximates the posterior.

•Optimization is done using functionals.

49

p(Z | X)

Careful: Different notation! In Bishop (and in the following slides)

Z are hidden states and X are observations

Page 50: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Variational Inference

In general, variational methods are concerned with mappings that take functions as input.

Example: the entropy of a distribution p

Variational optimization aims at finding functions that minimize (or maximize) a given functional.

This is mainly used to find approximations to a given function by choosing from a family.

The aim is mostly tractability and simplification.

50

H[p] =

Zp(x) log p(x)dx

“Functional”

Page 51: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

The KL-Divergence

Aim: define a functional that resembles a

“difference” between distributions p and q

Idea: use the average additional amount of information:

This is known as the Kullback-Leibler divergence

It has the properties:

This follows from Jensen’s inequality

51

�Z

p(x) log q(x)dx�✓�Z

p(x) log p(x)dx

◆= �

Zp(x) log

q(x)

p(x)dx

KL(qkp) 6= KL(pkq)

= KL(pkq)

KL(pkq) � 0 KL(pkq) = 0 , p ⌘ q

Page 52: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Example: A Variational Formulation of EM

Assume for a moment that we observe X and the

binary latent variables Z. The likelihood is then:

52

p(X,Z | ⇡,µ,⌃) =NY

n=1

p(zn | ⇡)p(xn | zn,µ,⌃)

Page 53: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Remember:

znk 2 {0, 1},KX

k=1

znk = 1

Example: A Variational Formulation of EM

Assume for a moment that we observe X and the

binary latent variables Z. The likelihood is then: where and

53

p(X,Z | ⇡,µ,⌃) =NY

n=1

p(zn | ⇡)p(xn | zn,µ,⌃)

p(zn | ⇡) =KY

k=1

⇡znkk

p(xn | zn,µ,⌃) =KY

k=1

N (xn | µk,⌃k)znk

Page 54: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

Remember:

znk 2 {0, 1},KX

k=1

znk = 1

Example: A Variational Formulation of EM

Assume for a moment that we observe X and the

binary latent variables Z. The likelihood is then: where andwhich leads to the log-formulation:

54

p(X,Z | ⇡,µ,⌃) =NY

n=1

p(zn | ⇡)p(xn | zn,µ,⌃)

p(zn | ⇡) =KY

k=1

⇡znkk

p(xn | zn,µ,⌃) =KY

k=1

N (xn | µk,⌃k)znk

log p(X,Z | ⇡,µ,⌃) =NX

n=1

KX

k=1

znk(log ⇡k + logN (xn | µk,⌃k))

Page 55: The Particle Filter - TUM

PD Dr. Rudolph TriebelComputer Vision Group

Machine Learning for Computer Vision

The Complete-Data Log-Likelihood

• This is called the complete-data log-likelihood

• Advantage: solving for the parameters is much simpler, as the log is inside the sum!

• We could switch the sums and then for every

mixture component k only look at the points that are associated with that component.

• This leads to simple closed-form solutions for the parameters

• However: the latent variables Z are not observed!

55

log p(X,Z | ⇡,µ,⌃) =NX

n=1

KX

k=1

znk(log ⇡k + logN (xn | µk,⌃k))

(⇡k,µk,⌃k)


Recommended