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)

Bases: pyabc.epsilon.Epsilon

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, history: pyabc.storage.history.History, latest_population: pyabc.population.Population = None)

Possibly calculate and return current epsilon / epsilon at time t.

Parameters:
  • t (int) – The population number. Counting is zero based. So the first population has t=0.
  • history (History) – ABC history object. Can be used to query summary statistics to set the epsilon
  • latest_population (Population) – The latest population, which may be different from the one stored in history.
Returns:

eps – The new epsilon for population t.

Return type:

float

get_config()

Return configuration of the distance function.

Returns:config – Dictionary describing the distance function.
Return type:dict
class pyabc.epsilon.Epsilon

Bases: abc.ABC

Abstract epsilon base class.

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

__call__(t: int, history: pyabc.storage.history.History, latest_population: pyabc.population.Population = None) → float

Possibly calculate and return current epsilon / epsilon at time t.

Parameters:
  • t (int) – The population number. Counting is zero based. So the first population has t=0.
  • history (History) – ABC history object. Can be used to query summary statistics to set the epsilon
  • latest_population (Population) – The latest population, which may be different from the one stored in history.
Returns:

eps – The new epsilon for population t.

Return type:

float

get_config()

Return configuration of the distance function.

Returns:config – Dictionary describing the distance function.
Return type:dict
initialize(sample_from_prior: List[dict], distance_to_ground_truth_function: Callable[dict, float])

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.

The default implementation is to do nothing. It is not necessary to implement this method.

Parameters:
  • sample_from_prior (List[dict]) – List of dictionaries containing the summary statistics.
  • distance_to_ground_truth_function (Callable[[dict], float]) – One of the distance functions pre evaluated at its second argument (the one representing the measured data). E.g. something like lambda x: distance_function(x, x_measured)
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.
Return type:str
class pyabc.epsilon.ListEpsilon(values: List[float])

Bases: pyabc.epsilon.Epsilon

Return epsilon values from a predefined list

Parameters:values (List[float]) – List of epsilon values. values[t] is the value for population t.
__call__(t: int, history: pyabc.storage.history.History, latest_population: pyabc.population.Population = None)

Possibly calculate and return current epsilon / epsilon at time t.

Parameters:
  • t (int) – The population number. Counting is zero based. So the first population has t=0.
  • history (History) – ABC history object. Can be used to query summary statistics to set the epsilon
  • latest_population (Population) – The latest population, which may be different from the one stored in history.
Returns:

eps – The new epsilon for population t.

Return type:

float

get_config()

Return configuration of the distance function.

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

Bases: pyabc.epsilon.QuantileEpsilon

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)

Bases: pyabc.epsilon.Epsilon

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

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.
  • strategy works even if the posterior is multi-modal. (This) –
  • that the acceptance threshold calculation is based on the distance (Note) –
  • the observation, not on the parameters which generated data with that (to) –
  • distance.
  • completely different parameter sets produce equally good samples, (If) –
  • distances of their samples to the ground truth data should be (the) –
  • comparable.
  • idea behind weighting is that the probability p_k of obtaining a (The) –
  • eps_k in the next generation should be proportional to the (distance) –
  • w_k of respective particle k in the current generation. Both (weight) –
  • and non-weighted median should lead to correct results. (weighted) –
__call__(t: int, history: pyabc.storage.history.History, latest_population: pyabc.population.Population = None) → float

Compute new epsilon from input, and return it.

get_config()

Return configuration of the distance function.

Returns:config – Dictionary describing the distance function.
Return type:dict
initialize(sample_from_prior, distance_to_ground_truth_function)

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.

The default implementation is to do nothing. It is not necessary to implement this method.

Parameters:
  • sample_from_prior (List[dict]) – List of dictionaries containing the summary statistics.
  • distance_to_ground_truth_function (Callable[[dict], float]) – One of the distance functions pre evaluated at its second argument (the one representing the measured data). E.g. something like lambda x: distance_function(x, x_measured)