rxmc.param_sampling.BatchedAdaptiveMetropolisSampler#
- class rxmc.param_sampling.BatchedAdaptiveMetropolisSampler(params: list[Parameter], prior, starting_location: ndarray, initial_proposal_cov: ndarray, epsilon_fraction: float = 1e-06)[source]#
Bases:
SamplerMetropolis sampler that updates the proposal covariance after each batch.
After each completed (non-burn) batch the proposal covariance is replaced by the empirical covariance of that batch, scaled by
2.38² / ndim.- Parameters:
params (list of Parameter) – Parameters to sample.
prior (object) – Prior distribution with a callable
logpdf(x)method.starting_location (np.ndarray, shape (ndim,)) – Initial parameter vector.
initial_proposal_cov (np.ndarray, shape (ndim, ndim)) – Initial proposal covariance matrix.
epsilon_fraction (float, optional) – Small regularisation fraction added to the empirical covariance diagonal. Defaults to
1e-6.
- __init__(params: list[Parameter], prior, starting_location: ndarray, initial_proposal_cov: ndarray, epsilon_fraction: float = 1e-06)[source]#
Methods
__init__(params, prior, starting_location, ...)batch_acceptance_fractions()Acceptance fraction for each completed batch.
most_recent_batch_acceptance_fraction()Acceptance fraction of the most recent batch.
overall_acceptance_fraction()Overall acceptance fraction across all completed batches.
record_batch(n_steps, n_accepted, chain, ...)Append a completed batch to the running chain.
sample(n_steps, starting_location, rng, ...)Run the sampler for one batch, updating the proposal after recording.
- sample(n_steps: int, starting_location: ndarray, rng: Generator, log_posterior: Callable[[ndarray], float], burn: bool = False)[source]#
Run the sampler for one batch, updating the proposal after recording.
Overrides
Sampler.sample()to adapt the proposal covariance from the current batch’s empirical covariance after each non-burn batch.- Parameters:
n_steps (int) – Number of steps to run.
starting_location (np.ndarray, shape (ndim,)) – Starting parameter vector.
rng (np.random.Generator) – Random number generator.
log_posterior (callable) – Function
f(x) -> floatreturning the log posterior.burn (bool, optional) – If
True, discard samples and skip covariance update. Defaults toFalse.