ParticleFilter

class probnum.filtsmooth.ParticleFilter(dynamics_model, measurement_model, initrv, num_particles, linearized_measurement_model=None, with_resampling=True, resampling_percentage_threshold=0.1)[source]

Bases: probnum.filtsmooth.bayesfiltsmooth.BayesFiltSmooth

Particle filter (PF). Also known as sequential Monte Carlo method.

A PF estimates the posterior distribution of a Markov process given noisy, non-linear observations, with a set of particles.

The random state of the particle filter is inferred from the random state of the initial random variable.

Parameters
  • dynamics_model (Union[LTISDE, DiscreteGaussian]) – Prior dynamics. Since the PF is essentially a discrete-time algorithm, the prior must be a discrete model (or at least one with an equivalent discretisation). This transition must support forward_realization.

  • measurement_model (DiscreteGaussian) – Measurement model. Must be a discrete model that supports forward_realization.

  • initrv (RandomVariable) – Initial random variable. Can be any RandomVariable object that implements sample().

  • num_particles (Integral) – Number of particles to use.

  • linearized_measurement_model (Optional[DiscreteGaussian]) – Linearized measurement model that is used as an importance density. In principle, any discrete-time model that supports backward_realization is applicable. In practice, it will almost always be one out of DiscreteEKFComponent, DiscreteUKFComponent, or IteratedDiscreteComponent. Linear components are also possible, but would most often imply that a particle filter is not required, because the filtering problem can be used much faster with a Kalman filter. The exception to this rule is if the initial random variable is not Gaussian. Optional. Default is None, which implies the bootstrap PF.

  • with_resampling (bool) – Whether after each step the effective number of particles shall be checked, and, if too low, the state should be resampled. Optional. Default is True.

  • resampling_percentage_threshold (Real) – Percentage threshold for resampling. That is, it is the value \(p\) such that resampling is performed if \(N_{\text{eff}} < p \, N_\text{particles}\) holds. Optional. Default is 0.1. If this value is non-positive, resampling is never performed. If it is larger than 1, resampling is performed after each step.

Attributes Summary

random_state

Random state of the particle filter.

Methods Summary

compute_new_particle(data, stop, dynamics_rv)

Compute a new particle.

dynamics_to_proposal_rv(dynamics_rv, data, t)

Turn a dynamics RV into a proposal RV.

filter(dataset, times)

Apply Particle filtering to a data set.

filter_step(start, stop, randvar, data)

Perform a particle filter step.

smooth(filter_posterior[, _previous_posterior])

Smoothing.

Attributes Documentation

random_state

Random state of the particle filter.

Inferred from the random state of the initial random variable.

Methods Documentation

compute_new_particle(data, stop, dynamics_rv)[source]

Compute a new particle.

Turn the dynamics RV into a proposal RV, apply the measurement model and compute new weights via the respective PDFs.

dynamics_to_proposal_rv(dynamics_rv, data, t)[source]

Turn a dynamics RV into a proposal RV.

The output of this function depends on the choice of PF. For the bootstrap PF, nothing happens. For other PFs, the importance density is used to improve the proposal. Currently, only approximate Gaussian importance densities are provided.

filter(dataset, times)[source]

Apply Particle filtering to a data set.

Parameters
  • dataset (array_like, shape (N, M)) – Data set that is filtered.

  • times (array_like, shape (N,)) – Temporal locations of the data points. The zeroth element in times and dataset is the location of the initial random variable.

Returns

Posterior distribution of the filtered output.

Return type

ParticleFilterPosterior

filter_step(start, stop, randvar, data)[source]

Perform a particle filter step.

This method implements sequential importance (re)sampling.

It consists of the following steps: 1. Propagating the “past” particles through the dynamics model. 2. Computing a “proposal” random variable. This is either the prior dynamics model or the output of a filter step of an (approximate) Gaussian filter. 3. Sample from the proposal random variable. This is the “new” particle. 4. Propagate the particle through the measurement model. This is required in order to evaluate the PDF of the resulting RV at the data. If this is small, the weight of the particle will be small. 5. Compute weights (“event probabilities”) of the new particle. This requires evaluating the PDFs of all three RVs (dynamics, proposal, measurement).

After this is done for all particles, the weights are normalized in order to sum to 1. If the effective number of particles is low, the particles are resampled.

smooth(filter_posterior, _previous_posterior=None)

Smoothing.

Return type

TimeSeriesPosterior