pybop.samplers.base_pints_sampler#
Classes#
Base class for PINTS samplers. |
|
Pints sampler options. |
Module Contents#
- class pybop.samplers.base_pints_sampler.BasePintsSampler(log_pdf: pybop.problems.log_pdf.LogPDF, sampler: type[pints.SingleChainMCMC | pints.MultiChainMCMC], options: PintsSamplerOptions | None = None)[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.LogPDF) – 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.
- _initialise_chain_processor()[source]#
Initialise the appropriate chain processor based on configuration.
- 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:
- 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#
- _chains_in_memory = True#
- _evaluation_files = None#
- _initial_phase#
- _initial_phase_iterations = 250#
- _log_filename = None#
- _log_to_screen = True#
- _loop_iters = 0#
- _max_iterations = 500#
- _needs_sensitivities#
- _sampler#
- _single_chain#
- _verbose = False#
- _warm_up = 0#
- property active#
- property chains_in_memory#
- iter_time = 0.0#
- property iteration#
- property max_iterations#
- property n_samples#
- property needs_sensitivities#
- property sampled_logpdf#
- property sampled_prior#
- property samplers#
- property single_chain#
- class pybop.samplers.base_pints_sampler.PintsSamplerOptions[source]#
Bases:
pybop.samplers.base_sampler.SamplerOptionsPints sampler options.
- n_chains#
The number of chains to concurrently sample from (default: 1).
- Type:
int
- max_iterations#
Maximum number of iterations to run (default: 500).
- Type:
int
- verbose#
If True, additional information will be printed (default: False).
- Type:
bool
- warm_up_iterations#
Number of iterations to warm up the sampler (default: 250).
- Type:
int
- chains_in_memory#
Whether to store the chains in memory (default: True).
- Type:
bool
- log_to_screen#
If True (default), the sampler will print information during the sampling.
- Type:
bool
- log_filename#
The name of the file to save the sampler log to (default: None).
- Type:
str
- chain_files#
The name of the file to save the chains in (default: None).
- Type:
list
- evaluation_files#
The name of the file to save the evaluations in (default: None).
- Type:
list
- chain_files: list[str] | None = None#
- chains_in_memory: bool = True#
- evaluation_files: list[str] | None = None#
- initial_phase_iterations: int = 250#
- log_filename: str | None = None#
- log_to_screen: bool = True#
- max_iterations: int = 500#
- verbose: bool = False#
- warm_up_iterations: int = 0#