curepy.retrieval_methods.mcmc module

curepy.retrieval_methods.mcmc module#

Markov Chain Monte Carlo (MCMC) retrieval class

class curepy.retrieval_methods.mcmc.MCMC(nwalkers: int, steps: int, burn_in: int, progress: bool = True, parallel_cores: int = 1)[source]#

Bases: BaseRetrieval

MCMC retrieval object.

analyse_samples(samples: ndarray, b_samples: ndarray | None, return_samples: bool, return_corr: bool, return_b_samples: bool, reshape_results: bool, corr_dims: int | Sequence[int] | None = -99) RetrievalResult[source]#

Summarise MCMC samples into a RetrievalResult.

Computes the median, symmetric uncertainty (average of upper and lower 1-sigma percentiles), and optionally the correlation matrix.

Parameters:
  • samples – Post-burn-in MCMC samples.

  • b_samples – Ancillary parameter samples.

  • return_samples – If True, include the raw samples in the result.

  • return_corr – If True, compute and include the correlation matrix.

  • return_b_samples – If True, include ancillary samples.

  • reshape_results – If True, reshape outputs to the initial-guess shape.

  • corr_dims – int or List of ints, axis to calculate correlation matrix along.

Returns:

Retrieved values, uncertainties, and optional extras.

generate_theta_i(theta_0: ndarray, factor_std: float = 0.1) ndarray[source]#

Generate a single walker starting position from theta_0.

Perturbs theta_0 by a Gaussian factor and recursively reduces the perturbation magnitude until the resulting position lies within the support of the prior.

Parameters:
  • theta_0 – Initial state vector.

  • factor_std – Standard deviation of the multiplicative Gaussian perturbation.

Returns:

Perturbed starting position that is within the prior support.

run_MCMC(theta_0: ndarray, nwalkers: int, steps: int, burn_in: int) ndarray[source]#

Run emcee.EnsembleSampler and return the post-burn-in chain.

Parameters:
  • theta_0 – Initial state vector around which walkers are initialised.

  • nwalkers – Number of ensemble walkers.

  • steps – Total number of sampling steps.

  • burn_in – Number of initial samples to discard.

Returns:

Array of post-burn-in samples with shape (nwalkers * steps - burn_in, ndim).