Basic Particle Filter
Update Steps
The basic particle filtering step in ParticleFilters.jl is implemented in the update
function, and consists of three steps:
- Prediction (or propagation) - each state particle is simulated forward one step in time
- Reweighting - an explicit measurement (observation) model is used to calculate a new weight
- Resampling - a new collection of state particles is generated with particle frequencies proportional to the new weights
This is an example of sequential importance resampling using the state transition distribution as the proposal distribution, and the BootstrapFilter
constructor can be used to construct such a filter with a model
that controls the prediction and reweighting steps, and a number of particles to create in the resampling phase.
A more flexible structure for building a particle filter is the BasicParticleFilter
. It contains three models, one for each step:
- The
predict_model
controls prediction throughpredict!
- The
reweight_model
controls reweighting throughreweight!
- The
resampler
controls resampling throughresample
ParticleFilters.jl contains implementations of these components that can be mixed and matched. In many cases the prediction and reweighting steps use the same model, for example a ParticleFilterModel
or a POMDP
.
To carry out the steps individually without the need for pre-allocating memory or doing a full update
step, the predict
, reweight
, and resample
functions are provided.
Docstrings
ParticleFilters.BootstrapFilter
— FunctionBootstrapFilter(model, n, [rng])
Construct a standard bootstrap particle filter.
The Bootstrap filter was first described in Gordon, N. J., Salmond, D. J., & Smith, A. F. M. "Novel approach to nonlinear / non-Gaussian Bayesian state estimation", with the added robustness of the LowVarianceResampler.
Arguments
model
: a model for the prediction dynamics and likelihood reweighing, for example aPOMDP
orParticleFilterModel
n::Integer
: number of particlesrng::AbstractRNG
: random number generator
For a more flexible particle filter structure see BasicParticleFilter
.
ParticleFilters.BasicParticleFilter
— TypeBasicParticleFilter(predict_model, reweight_model, resampler, n_init::Integer, rng::AbstractRNG)
BasicParticleFilter(model, resampler, n_init::Integer, rng::AbstractRNG)
Construct a basic particle filter with three steps: predict, reweight, and resample.
In the second constructor, model
is used for both the prediction and reweighting.
POMDPs.update
— Functionupdate(updater::Updater, belief_old, action, observation)
Return a new instance of an updated belief given belief_old
and the latest action and observation.
ParticleFilters.predict!
— Functionpredict!(pm, m, b, u, rng)
predict!(pm, m, b, u, y, rng)
Fill pm
with predicted particles for the next time step.
A method of this function should be implemented by prediction models to be used in a BasicParticleFilter
. pm
should be a correctly-sized vector created by particle_memory
to hold a one-step-propagated particle for each particle in b
.
Normally the observation y
is not needed, so most prediction models should implement the first version, but the second is available for heuristics that use y
.
Arguments
pm::Vector
: memory for holding the propagated particles; created byparticle_memory
and resized ton_particles(b)
.m
: prediction model, the "owner" of this functionb::ParticleCollection
: current belief; each particle in this belief should be propagated one step and inserted intopm
.u
: control or actionrng::AbstractRNG
: random number generator; should be used for any randomness in propagation for reproducibility.y
: measuerement/observation (usually not needed)
ParticleFilters.reweight!
— Functionreweight!(wm, m, b, a, pm, y)
reweight!(wm, m, b, a, pm, y, rng)
Fill wm
likelihood weights for each particle in pm
.
A method of this function should be implemented by reweighting models to be used in a BasicParticleFilter
. wm
should be a correctly-sized vector to hold weights for each particle in pm.
Normally rng
is not needed, so most reweighting models should implement the first version, but the second is available for heuristics that use random numbers.
Arguments
wm::Vector{Float64}
: memory for holding likelihood weights.m
: reweighting model, the "owner" of this functionb::ParticleCollection
: previous belief;pm
should contain a propagated particle for each particle in this beliefu
: control or actionpm::Vector
: memory for holding current particles; these particle have been propagated bypredict!
.y
: measurement/observationrng::AbstractRNG
: random number generator; should be used for any randomness for reproducibility.
ParticleFilters.resample
— Functionresample(resampler, bp::AbstractParticleBelief, rng::AbstractRNG)
Sample a new ParticleCollection from bp
.
Generic domain-independent resamplers should implement this version.
resample(resampler, bp::WeightedParticleBelief, predict_model, reweight_model, b, a, o, rng)
Sample a new particle collection from bp with additional information from the arguments to the update function.
This version defaults to resample(resampler, bp, rng)
. Domain-specific resamplers that wish to add noise to particles, etc. should implement this version.
ParticleFilters.predict
— Functionpredict(m, b, u, rng)
Simulate each of the particles in b
forward one time step using model m
and contol input u
returning a vector of states. Calls predict!
internally - see that function for documentation.
This function is provided for convenience only. New models should implement predict!
.
ParticleFilters.reweight
— Functionreweight(m, b, u, pm, y)
Return a vector of likelihood weights for each particle in pm
given observation y
.
pm
can be generated with predict(m, b, u, rng)
.
This function is provided for convenience only - new reweighting models should implement reweight!
.
ParticleFilters.particle_memory
— Functionparticle_memory(m)
Return a suitable container for particles produced by prediction model m
.
This should usually be an empty Vector{S}
where S
is the type of the state for prediction model m
. Size does not matter because resize!
will be called appropriately within update
.