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_dist, n_particles=None, precomputed_mean=None, precomputed_cov=None)[source]

Resample the particles given by particle_weights and particle_locations, drawing n_particles new particles.

Parameters: Return ParticleDistribution: model (Model) – Model from which the particles are drawn, used to define the valid region for resampling. paricle_dist (ParticleDistribution) – The particle distribution to be resampled. 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. Resampled particle distribution

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=1e-10, default_n_particles=None, kernel=<built-in 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. default_n_particles (int) – The default number of particles to draw during a resampling action. If None, the number of redrawn particles redrawn will be equal to the number of particles given. The value of default_n_particles can be overridden by any integer value of n_particles given to __call__.

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
__call__(model, particle_dist, n_particles=None, precomputed_mean=None, precomputed_cov=None)[source]

Resample the particles according to algorithm given in [LW01].