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.
Try to keep the acceptance rate constant at a value of
target_rate. Note that this scheme will fail to
reduce the temperature sufficiently in later iterations, if the
problem’s inherent acceptance rate is lower, but it has been
observed to give big feasible temperature leaps in early iterations.
In particular, this scheme can be used to propose an initial temperature.
Parameters:
target_rate (float, optional) – The target acceptance rate to match.
min_rate (float, optional) – The minimum rate below which not to apply the acceptance step scheme
any more. Setting this to a value of e.g. 0.05 can make sense
1) because it may be unlikely that the acceptance rate scheme will
propose a useful temperature at such low acceptance levels, and
2) to avoid uneccessary computations.
This scheme is loosely based on [1], however note that it does
not try to replicate it entirely. In particular, the implementation
of pyABC does not allow the sampling to be stopped when encountering
too low acceptance rates, such that this can only be done ex-posteriori
here.
Parameters:
alpha (float, optional) – The ratio by which to decrease the temperature value. More
specifically, the next temperature is given as
(1-alpha) * temperature.
min_rate (float, optional) – A minimum acceptance rate. If this rate has been violated in the
previous iteration, the alpha value is decreased.
This is called by the ABCSMC class and gives the epsilon
the opportunity to configure the sampler.
For example, it might request the sampler to
also return rejected particles in order to adapt the
epsilon to the statistics of the sample.
The method is called by the ABCSMC framework before the first
use of the epsilon (at the beginning of ABCSMC.run()), after
initialize().
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.
Update epsilon value to be used as acceptance criterion for
generation t.
Default: Do nothing.
Parameters:
t – The generation index to update / set epsilon for. Counting is
zero-based. So the first population has t=0.
get_weighted_distances – 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.
get_all_records – Returns on demand a list of information obtained from all
particles.
acceptance_rate – The current generation’s acceptance rate.
acceptor_config – An object provided by the Acceptor class.
where n denotes the number of populations, and j=1,…,n the iteration.
This translates to
\[T_j = T_{j-1}^{(n-j)/(n-(j-1))}.\]
This ensures that a temperature of 1.0 is reached after exactly the
remaining number of steps.
So, in both cases the sequence of temperatures follows an exponential
decay, also known as a geometric progression, or a linear progression
in log-space.
Note that the formula is applied anew in each iteration.
This is advantageous if also other schemes are used s.t. T_{j-1}
is smaller than by the above.
Parameters:
alpha (float) – Factor by which to reduce the temperature, if max_nr_populations
is infinite.
Like the pyabc.epsilon.ExpDecayFixedIterScheme,
this yields a geometric progression, however with a fixed ratio,
irrespective of the number of iterations. If a finite number of
iterations is specified in ABCSMC, there is no influence on the final
jump to a temperature of 1.0.
This is quite similar to the pyabc.epsilon.DalyScheme, although
simpler in implementation. The alpha value here corresponds to a value of
1 - alpha there.
Parameters:
alpha (float, optional) – The ratio of subsequent temperatures.
min_rate (float, optional) – A minimum acceptance rate. If this rate has been violated in the
previous iteration, the alpha value is increased.
max_rate (float, optional) – Maximum rate to not be exceeded, otherwise the alpha value is
decreased.
Note that this is similar to the
pyabc.epsilon.ExpDecayFixedIterScheme, which is
indeed the limit for exponent -> infinity. For smaller
exponent, the sequence makes larger steps for low temperatures. This
can be useful in cases, where lower temperatures (which are usually
more expensive) can be traversed in few larger steps, however also
the opposite may be true, i.e. that more steps at low temperatures
are advantageous.
Parameters:
exponent (float, optional) – The exponent to use in the scheme.
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.
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.
Threshold based on the threshold - acceptance rate relation.
Approaches based on quantiles over previously observed distances
(pyabc.epsilon.QuantileEpsilon) can fail to converge to the true
posterior, by not focusing on regions in parameter space corresponding to
small distances.
For example when there is only a small global optimum and a large local
optimum, are such approaches likely to focus only on the latter,
especially for large alpha.
In contrast, this approach is based on an estimate of the threshold -
acceptance rate curve, aiming to balance threshold reduction with
computational cost, and avoiding local optima.
It is based on [3], but uses a simpler acceptance rate
approximation via importance sampling propagation and automatic
differentiation.
It chooses a threshold maximizing the second derivative of the acceptance
rate as a function of the threshold. This tackles in particular local
optima, which induce a convex shape.
In case of a convex curve, common for unimodal problems, or more general
too low proposed thresholds or acceptance rates, instead a value is
calculated as a trade-off between high acceptance rate and low threshold,
minimizing a joint distance.
min_rate – Minimum acceptance rate. If the proposal optimal rate is lower
(in particular for concave curves, for which the danger of local
optima is not given), instead a trade-off of low threshold and
high acceptance rate is performed.
k – Coefficient governing the steepness of the continuous acceptance
step aproximation (which is used to obtain a more meaningful
2nd derivative). If inf, no continuous approximation is used.
This is called by the ABCSMC class and gives the epsilon
the opportunity to configure the sampler.
For example, it might request the sampler to
also return rejected particles in order to adapt the
epsilon to the statistics of the sample.
The method is called by the ABCSMC framework before the first
use of the epsilon (at the beginning of ABCSMC.run()), after
initialize().
Update epsilon value to be used as acceptance criterion for
generation t.
Default: Do nothing.
Parameters:
t – The generation index to update / set epsilon for. Counting is
zero-based. So the first population has t=0.
get_weighted_distances – 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.
get_all_records – Returns on demand a list of information obtained from all
particles.
acceptance_rate – The current generation’s acceptance rate.
acceptor_config – An object provided by the Acceptor class.
This class implements a highly adaptive and configurable temperature
scheme. Via the argument schemes, arbitrary temperature schemes can be
passed to calculate the next generation’s temperature, via aggregate_fun
one can define how to combine multiple guesses, via initial_temperature
the initial temperature can be set.
Parameters:
schemes – Temperature schemes returning proposed
temperatures for the next time point, e.g.
instances of pyabc.epsilon.TemperatureScheme.
aggregate_fun – The function to aggregate the schemes by, of the form
Callable[List[float],float].
Defaults to taking the minimum.
initial_temperature – The initial temperature. If None provided, an AcceptanceRateScheme
is used.
enforce_exact_final_temperature – Whether to force the final temperature (if max_nr_populations < inf)
to be 1.0, giving exact inference.
log_file – A log file for storing data of the temperature that are currently not
saved in the database. The data are saved in json format.
Properties –
---------- –
max_nr_populations – The maximum number of iterations as passed to ABCSMC.
May be inf, but not all schemes can handle that (and will complain).
temperatures – Times as keys and temperatures as values.
This is called by the ABCSMC class and gives the epsilon
the opportunity to configure the sampler.
For example, it might request the sampler to
also return rejected particles in order to adapt the
epsilon to the statistics of the sample.
The method is called by the ABCSMC framework before the first
use of the epsilon (at the beginning of ABCSMC.run()), after
initialize().
Update epsilon value to be used as acceptance criterion for
generation t.
Default: Do nothing.
Parameters:
t – The generation index to update / set epsilon for. Counting is
zero-based. So the first population has t=0.
get_weighted_distances – 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.
get_all_records – Returns on demand a list of information obtained from all
particles.
acceptance_rate – The current generation’s acceptance rate.
acceptor_config – An object provided by the Acceptor class.
A TemperatureScheme suggests the next temperature value. It is used as
one of potentially multiple schemes employed in the Temperature class.
This class is abstract.