Resampler
Particle
- class stonesoup.resampler.particle.SystematicResampler[source]
Bases:
Resampler
Traditional style resampler for particle filter. Calculates first random point in (0, 1/nparts], then calculates nparts points that are equidistantly distributed across the CDF. Complexity of order O(N) where N is the number of resampled particles.
- resample(particles, nparts=None)[source]
Resample the particles
- Parameters:
particles (
ParticleState
or list ofParticle
) – The particles or particle state to be resampled according to their weightsnparts (int) – The number of particles to be returned from resampling
- Returns:
particle state – The particle state after resampling
- Return type:
- class stonesoup.resampler.particle.ESSResampler(threshold: float = None, resampler: Resampler = SystematicResampler())[source]
Bases:
Resampler
This wrapper uses a
Resampler
to resample the particles inside an instance ofParticles
, but only after checking if this is necessary by comparing the Effective Sample Size (ESS) with a supplied threshold (numeric). Kish’s ESS is used, as recommended in Section 3.5 of this tutorial [1].References
- Parameters:
threshold (
float
, optional) – Threshold compared with ESS to decide whether to resample. Default is number of particles divided by 2, set in resample methodresampler (
Resampler
, optional) – Resampler to wrap, which is called when ESS below threshold
- threshold: float
Threshold compared with ESS to decide whether to resample. Default is number of particles divided by 2, set in resample method
- resample(particles, nparts=None)[source]
- Parameters:
particles (
ParticleState
or list ofParticle
) – The particles to be resampled according to their weightnparts (int) – The number of particles to be returned from resampling
- Returns:
particles – The particles, either unchanged or resampled, depending on weight degeneracy
- Return type:
- class stonesoup.resampler.particle.MultinomialResampler[source]
Bases:
Resampler
Traditional style resampler for particle filter. Calculates a random point in (0, 1] individually for each particle, and picks the corresponding particle from the CDF calculated from particle weights. Complexity is of order O(NM) where N and M are the number of resampled and existing particles respectively.
- resample(particles, nparts=None)[source]
Resample the particles
- Parameters:
particles (
ParticleState
or list ofParticle
) – The particles or particle state to be resampled according to their weightsnparts (int) – The number of particles to be returned from resampling
- Returns:
particle state – The particle state after resampling
- Return type:
- class stonesoup.resampler.particle.StratifiedResampler[source]
Bases:
Resampler
Traditional style resampler for particle filter. Splits the CDF into N evenly sized subpopulations (‘strata’), then independently picks one value from each stratum. Complexity of order O(N).
- resample(particles, nparts=None)[source]
Resample the particles
- Parameters:
particles (
ParticleState
or list ofParticle
) – The particles or particle state to be resampled according to their weightsnparts (int) – The number of particles to be returned from resampling
- Returns:
particle state – The particle state after resampling
- Return type:
- class stonesoup.resampler.particle.ResidualMethod(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
Enum
- class stonesoup.resampler.particle.ResidualResampler(residual_method: ResidualMethod = ResidualMethod.MULTINOMIAL)[source]
Bases:
Resampler
Wrapper around a traditional resampler. Any particle, p with weight W >= 1/N, will be resampled floor(W_p) times, providing N_stage_1 = sum(floor(W_p)) resampled particles.
The residual weights of each particle are carried over and passed into another resampler, where the remaining N - N_stage_1 particles are resampled from.
Should be a more computationally efficient method than resampling all particles from a CDF. Cannot be used to upsample or downsample.
- Parameters:
residual_method (
ResidualMethod
, optional) – Method used to resample particles from the residuals.
- residual_method: ResidualMethod
Method used to resample particles from the residuals.
- resample(particles, nparts=None)[source]
Resample the particles. For ResidualResampler, nparts must equal len(particles)
- Parameters:
particles (
ParticleState
or list ofParticle
) – The particles or particle state to be resampled according to their weightsnparts (int) – The number of particles to be returned from resampling - must equal number of particles from previous step
- Returns:
particle state – The particle state after resampling
- Return type: