You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/calibrationtools/particle_updater.py
+113-3Lines changed: 113 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,44 @@
6
6
from .perturbation_kernelimportPerturbationKernel
7
7
from .prior_distributionimportPriorDistribution
8
8
from .spawn_rngimportspawn_rng
9
-
from .variance_adapterimportVarianceAdapter
9
+
from .variance_adapterimportAdaptIdentityVariance, VarianceAdapter
10
10
11
11
12
12
class_ParticleUpdater:
13
+
"""
14
+
A class responsible for managing and updating a population of particles
15
+
in an ABC-SMC framework. It provides functionality for sampling,
16
+
perturbing, and calculating weights for proposed particles, as well as
17
+
adapting the variance of the perturbation kernel.
18
+
19
+
Attributes:
20
+
perturbation_kernel (PerturbationKernel): The kernel used to perturb particles.
21
+
priors (PriorDistribution): The prior distribution of particle states. This remains fixed regardless of population changes.
22
+
variance_adapter (VarianceAdapter): The adapter used to adjust the variance of the perturbation kernel according to population particle state variance.
23
+
seed_sequence (SeedSequence | None): An optional seed sequence for random number generation.
24
+
particle_population (ParticlePopulation): The current population of particles.
25
+
26
+
Methods:
27
+
sample_particle() -> Particle:
28
+
Samples a particle from the current population based on their weights.
29
+
30
+
sample_and_perturb_particle(max_attempts: int = 10_000) -> Particle:
31
+
Samples a particle, perturbs it using the perturbation kernel, and returns
32
+
the perturbed particle. Raises a RuntimeError if a valid particle cannot
33
+
be sampled within the maximum number of attempts.
34
+
35
+
calculate_weight(particle: Particle) -> float:
36
+
Calculates the weight of a given particle based on the prior distribution
37
+
and the transition probabilities of the perturbation kernel.
38
+
39
+
adapt_variance():
40
+
Adapts the variance of the perturbation kernel based on the current particle population.
41
+
42
+
Raises:
43
+
ValueError: If the particle population is not set when attempting to sample a particle.
44
+
RuntimeError: If a valid perturbed particle cannot be sampled within the maximum number of attempts.
perturbation_kernel (PerturbationKernel): The initial kernel used to perturb particles during proposals.
60
+
priors (PriorDistribution): The prior distribution used for calculating particle weights.
61
+
variance_adapter (VarianceAdapter): The adapter responsible for adjusting perturbation variance.
62
+
seed_sequence (SeedSequence | None, optional): A sequence of seeds for replicable random number generation. Defaults to None.
63
+
particle_population (ParticlePopulation | None, optional): An initial population of particles. If not provided, a new ParticlePopulation instance is created. Defaults to None.
"Particle population is empty and variance adapter depends on population variance. Please add entries to the particle population or use `AdaptIdentityVariance` class."
0 commit comments