bebi103.hmc.convert_samples

bebi103.hmc.convert_samples(samples, out_format, inc_warmup=False, arviz_kwargs=None, groups=None)

Converts samples to a new format.

Parameters:
  • samples (dict, cmdstanpy.CmdStanMCMC, xarray.DataTree, pandas.DataFrame, or polars.DataFrame) – Results from an MCMC sampling to convert to desired format.

  • out_format (str, one of 'dict', 'arviz', 'pandas', 'polars') –

    The desired output format of the samples.

    • dict: Dictionary of expectands and HMC diagnostics. Each item is a 2D Numpy array. The first dimension indexes the Markov chains and the second indexes the sequential states within each chain.

    • arviz: An xarray.DataTree instance as used by ArviZ. Only valid if samples is a cmdstanpy.CmdStanMCMC instance.

    • pandas.DataFrame: Each row of the data frame is a chain/draw with expectand values and HMC diagnostic results.

    • polars.DataFrame: Each row of the data frame is a chain/draw with expectand values and HMC diagnostic results.

  • inc_warmup (bool, default False) – If True, include warmup samples. Only active if samples is a cmdstanpy.CmdStanMCMC instance.

  • arviz_kwargs (dict, default None) – Keyword arguments to be passed to arviz_base.from_cmdstanpy().

  • groups (str or iterable of str, default None) – Groups of an xarray.DataTree to use when converting to ‘dict’, ‘pandas’, or ‘polars’ format. Allowed groups are ‘posterior’, ‘prior’, ‘posterior_predictive’, ‘prior_predictive’, ‘log_likelihood’, and ‘sample_stats’. If None, all allowed groups present in samples are used. Prior-side groups (‘prior’, ‘prior_predictive’) cannot be combined with posterior-side groups (‘posterior’, ‘posterior_predictive’, ‘log_likelihood’, ‘sample_stats’) into a single output, so groups must be specified if samples has groups from both sides. May only be given if samples is an xarray.DataTree.

Returns:

output – An single instance of the desired out_format is returned.

Return type:

various formats