pypfda.resampling¶
Particle resampling schemes.
Each scheme takes a vector of normalized weights and a random generator
and returns an integer index array of the same length whose values are
in [0, n_members). The expected number of times particle \(i\)
is selected equals \(N w_i\). Variance differs across schemes;
systematic resampling has the lowest variance and is the recommended
default for most applications.
References
Douc, R., Cappé, O. & Moulines, E. (2005). Comparison of resampling schemes for particle filtering. ISPA 2005.
Functions
|
Plain multinomial resampling. |
|
Dispatch by name to one of the resampling routines. |
|
Residual resampling. |
|
Stratified resampling. |
|
Systematic resampling. |
- pypfda.resampling.systematic(weights, rng=None)[source]¶
Systematic resampling.
Draws a single uniform random offset and walks through the inverse cumulative distribution function with deterministic, evenly-spaced strides. Lowest variance among standard schemes; preserves the expected count exactly when weights are rationals with a common denominator that divides
N.- Parameters:
weights (array_like, shape (n_members,)) – Normalized weights.
rng (numpy.random.Generator, optional) – Random number generator. If
None,np.random.default_rng()is used.
- Returns:
indices – Indices into the input weight vector.
- Return type:
ndarray of int, shape (n_members,)
- pypfda.resampling.stratified(weights, rng=None)[source]¶
Stratified resampling.
Like
systematic()but draws an independent uniform offset inside each of theNequal-width strata. Slightly higher variance than systematic, but eliminates the (theoretical) failure mode where systematic resampling can be sensitive to particle ordering.
- pypfda.resampling.residual(weights, rng=None)[source]¶
Residual resampling.
Allocates
floor(N * w_i)deterministic copies of each particle and resamples the remainder multinomially with normalized residual weights. Often the lowest variance for small ensembles where many weights are close to the uniform value.
- pypfda.resampling.multinomial(weights, rng=None)[source]¶
Plain multinomial resampling.
Draws
Nindependent samples from the categorical distribution defined by the weights. Highest variance of the standard schemes; included mainly as a baseline.
- pypfda.resampling.resample(weights, method='systematic', rng=None)[source]¶
Dispatch by name to one of the resampling routines.
- Parameters:
weights (array_like, shape (n_members,)) – Normalized weights.
method ({'systematic', 'stratified', 'residual', 'multinomial'}, default 'systematic') – Resampling scheme.
rng (numpy.random.Generator, optional) – Random generator.
- Returns:
indices
- Return type:
ndarray of int, shape (n_members,)