Epsilon

Acceptance threshold scheduling strategies.

Acceptance thresholds 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, history)
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
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)
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
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_funciton(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, history)
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
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)

Bases: pyabc.epsilon.Epsilon

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

Parameters:
  • initial_epsilon (Union[str, int]) –
    • If ‘from_sample’, then the initial median is calculated from a sample of the current population size from the prior distribution.
    • If a number is given, this number is used.
  • median_multiplier (float) – Multiplies the median by that number. also applies it to the initial median if it is calculated from samples. However, it does not apply to the initial median if it is given as a number.

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.

__call__(t, history)
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
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, 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_funciton(x, x_measured)