Skip to content

epymorph.parameter_fitting.utils.resampler

WeightsResampling

WeightsResampling(N: int, likelihood_fn)

A class for computing and resampling weights in particle filtering.

Attributes:

  • N (int) –

    Number of particles.

  • static_params (dict) –

    Static parameters from the rume dictionary.

  • likelihood_fn (object) –

    An object responsible for computing the likelihood of observations.

Parameters:

  • N (int) –

    Number of particles.

  • likelihood_fn (object) –

    An object for computing the likelihood of observations.

N instance-attribute

N = N

likelihood_fn instance-attribute

likelihood_fn = likelihood_fn

compute_weights

compute_weights(
    current_obs_data: ndarray, expected_observations: list
) -> ndarray

Computes the weights for each particle based on the likelihood of the current observation.

Parameters:

  • current_obs_data (ndarray) –

    The current observation data.

  • expected_observations (list) –

    The expected observations corresponding to each particle.

Returns:

  • ndarray

    An array of computed weights normalized to sum to 1.

resample_particles

resample_particles(
    particles: list, weights: ndarray, rng: Generator
) -> list

Resamples particles based on the computed weights.

Parameters:

  • particles (list) –

    Particles which represent the estimated state of the system.

  • weights (ndarray) –

    Wights corresponding to each particle.

Returns:

  • list

    The resampled particles.

update_weights

update_weights(
    weights: ndarray, new_weights: ndarray
) -> list

Updates the weights by multiplying current weights with new weights.

Parameters:

  • weights (ndarray) –

    The current weights of the particles.

  • new_weights (ndarray) –

    The new weights to be multiplied with the current weights.

Returns:

  • list

    The updated weights.

ResamplingByNode

ResamplingByNode(N: int, likelihood_fn)

Bases: WeightsResampling

Uses an approximate resampling algorithm which is efficient for multi-node systems. The weights for each node are computed separately. During resampling the particles are decomposed by node, each node is resampled separately, and new particles are reconstructed treating nodes independently.

Attributes:

  • N (int) –

    Number of particles.

  • static_params (dict) –

    Static parameters from the rume dictionary.

  • likelihood_fn (object) –

    An object responsible for computing the likelihood of observations.

compute_weights

compute_weights(
    current_obs_data: ndarray, expected_observations: list
) -> ndarray

Computes the weights for each node for each particle based on the likelihood of the current observation.

Parameters:

  • current_obs_data (ndarray) –

    The current observation data.

  • expected_observations (list) –

    The expected observations corresponding to each particle.

Returns:

  • ndarray

    An array of computed weights with each row normalized to sum to 1.

resample_particles

resample_particles(
    particles: list[Particle],
    weights: ndarray,
    rng: Generator,
) -> list

Resamples particles using an approximate algorithm based on the computed weights. The particles are deconstructed by node, each node is resampled independently, then new particles are reconstructed.

Parameters:

  • particles (list) –

    Particles which represent the estimated state of the system.

  • weights (ndarray) –

    Wights corresponding to each node for each particle.

Returns:

  • list

    The resampled particles.