Resampling Algorithms¶
Introduction¶
In order to restore numerical stability to the sequential Monte Carlo algorithm as the effective sample size is reduced, resampling is used to adaptively move particles so as to better represent the posterior distribution. QInfer allows for such algorithms to be specified in a modular way.
Resampler
 Abstract base class for resampling algorithms¶
Class Reference¶

class
qinfer.
Resampler
[source]¶ Bases:
object

__call__
(model, particle_weights, particle_locations, n_particles=None, precomputed_mean=None, precomputed_cov=None)[source]¶ Resample the particles given by
particle_weights
andparticle_locations
, drawingn_particles
new particles.Parameters:  model (Model) – Model from which the particles are drawn, used to define the valid region for resampling.
 particle_weights (np.ndarray) – Weights of each particle,
represented as an array of shape
(n_original_particles, )
and dtypefloat
.  particle_locations (np.ndarray) – Locations of each particle,
represented as an array of shape
(n_original_particles, model.n_modelparams)
and dtypefloat
.  n_particles (int) – Number of new particles to draw, or
None
to draw the same number as the original distribution.  precomputed_mean (np.ndarray) – Mean of the original
distribution, or
None
if this should be computed by the resampler.  precomputed_cov (np.ndarray) – Covariance of the original
distribution, or
None
if this should be computed by the resampler.
Return np.ndarray new_weights: Weights of each new particle.
Return np.ndarray new_locations: Locations of each new particle.

LiuWestResampler
 Liu and West (2000) resampling algorithm¶
Class Reference¶

class
qinfer.
LiuWestResampler
(a=0.98, h=None, maxiter=1000, debug=False, postselect=True, zero_cov_comp=1e10, kernel=<builtin method randn of mtrand.RandomState object>)[source]¶ Bases:
qinfer.resamplers.Resampler
Creates a resampler instance that applies the algorithm of [LW01] to redistribute the particles.
Parameters:  a (float) – Value of the parameter \(a\) of the [LW01] algorithm to use in resampling.
 h (float) – Value of the parameter \(h\) to use, or
None
to use that corresponding to \(a\).  maxiter (int) – Maximum number of times to attempt to resample within the space of valid models before giving up.
 debug (bool) – Because the resampler can generate large amounts of debug information, nothing is output to the logger, even at DEBUG level, unless this flag is True.
 postselect (bool) – If
True
, ensures that models are valid by postselecting.  zero_cov_comp (float) – Amount of covariance to be added to every parameter during resampling in the case that the estimated covariance has zero norm.
 kernel (callable) – Callable function
kernel(*shape)
that returns samples from a resampling distribution with mean 0 and variance 1.
Warning
The [LW01] algorithm preserves the first two moments of the distribution (in expectation over the random choices made by the resampler) if and only if \(a^2 + h^2 = 1\), as is set by the
h=None
keyword argument.
a
¶