pyabc.populationstrategy

Population strategies

Strategies to choose the population size.

The population size can be constant or can change over the course of the generations.

class pyabc.populationstrategy.AdaptivePopulationSize(start_nr_particles, mean_cv: float = 0.05, max_population_size: int = inf, min_population_size: int = 10, n_bootstrap: int = 10, nr_calibration_particles: int = None)[source]

Bases: PopulationStrategy

Adapt the population size according to the mean coefficient of variation error criterion, as detailed in [1] . This strategy tries to respond to the shape of the current posterior approximation by selecting the population size such that the variation of the density estimates matches the target variation given via the mean_cv argument.

Parameters:
  • start_nr_particles – Number of particles in the first populations

  • mean_cv – The error criterion. Defaults to 0.05. A smaller value leads generally to larger populations. The error criterion is the mean coefficient of variation of the estimated KDE.

  • max_population_size – Max nr of allowed particles in a population. Defaults to infinity.

  • min_population_size – Min number of particles allowed in a population. Defaults to 10.

  • n_bootstrap – Number of bootstrapped populations to use to estimate the CV. Defaults to 10.

  • nr_calibration_particles – Number of calibration particles.

__call__(**kwargs)[source]

Call self as a function.

__init__(start_nr_particles, mean_cv: float = 0.05, max_population_size: int = inf, min_population_size: int = 10, n_bootstrap: int = 10, nr_calibration_particles: int = None)[source]
get_config() dict[source]

Get the configuration of this object.

Returns:

Configuration of the class as dictionary

Return type:

config

update(transitions: List[Transition], model_weights: ndarray, t: int = None)[source]

Select the population size for the next population.

Parameters:
  • transitions – List of transitions.

  • model_weights – Array of model weights.

  • t – Time to adapt for.

class pyabc.populationstrategy.ConstantPopulationSize(nr_particles: int, nr_calibration_particles: int = None)[source]

Bases: PopulationStrategy

Constant size of the different populations

Parameters:
  • nr_particles – Number of particles per population.

  • nr_calibration_particles – Number of calibration particles.

__call__(**kwargs)[source]

Call self as a function.

__init__(nr_particles: int, nr_calibration_particles: int = None)[source]
get_config() dict[source]

Get the configuration of this object.

Returns:

Configuration of the class as dictionary

Return type:

config

class pyabc.populationstrategy.ListPopulationSize(values: List[int] | Dict[int, int], nr_calibration_particles: int = None)[source]

Bases: PopulationStrategy

Return population size values from a predefined list. For every time point enquired later (specified by time t), an entry must exist in the list.

Parameters:
  • values – List of population size values. values[t] is the value for population t.

  • nr_calibration_particles – Number of calibration particles.

__call__(**kwargs)[source]

Call self as a function.

__init__(values: List[int] | Dict[int, int], nr_calibration_particles: int = None)[source]
get_config() dict[source]

Get the configuration of this object.

Returns:

Configuration of the class as dictionary

Return type:

config

class pyabc.populationstrategy.PopulationStrategy(nr_calibration_particles: int = None)[source]

Bases: ABC

Strategy to select the sizes of the populations.

This is a non-functional abstract base implementation. Do not use this class directly. Subclasses must override the update method.

Parameters:

nr_calibration_particles – Number of calibration particles.

abstract __call__(t: int = None) int[source]

Call self as a function.

__init__(nr_calibration_particles: int = None)[source]
get_config() dict[source]

Get the configuration of this object.

Returns:

Configuration of the class as dictionary

Return type:

config

to_json() str[source]

Return the configuration as json string. Per default, this converts the dictionary returned by get_config to json.

Returns:

Configuration of the class as json string.

Return type:

config

update(transitions: List[Transition], model_weights: ndarray, t: int = None)[source]

Select the population size for the next population.

Parameters:
  • transitions – List of transitions.

  • model_weights – Array of model weights.

  • t – Time to adapt for.