MCMCPosteriorParameters#

class MCMCPosteriorParameters(method='slice_np_vectorized', thin=-1, warmup_steps=200, num_chains=20, init_strategy='resample', init_strategy_parameters=None, num_workers=1, mp_context='spawn')[source]#

Bases: PosteriorParameters

Parameters for initializing MCMCPosterior.

Fields:
method: Method used for MCMC sampling, one of slice_np,

slice_np_vectorized, hmc_pyro, nuts_pyro, slice_pymc, hmc_pymc, nuts_pymc. slice_np is a custom numpy implementation of slice sampling. slice_np_vectorized is identical to slice_np, but if num_chains>1, the chains are vectorized for slice_np_vectorized whereas they are run sequentially for slice_np. The samplers ending on _pyro are using Pyro, and likewise the samplers ending on _pymc are using PyMC.

thin: The thinning factor for the chain, default 1 (no thinning). warmup_steps: The initial number of samples to discard. num_chains: The number of chains. Should generally be at most

num_workers - 1.

init_strategy: The initialisation strategy for chains; proposal will draw

init locations from proposal, whereas sir will use Sequential- Importance-Resampling (SIR). SIR initially samples init_strategy_num_candidates from the proposal, evaluates all of them under the potential_fn and proposal, and then resamples the initial locations with weights proportional to exp(potential_fn - proposal.log_prob. resample is the same as sir but uses exp(potential_fn) as weights.

init_strategy_parameters: Dictionary of keyword arguments passed to the

init strategy, e.g., for init_strategy=sir this could be num_candidate_samples, i.e., the number of candidates to find init locations (internal default is 1000), or device.

num_workers: number of cpu cores used to parallelize mcmc mp_context: Multiprocessing start method, either “fork” or “spawn”

(default), used by Pyro and PyMC samplers. “fork” can be significantly faster than “spawn” but is only supported on POSIX-based systems (e.g. Linux and macOS, not Windows).

Parameters:
  • method (Literal['slice_np', 'slice_np_vectorized', 'hmc_pyro', 'nuts_pyro', 'slice_pymc', 'hmc_pymc', 'nuts_pymc'])

  • thin (int)

  • warmup_steps (int)

  • num_chains (int)

  • init_strategy (Literal['proposal', 'sir', 'resample'])

  • init_strategy_parameters (Dict[str, Any] | None)

  • num_workers (int)

  • mp_context (Literal['fork', 'spawn'])

method: Literal['slice_np', 'slice_np_vectorized', 'hmc_pyro', 'nuts_pyro', 'slice_pymc', 'hmc_pymc', 'nuts_pymc'] = 'slice_np_vectorized'#
thin: int = -1#
warmup_steps: int = 200#
num_chains: int = 20#
init_strategy: Literal['proposal', 'sir', 'resample'] = 'resample'#
init_strategy_parameters: Dict[str, Any] | None = None#
num_workers: int = 1#
mp_context: Literal['fork', 'spawn'] = 'spawn'#
validate()[source]#

Validate MCMCPosteriorParameters fields.

with_param(**kwargs)#

Create a new instance of the class with updated field values.

Only allows updates to fields defined in the dataclass. Raises an error if any unknown or invalid field names are passed.

Parameters:

**kwargs – Field-value pairs to override in the new instance.

Returns:

A new instance of the same class with updated values.

Raises:

ValueError – If any of the provided keys are not valid dataclass fields.