pybop.samplers.base_pints_sampler#

Classes#

BasePintsSampler

Base class for PINTS samplers.

Module Contents#

class pybop.samplers.base_pints_sampler.BasePintsSampler(log_pdf: pybop.LogPosterior | list[pybop.LogPosterior], sampler, chains: int = 1, warm_up=None, x0=None, cov0=0.1, **kwargs)[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.LogPosterior or List[pybop.LogPosterior]) – An object to be sampled, currently supports the pybop.LogPosterior class.

  • sampler (pybop.Sampler) – The sampling algorithm to use.

  • chains (int) – Number of chains to run concurrently. Each chain contains separate markov samples from the log_pdf.

  • x0 (numpy.ndarray) – Initial values of the parameters for the optimisation.

  • cov0 (list-like) – Initial covariance for the chains in the parameters. Either a scalar value (same for all coordinates) or an array with one entry per dimension.

  • kwargs – Additional keyword arguments.

_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.

_create_evaluator()[source]#

Create appropriate evaluator based on configuration settings.

_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.

run() numpy.ndarray | None[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 or sequential evaluation based on the configuration.

Returns:

A numpy array containing the samples from the posterior distribution if chains are stored in memory, otherwise returns None.

Return type:

np.ndarray

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 evaluator (parallel or sequential) 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[source]#
_chains_in_memory[source]#
_evaluation_files[source]#
_initial_phase[source]#
_initial_phase_iterations[source]#
_iteration = 0[source]#
_log_filename[source]#
_log_to_screen[source]#
_loop_iters = 0[source]#
_max_iterations[source]#
_needs_sensitivities[source]#
_parallel[source]#
_prior = None[source]#
_single_chain[source]#
_verbose[source]#
_warm_up = None[source]#
property active[source]#
property chains_in_memory[source]#
iter_time[source]#
property iteration[source]#
property max_iterations[source]#
property n_samples[source]#
property needs_sensitivities[source]#
property prior[source]#
property sampled_logpdf[source]#
property sampled_prior[source]#
sampler[source]#
property samplers[source]#
property single_chain[source]#