ABC sampler base class

class pints.ABCSampler[source]

Abstract base class for ABC methods. All ABC samplers implement the pints.Loggable and pints.TunableMethod interfaces.

ask()[source]

Returns a parameter vector sampled from the LogPrior.

n_hyper_parameters()

Returns the number of hyper-parameters for this method (see TunableMethod).

name()[source]

Returns this method’s full name.

set_hyper_parameters(x)

Sets the hyper-parameters for the method with the given vector of values (see TunableMethod).

Parameters:

x – An array of length n_hyper_parameters used to set the hyper-parameters.

tell(x)[source]

Performs an iteration of the ABC algorithm, using the parameters specified by ask. Expects to receive x as a sequence of length at least 1. Returns the accepted parameter values.

class pints.ABCController(error_measure, log_prior, method=None)[source]

Samples from a pints.LogPrior.

Properties related to the number of iterations, parallelisation, threshold, and number of parameters to sample can be set directly on the ABCController object. Afterwards the ABC routine can be run.

Parameters:
  • error_measure – An error measure to evaluate on a problem, given a forward model, simulated and observed data, and times

  • log_prior – A LogPrior function from which parameter values are sampled

  • method – The class of ABCSampler to use. If no method is specified, RejectionABC is used.

Example

::

abc = pints.ABCController(error_measure, log_prior) abc.set_max_iterations(1000) posterior_estimate = abc.run()

log_filename()[source]

Returns the path to the controller log, or None if not set.

max_iterations()[source]

Returns the maximum iterations if this stopping criterion is set, or None if it is not. See set_max_iterations().

n_samples()[source]

Returns the target number of samples to obtain in the estimated posterior.

parallel()[source]

Returns the number of parallel worker processes this routine will be run on, or False if parallelisation is disabled.

run()[source]

Runs the ABC sampler.

sampler()[source]

Returns the underlying sampler object.

set_log_interval(iters=20, warm_up=3)[source]

Changes the frequency with which messages are logged.

Parameters:
  • iters – A log message will be shown every iters iterations.

  • warm_up – A log message will be shown every iteration, for the first warm_up iterations.

set_log_to_file(filename=None, csv=False)[source]

Enables progress logging to file when a filename is passed in, disables it if filename is False or None.

The argument csv can be set to True to write the file in comma separated value (CSV) format. By default, the file contents will be similar to the output on screen.

set_log_to_screen(enabled)[source]

Enables or disables progress logging to screen.

set_max_iterations(iterations=10000)[source]

Adds a stopping criterion, allowing the routine to halt after the given number of iterations.

This criterion is enabled by default. To disable it, use set_max_iterations(None).

set_n_samples(n_samples=500)[source]

Sets a target number of samples

set_parallel(parallel=False)[source]

Enables/disables parallel evaluation.

If parallel=True, the method will run using a number of worker processes equal to the detected cpu core count. The number of workers can be set explicitly by setting parallel to an integer greater than 0. Parallelisation can be disabled by setting parallel to 0 or False.