Epsilon¶

Acceptance threshold scheduling strategies¶

Acceptance thresholds (= epsilon) can be calculated based on the distances from the observed data, can follow a pre-defined list, can be constant, or can have a user-defined implementation.

class pyabc.epsilon.ConstantEpsilon(constant_epsilon_value: float)

Keep epsilon constant over all populations. This acceptance threshold scheduling strategy is most likely only interesting for debugging purposes.

Parameters: constant_epsilon_value (float) – The epsilon value for all populations
__call__(t: int)

Get epsilon value for generation t.

Parameters: t (int) – The time point to get the epsilon threshold for. eps – The epsilon for population t. float
get_config()

Return configuration of the distance function.

Returns: config – Dictionary describing the distance function. dict
class pyabc.epsilon.Epsilon(require_initialize: bool = True)

Bases: abc.ABC

Abstract epsilon base class.

This class encapsulates a strategy for setting a new epsilon for each new population.

__call__(t: int) → float

Get epsilon value for generation t.

Parameters: t (int) – The time point to get the epsilon threshold for. eps – The epsilon for population t. float
get_config()

Return configuration of the distance function.

Returns: config – Dictionary describing the distance function. dict
initialize(t: int, weighted_distances: pandas.core.frame.DataFrame)

This method is called by the ABCSMC framework before the first usage of the epsilon and can be used to calibrate it to the statistics of the samples.

This method is only called if require_initialize == True.

Default: Do nothing.

Parameters: t (int) – The time point to initialize the epsilon for. weighted_distances (pandas.DataFrame) – The distances for initializing the epsilon, as returned by Population.get_weighted_distances().
to_json()

Return JSON encoded configuration of the distance function.

Returns: json_str – JSON encoded string describing the distance function. The default implementation is to try to convert the dictionary returned my get_config. str
update(t: int, weighted_distances: pandas.core.frame.DataFrame)

Update epsilon value to be used as acceptance criterion for generation t.

Default: Do nothing.

Parameters: t (int) – The generation index to update / set epsilon for. Counting is zero-based. So the first population has t=0. weighted_distances (pandas.DataFrame) – The distances that should be used to update epsilon, as returned by Population.get_weighted_distances(). These are usually the distances of samples accepted in population t-1. The distances may differ from those used for acceptance in population t-1, if the distance function for population t has been updated.
class pyabc.epsilon.ListEpsilon(values: List[float])

Return epsilon values from a predefined list. For every time point enquired later, an epsilon value must exist in the list.

Parameters: values (List[float]) – List of epsilon values. values[t] is the value for population t.
__call__(t: int)

Get epsilon value for generation t.

Parameters: t (int) – The time point to get the epsilon threshold for. eps – The epsilon for population t. float
get_config()

Return configuration of the distance function.

Returns: config – Dictionary describing the distance function. dict
class pyabc.epsilon.MedianEpsilon(initial_epsilon: Union[str, int, float] = 'from_sample', median_multiplier: float = 1, weighted: bool = True)

Calculate epsilon as median of the distances from the last population.

class pyabc.epsilon.QuantileEpsilon(initial_epsilon: Union[str, int, float] = 'from_sample', alpha: float = 0.5, quantile_multiplier: float = 1, weighted: bool = True)

Calculate epsilon as alpha-quantile of the distances from the last population.

This strategy works even if the posterior is multi-modal. Note that the acceptance threshold calculation is based on the distance to the observation, not on the parameters which generated data with that distance.

If completely different parameter sets produce equally good samples, the distances of their samples to the ground truth data should be comparable.

The idea behind weighting is that the probability p_k of obtaining a distance eps_k in the next generation should be proportional to the weight w_k of respective particle k in the current generation. Both weighted and non-weighted median should lead to correct results.

Parameters: initial_epsilon (Union[str, int]) – If ‘from_sample’, then the initial quantile is calculated from a sample of the current population size from the prior distribution. If a number is given, this number is used. alpha (float) – The alpha-quantile to be used, e.g. alpha=0.5 means median. quantile_multiplier (float) – Multiplies the quantile by that number. also applies it to the initial quantile if it is calculated from samples. However, it does not apply to the initial quantile if it is given as a number. weighted (bool) – Flag indicating whether the new epsilon should be computed using weighted (True, default) or non-weighted (False) distances.
__call__(t: int) → float

Epsilon value for time t, set before via update() method.

Returns: eps – The epsilon value for time t (throws error if not existent). float
get_config()

Return configuration of the distance function.

Returns: config – Dictionary describing the distance function. dict
initialize(t: int, weighted_distances: pandas.core.frame.DataFrame)

This method is called by the ABCSMC framework before the first usage of the epsilon and can be used to calibrate it to the statistics of the samples.

This method is only called if require_initialize == True.

Default: Do nothing.

Parameters: t (int) – The time point to initialize the epsilon for. weighted_distances (pandas.DataFrame) – The distances for initializing the epsilon, as returned by Population.get_weighted_distances().
update(t: int, weighted_distances: pandas.core.frame.DataFrame)

Compute quantile of the (weighted) distances given in population, and use this to update epsilon.