pybop.samplers.base_pints_sampler#

Classes#

BasePintsSampler

Base class for PINTS samplers.

PintsSamplerOptions

Pints sampler options.

Module Contents#

class pybop.samplers.base_pints_sampler.BasePintsSampler(log_pdf: pybop.problems.problem.Problem, sampler: type[pints.SingleChainMCMC | pints.MultiChainMCMC], options: PintsSamplerOptions | None = None)[source]#

Bases: pybop.BaseSampler

Base class for PINTS samplers.

This class extends the BaseSampler class to provide a common interface for PINTS samplers. The class provides a sample() method that can be used to sample from the posterior distribution using a PINTS sampler.

Parameters:
  • log_pdf (pybop.Problem) – The negative unnormalised posterior distribution.

  • sampler (pints.MCMCSampler) – The PINTS sampler to be used for sampling.

  • options (Optional[PintsSamplerOptions]) – Options for the sampler, by default None.

_ask_for_samples()[source]#
_check_initial_phase()[source]#

Set initial phase if needed

_check_stopping_criteria()[source]#

Verify that at least one stopping criterion is defined.

_end_initial_phase()[source]#
_finalise_logging()[source]#
_initialise_chain_processor()[source]#

Initialise the appropriate chain processor based on configuration.

_initialise_logging()[source]#
_initialise_storage()[source]#
_process_chains()[source]#

Process chains using the appropriate processor.

static default_options() PintsSamplerOptions[source]#

Get the default options for the sampler.

run() numpy.ndarray[source]#

Executes the Monte Carlo sampling process and generates samples from the posterior distribution.

This method orchestrates the entire sampling process, managing iterations, evaluations, logging, and stopping criteria. It initialises the necessary structures, handles both single and multi-chain scenarios, and manages parallel evaluation based on the configuration.

Returns:

The results including a numpy array containing the samples from the posterior distribution if chains are stored in memory, otherwise None.

Return type:

SamplingResult

Raises:
  • ValueError – If no stopping criterion is set (i.e., _max_iterations is None).

  • Details:

    • Checks and ensures at least one stopping criterion is set.

    • Initialises iterations, evaluations, and other required

    structures. - Sets up the parallel evaluator based on the configuration. - Handles the initial phase, if applicable, and manages intermediate steps in the sampling process. - Logs progress and relevant information based on the logging configuration. - Iterates through the sampling process, evaluating the log PDF, updating chains, and managing the stopping criteria. - Finalises and returns the collected samples, or None if chains are not stored in memory.

_chain_files = None[source]#
_chains_in_memory = True[source]#
_evaluation_files = None[source]#
_initial_phase[source]#
_initial_phase_iterations = 250[source]#
_log_filename = None[source]#
_log_to_screen = True[source]#
_loop_iters = 0[source]#
_max_iterations = 500[source]#
_n_parameters[source]#
_needs_sensitivities[source]#
_sampler[source]#
_single_chain[source]#
_verbose = False[source]#
_warm_up = 0[source]#
property active[source]#
property chains_in_memory[source]#
iter_time = 0.0[source]#
property iteration[source]#
property max_iterations[source]#
property n_samples[source]#
property needs_sensitivities[source]#
property sampled_logpdf[source]#
property sampled_prior[source]#
property samplers[source]#
property single_chain[source]#
class pybop.samplers.base_pints_sampler.PintsSamplerOptions[source]#

Bases: pybop.samplers.base_sampler.SamplerOptions

Pints sampler options.

n_chains[source]#

The number of chains to concurrently sample from (default: 1).

Type:

int

cov[source]#

Covariance matrix (default: 0.05).

Type:

float | np.ndarray

max_iterations[source]#

Maximum number of iterations to run (default: 500).

Type:

int

verbose[source]#

If True, additional information will be printed (default: False).

Type:

bool

warm_up_iterations[source]#

Number of iterations to warm up the sampler (default: 250).

Type:

int

chains_in_memory[source]#

Whether to store the chains in memory (default: True).

Type:

bool

log_to_screen[source]#

If True (default), the sampler will print information during the sampling.

Type:

bool

log_filename[source]#

The name of the file to save the sampler log to (default: None).

Type:

str

chain_files[source]#

The name of the file to save the chains in (default: None).

Type:

list

evaluation_files[source]#

The name of the file to save the evaluations in (default: None).

Type:

list

validate()[source]#

Validate the options.

Raises:

ValueError – If the options are invalid.

chain_files: list[str] | None = None[source]#
chains_in_memory: bool = True[source]#
evaluation_files: list[str] | None = None[source]#
initial_phase_iterations: int = 250[source]#
log_filename: str | None = None[source]#
log_to_screen: bool = True[source]#
max_iterations: int = 500[source]#
verbose: bool = False[source]#
warm_up_iterations: int = 0[source]#