rxmc.metropolis_hastings.metropolis_hastings#

rxmc.metropolis_hastings.metropolis_hastings(x0: ndarray, bounds: ndarray, n_steps: int, log_posterior: Callable[[ndarray], float], rng: Generator, propose: Callable[[ndarray, Generator], ndarray]) Tuple[ndarray, ndarray, int][source]#

Metropolis-Hastings MCMC sampling.

Proposals that fall outside bounds are rejected outright; otherwise the standard MH acceptance criterion is applied.

Parameters:
  • x0 (np.ndarray, shape (ndim,)) – Initial parameter vector.

  • bounds (np.ndarray, shape (ndim, 2)) – Parameter bounds; each row is [lower, upper].

  • n_steps (int) – Number of MCMC steps to generate.

  • log_posterior (callable) – Function f(x) -> float returning the log posterior at x.

  • rng (np.random.Generator) – Random number generator for reproducibility.

  • propose (callable) – Function g(x, rng) -> x_new that draws a candidate from the proposal distribution centred at x.

Returns:

  • chain (np.ndarray, shape (n_steps, ndim)) – Sampled parameter vectors.

  • logp_chain (np.ndarray, shape (n_steps,)) – Log posterior values corresponding to each sample.

  • accepted (int) – Number of accepted proposals.