An introduction to particle filters
Andreas Svensson
Department of Information Technology Uppsala University
June 10, 2014
June 10, 2014, 1 / 16 Andreas Svensson - An introduction to particle filters
An introduction to particle filters Andreas Svensson Department of - - PowerPoint PPT Presentation
An introduction to particle filters Andreas Svensson Department of Information Technology Uppsala University June 10, 2014 June 10, 2014, 1 / 16 Andreas Svensson - An introduction to particle filters Outline Motivation and ideas Algorithm
Department of Information Technology Uppsala University
June 10, 2014, 1 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 2 / 16 Andreas Svensson - An introduction to particle filters
t
t
June 10, 2014, 3 / 16 Andreas Svensson - An introduction to particle filters
◮ Linear Gaussian state space model
t
t
June 10, 2014, 3 / 16 Andreas Svensson - An introduction to particle filters
◮ Linear Gaussian state space model
t
t
◮ A more general state space model in different notation
June 10, 2014, 3 / 16 Andreas Svensson - An introduction to particle filters
Kalman filter! ''Exact solution to the right problem''
EKF, UKF, … ''Exact solution to the wrong problem'' Particle filter ''Approximate solution to the right problem''
June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
Kalman filter! ''Exact solution to the right problem''
EKF, UKF, … ''Exact solution to the wrong problem'' Particle filter ''Approximate solution to the right problem''
June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
◮ Kalman filter!
''Exact solution to the right problem''
EKF, UKF, … ''Exact solution to the wrong problem'' Particle filter ''Approximate solution to the right problem''
June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
◮ Kalman filter!
''Exact solution to the right problem''
EKF, UKF, … ''Exact solution to the wrong problem'' Particle filter ''Approximate solution to the right problem''
June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
◮ Kalman filter!
''Exact solution to the right problem''
◮ EKF, UKF, …
''Exact solution to the wrong problem''
◮ Particle filter
''Approximate solution to the right problem''
June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
◮ Kalman filter! ''Exact solution to the right problem''
◮ EKF, UKF, …
''Exact solution to the wrong problem''
◮ Particle filter
''Approximate solution to the right problem''
June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
◮ Kalman filter! ''Exact solution to the right problem''
◮ EKF, UKF, … ''Exact solution to the wrong problem'' ◮ Particle filter
''Approximate solution to the right problem''
June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
◮ Kalman filter! ''Exact solution to the right problem''
◮ EKF, UKF, … ''Exact solution to the wrong problem'' ◮ Particle filter ''Approximate solution to the right problem'' June 10, 2014, 4 / 16 Andreas Svensson - An introduction to particle filters
Time State True state tracejctory
A linear system - Find p(xt|y1:t) (true xt shown)!
June 10, 2014, 5 / 16 Andreas Svensson - An introduction to particle filters
Time State True state tracejctory Kalman filter mean
Kalman filter mean
June 10, 2014, 5 / 16 Andreas Svensson - An introduction to particle filters
Time State True state tracejctory Kalman filter mean Kalman filter covariance
Kalman filter mean and covariance
June 10, 2014, 5 / 16 Andreas Svensson - An introduction to particle filters
Time State True state tracejctory Kalman filter mean Kalman filter covariance
Kalman filter mean and covariance defines a Gaussian distribution at each t
June 10, 2014, 5 / 16 Andreas Svensson - An introduction to particle filters
Time State True state tracejctory
A numerical approximation can be used to describe the distribution - Particle Filter
June 10, 2014, 5 / 16 Andreas Svensson - An introduction to particle filters
Time State True state tracejctory
The Particle Filter can easily handle, e.g., non-gaussian multimodal hypotheses
June 10, 2014, 5 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 6 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
xi
t+1 from f (·|xi t, ut)
for i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights
0 x(:,1) = random(i_dist,N,1); w(:,1) = ones(N,1)/N; for t = 1:T 1 w(:,t) = pdf(m_dist,y(t)-g(x(:,t))); w(:,t) = w(:,t)/sum(w(:,t)); 2 Resample x(:,t) 3 x(:,t+1) = f(x(:,t),u(t)) + random(t_dist,N,1); end
June 10, 2014, 7 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
xi
t+1 from f (·|xi t, ut)
for i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights
0 x(:,1) = random(i_dist,N,1); w(:,1) = ones(N,1)/N; for t = 1:T 1 w(:,t) = pdf(m_dist,y(t)-g(x(:,t))); w(:,t) = w(:,t)/sum(w(:,t)); 2 Resample x(:,t) 3 x(:,t+1) = f(x(:,t),u(t)) + random(t_dist,N,1); end
June 10, 2014, 7 / 16 Andreas Svensson - An introduction to particle filters
→0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T →1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N →2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
→3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T →1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N →2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
→3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T →1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N →2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
→3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T →1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N →2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
→3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T →1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N →2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
→3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights 5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x
June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
0 Initialize xi
1 ∼ p(x1) and
wi = 1
N for i = 1, . . . , N
for t = 1 to T 1 Evaluate wi
t = g(yt|xi t, ut)
for i = 1, . . . , N 2 Resample {xi
t}N i=1 from
{xi
t, wi t}N i=1
3 Propagate xi
t by sampling
from f (·|xi
t−1, ut−1) for
i = 1, . . . , N end N Number of particles, xi
t Particles,
wi
t Particle weights
5 10 15 20 −30 −25 −20 −15 −10 −5 5 10 15 Time State x June 10, 2014, 8 / 16 Andreas Svensson - An introduction to particle filters
v = rand(N,1); wc = cumsum(w(:,t)); [ ,ind1] = sort([v;wc]); ind=find(ind1<=N)-(0:N-1)'; x(:,t)=x(ind,t); w(:,t)=ones(N,1)./N;
June 10, 2014, 9 / 16 Andreas Svensson - An introduction to particle filters
◮ Represent the information contained in the N black dots (of
state
v = rand(N,1); wc = cumsum(w(:,t)); [ ,ind1] = sort([v;wc]); ind=find(ind1<=N)-(0:N-1)'; x(:,t)=x(ind,t); w(:,t)=ones(N,1)./N;
June 10, 2014, 9 / 16 Andreas Svensson - An introduction to particle filters
◮ Represent the information contained in the N black dots (of
state
v = rand(N,1); wc = cumsum(w(:,t)); [ ,ind1] = sort([v;wc]); ind=find(ind1<=N)-(0:N-1)'; x(:,t)=x(ind,t); w(:,t)=ones(N,1)./N;
June 10, 2014, 9 / 16 Andreas Svensson - An introduction to particle filters
◮ Represent the information contained in the N black dots (of
state
◮ Can be seen as sampling from a cathegorical distribution
v = rand(N,1); wc = cumsum(w(:,t)); [ ,ind1] = sort([v;wc]); ind=find(ind1<=N)-(0:N-1)'; x(:,t)=x(ind,t); w(:,t)=ones(N,1)./N;
June 10, 2014, 9 / 16 Andreas Svensson - An introduction to particle filters
◮ Represent the information contained in the N black dots (of
state
◮ Can be seen as sampling from a cathegorical distribution ◮ To avoid particle depletion (''a lot of 0-weights particles'')
v = rand(N,1); wc = cumsum(w(:,t)); [ ,ind1] = sort([v;wc]); ind=find(ind1<=N)-(0:N-1)'; x(:,t)=x(ind,t); w(:,t)=ones(N,1)./N;
June 10, 2014, 9 / 16 Andreas Svensson - An introduction to particle filters
◮ Represent the information contained in the N black dots (of
state
◮ Can be seen as sampling from a cathegorical distribution ◮ To avoid particle depletion (''a lot of 0-weights particles'') ◮ Some Matlab code:
v = rand(N,1); wc = cumsum(w(:,t)); [ ,ind1] = sort([v;wc]); ind=find(ind1<=N)-(0:N-1)'; x(:,t)=x(ind,t); w(:,t)=ones(N,1)./N;
June 10, 2014, 9 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 10 / 16 Andreas Svensson - An introduction to particle filters
◮ Crucial step in the development in the 90's for making particle
June 10, 2014, 10 / 16 Andreas Svensson - An introduction to particle filters
◮ Crucial step in the development in the 90's for making particle
◮ Many different techniques exists with different properties and
June 10, 2014, 10 / 16 Andreas Svensson - An introduction to particle filters
◮ Crucial step in the development in the 90's for making particle
◮ Many different techniques exists with different properties and
◮ Computationally heavy. Not necessary to do in every iteration -
June 10, 2014, 10 / 16 Andreas Svensson - An introduction to particle filters
◮ Crucial step in the development in the 90's for making particle
◮ Many different techniques exists with different properties and
◮ Computationally heavy. Not necessary to do in every iteration -
◮ It is sometimes preferred to use the logarithms of the weights
June 10, 2014, 10 / 16 Andreas Svensson - An introduction to particle filters
Resampling step Likelihood evaluation (for the weight evaluation) Sampling from f for the propagation (trick: use proposal distributions!)
June 10, 2014, 11 / 16 Andreas Svensson - An introduction to particle filters
x)
Resampling step Likelihood evaluation (for the weight evaluation) Sampling from f for the propagation (trick: use proposal distributions!)
June 10, 2014, 11 / 16 Andreas Svensson - An introduction to particle filters
x)
x))
Resampling step Likelihood evaluation (for the weight evaluation) Sampling from f for the propagation (trick: use proposal distributions!)
June 10, 2014, 11 / 16 Andreas Svensson - An introduction to particle filters
x)
x))
◮ Resampling step ◮ Likelihood evaluation (for the weight evaluation) ◮ Sampling from f for the propagation (trick: use proposal
distributions!)
June 10, 2014, 11 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 12 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 12 / 16 Andreas Svensson - An introduction to particle filters
◮ Python: pyParticleEst ◮ Matlab: PFToolbox, PFLib ◮ C++: Particle++
June 10, 2014, 12 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 13 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 13 / 16 Andreas Svensson - An introduction to particle filters
June 10, 2014, 13 / 16 Andreas Svensson - An introduction to particle filters
pt g xt
sup
N
C N
June 10, 2014, 14 / 16 Andreas Svensson - An introduction to particle filters
pt g xt
sup
N
C N
June 10, 2014, 14 / 16 Andreas Svensson - An introduction to particle filters
pt g xt
sup
N
C N
June 10, 2014, 14 / 16 Andreas Svensson - An introduction to particle filters
N
C N
June 10, 2014, 14 / 16 Andreas Svensson - An introduction to particle filters
N
N
June 10, 2014, 14 / 16 Andreas Svensson - An introduction to particle filters
T (marginal smoothing) or
t y T (joint smoothing) instead of p xt y t (filtering).
T has to be available). Increased computational load.
June 10, 2014, 15 / 16 Andreas Svensson - An introduction to particle filters
◮ Smoothing: Finding p(xt|y1:T) (marginal smoothing) or
June 10, 2014, 15 / 16 Andreas Svensson - An introduction to particle filters
◮ Smoothing: Finding p(xt|y1:T) (marginal smoothing) or
◮ If f (xt+1|xt, ut) is not suitable to sample from, proposal
June 10, 2014, 15 / 16 Andreas Svensson - An introduction to particle filters
◮ Smoothing: Finding p(xt|y1:T) (marginal smoothing) or
◮ If f (xt+1|xt, ut) is not suitable to sample from, proposal
◮ Rao-Blackwellization for mixed linear/nonlinear models.
June 10, 2014, 15 / 16 Andreas Svensson - An introduction to particle filters
◮ Smoothing: Finding p(xt|y1:T) (marginal smoothing) or
◮ If f (xt+1|xt, ut) is not suitable to sample from, proposal
◮ Rao-Blackwellization for mixed linear/nonlinear models. ◮ System identification: PMCMC, SMC2.
June 10, 2014, 15 / 16 Andreas Svensson - An introduction to particle filters
◮ Gustafsson, F. (2010). Particle filter theory and practice with
positioning applications. Aerospace and Electronic Systems Magazine, IEEE, 25(7), 53-82.
◮ Schön, T.B., & Lindsten, F. Learning of dynamical systems - Particle
Filters and Markov chain methods. Draft available.
◮ Doucet, A., & Johansen, A. M. (2009). A tutorial on particle filtering and
smoothing: Fifteen years later. Handbook of Nonlinear Filtering, 12, 656-704. Homework: Implement your own Particle Filter for any (simple) problem of your choice!
June 10, 2014, 16 / 16 Andreas Svensson - An introduction to particle filters