pybop.samplers.base_pints_sampler#
Classes#
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.BaseSamplerBase 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.
- _initialise_chain_processor()[source]#
Initialise the appropriate chain processor based on configuration.
- 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.