pypfilt.resample

pypfilt.resample.resample(ctx, px, net_weight=1.0, part_ix=0, ix_offset=0, res_px=None, res_frac=0.0, res_offset=0)

Resample a particle population.

Parameters:
  • ctx – The simulation context.

  • px – An array of particle state vectors.

  • net_weight – The total weight to allocate across the particles. Note that this includes the reservoir particles (if any).

  • part_ix – The index of the partition to which the particles belong.

  • ix_offset – The index in the history matrix at which the particles in px begin.

  • res_px – An optional array of reservoir particles.

  • res_frac – The fraction of particles that should be selected from the reservoir particles.

  • res_offset – The index in the history matrix at which the particles in res_px begin.

Important

This function does not return a value, it destructively updates the px state vector array.

The supported resampling methods are:

  • 'basic': uniform random numbers from [0, 1].

  • 'stratified': uniform random numbers from [j / m, (j + 1) / m).

  • 'deterministic': select (j + a) / m for some fixed a in [0, 1].

Where m is the number of particles and j = 0, …, m - 1.

These algorithms are described in G Kitagawa, J Comp Graph Stat 5(1):1-25, 1996. doi:10.2307/1390750

When reservoir particles are provided, the following steps are performed:

  1. Sample C candidates from the N particles in px;

  2. Apply post-regularisation, if enabled, to these C candidates; and

  3. Sample R candidates from res_px.

In this case, px contains N = C + R particles and R is equal to res_frac * N (rounded to the nearest integer). Note that post-regularisation, if enabled, is not applied to the reservoir particles.

pypfilt.resample.resample_weights(weights, rnd, method='deterministic', count=None)

Resample a particle weight array.

Parameters:
  • weights (np.ndarray) – The particle weights.

  • rnd – A random number generator.

  • method – The resampling method: 'basic', 'stratified', or 'deterministic' (default).

  • count – The number of particles to select (default: the length of the weights array).

Returns:

A (sample_ixs, weight) tuple, where sample_ixs are the indices of the resampled particles and weight is the new weight for each particle (a single float).

pypfilt.resample.resample_ixs(weights, rnd, method, count=None)

Resample a particle weight array.

Parameters:
  • weights (np.ndarray) – The particle weights.

  • rnd – A random number generator.

  • method – The resampling method: 'basic', 'stratified', or 'deterministic' (default).

  • count – The number of particles to select (default: the length of the weights array).

Returns:

An array that contains the index of each resampled particle.

pypfilt.resample.post_regularise(ctx, px, new_px)

Sample model parameter values from a continuous approximation of the optimal filter, assuming that it has a smooth density.

This is the post-regularised particle filter (post-RPF). For details, see chapter 12 of Doucet et al., Sequential Monte Carlo Methods in Practice, Springer, 2001. doi:10.1007/978-1-4757-3437-9_12

Parameters:
  • ctx – The simulation context.

  • px – The particles, prior to resampling.

  • new_px – The particles after resampling directly from the discrete distribution (px). This matrix will be destructively updated with model parameter values samples from the regularisation kernel.