Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESS Resampler to particle filter tutorial #747

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions docs/tutorials/04_ParticleFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,26 @@
# many resampling schemes, and almost as many choices as to when to undertake resampling. The
# systematic resampler is described in [#]_, and in what follows below resampling is undertaken
# at each time-step.

# %%
# Use of Effective Sample Size resampler (ESS)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Resampling removes particles with a low weight and duplicates particles with a high weight.
# A side-effect of this is that additional variance is added. Use of `~.SystematicResampler`
# at each time-step means that additional variance is being introduced when it may not necessarily
# be required. To reduce the additional variance, it may be optimal to resample less frequently.
#
# The Effective Sample Size resampler (`~.ESSResampler`) compares the variance of the unnormalised weights
# of the particles to a pre-specified threshold, and only resamples when the variance is greater than this threshold.
# This threshold is often calculated by the ESS criterion (at time n) given by:
#
# .. math::
# ESS = \left(\sum_{i=1}^{N} (W_{n}^i)^2\right)^{-1}

from stonesoup.predictor.particle import ParticlePredictor
predictor = ParticlePredictor(transition_model)
from stonesoup.resampler.particle import SystematicResampler
resampler = SystematicResampler()
from stonesoup.resampler.particle import ESSResampler
resampler = ESSResampler()
from stonesoup.updater.particle import ParticleUpdater
updater = ParticleUpdater(measurement_model, resampler)

Expand Down