Beliefs

Types

ParticleFilters.jl provides two types of particle beliefs. ParticleCollection is little more than a vector of unweighted particles. WeightedParticleBelief allows for different weights for each of the particles.

Both are subtypes of AbstractParticleBelief and implement the same particle belief interface. For probability mass calculations (the pdf function), a dictionary containing the normalized sum of weights for all identical particles is created on the first call and cached for efficient future querying.

Warning

You should not access the fields of ParticleCollection or WeightedParticleBelief directly. Use the provided interface instead to ensure that internal data structures are maintained correctly.

Interface

Standard POMDPs.jl Distribution Interface

The following functions from the POMDPs.jl distributions interface (a subset of the Distributions.jl interface) provide basic ways of interacting with particle beliefs as distributions (click on each for documentation):

Particle Interface

These functions provide read only access to the particles, weights, and other aspects of the beliefs (click on each for docstrings):

To change the particles or weights in a belief, the following functions are provided:

Interface Docstrings

Base.randFunction
rand(rng::AbstractRNG, d::Any)

Return a random element from distribution or space d.

If d is a state or transition distribution, the sample will be a state; if d is an action distribution, the sample will be an action or if d is an observation distribution, the sample will be an observation.

source
Distributions.pdfFunction
pdf(d::Any, x::Any)

Evaluate the probability density of distribution d at sample x.

source
Distributions.supportFunction
support(d::Any)

Return an iterable object containing the possible values that can be sampled from distribution d. Values with zero probability may be skipped.

source
ParticleFilters.probdictFunction
probdict(b::AbstractParticleBelief)

Return a dictionary mapping states to probabilities.

The probability is the normalized sum of the weights for all matching particles.

For ParticleCollection and WeightedParticleBelief, the result is cached for efficiency so the calculation is only performed the first time this is called. There is a default implementation for all AbstractParticleBeliefs, but it is inefficient (it creates a new dictionary every time). New AbstractParticleBelief implementations should provide an efficient implementation.

source
ParticleFilters.effective_sample_sizeFunction
effective_sample_size(b::AbstractParticleBelief)

Calculate the effective sample size of a particle belief.

The effective sample size is $1/\sum_i \hat{w}_i^2$ where $\hat{w}_i = w_i / \sum_i w_i$.

source
ParticleFilters.set_particle!Function
set_particle!(b::AbstractParticleBelief, i, s)

Change the particle at index i without changing the weight.

This may not work for beliefs with immutable particle storage.

Example

set_particle!(b, 3, s)
source
ParticleFilters.set_pair!Function
set_pair!(b::AbstractParticleBelief{S}, i, sw::Pair{S,Float64})

Change both the particle and weight at index i. This will also adjust the weight sum and probabilities appropriately.

Example

set_pair!(b, 3, s=>0.5)
source
ParticleFilters.push_pair!Function
push_pair!(b::AbstractParticleBelief{S}, sw::Pair{S,Float64})

Push a new particle and weight pair onto the end of the belief. This will also adjust the weight sum and probabilities appropriately.

Example

push_pair!(b, s=>0.5)
source