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

Introduce resampler that checks if resampling required #563

Merged
merged 2 commits into from
Dec 16, 2021
Merged

Conversation

orosoman-dstl
Copy link
Contributor

This change is in response to #495
The new ESSResampler class checks whether the ESS (Effective Sample Size) is below a given threshold before proceeding, otherwise simply returning the original particles without any resampling.

@orosoman-dstl orosoman-dstl requested a review from a team as a code owner December 13, 2021 14:48
@orosoman-dstl orosoman-dstl requested review from sdhiscocks and svidal-dstl and removed request for a team December 13, 2021 14:48
@codecov
Copy link

codecov bot commented Dec 13, 2021

Codecov Report

Merging #563 (aaa2c92) into main (346c7fb) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #563   +/-   ##
=======================================
  Coverage   94.24%   94.25%           
=======================================
  Files         144      144           
  Lines        7121     7133   +12     
  Branches     1341     1345    +4     
=======================================
+ Hits         6711     6723   +12     
  Misses        310      310           
  Partials      100      100           
Flag Coverage Δ
integration 68.38% <46.15%> (-0.05%) ⬇️
unittests 91.54% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
stonesoup/resampler/particle.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 346c7fb...aaa2c92. Read the comment docs.

Comment on lines 52 to 53
class ESSResampler(SystematicResampler):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could do with a docstring, to explain a little about what it does, and any references you've used.

parent=Particles(state_vector=particles.state_vector[:, index],
weight=particles.weight[index]))
return new_particles


class ESSResampler(SystematicResampler):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this class could be a wrapper that could be used with other resamplers.

class ESSResampler(Resampler):
    resampler: Resampler = Property(doc="Resampler to wrap, which is called when ESS below threshold")
    ...

class ESSResampler(SystematicResampler):

threshold: float = Property(default=None,
doc='Threshold compared with ESS to decide whether to resample')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add to doc that default of None means threshold is number of particles / 2.

@sdhiscocks sdhiscocks merged commit ba84d4e into main Dec 16, 2021
@sdhiscocks sdhiscocks deleted the ESSResampler branch December 16, 2021 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants