derivkit.forecasting.getdist_dali_samples module#

Provides GetDist sampling helpers for DALI approximate posteriors.

This module converts DALI-expanded posteriors into GetDist-compatible getdist.MCSamples for plotting and analysis.

Two backends are provided:

  • Importance sampling using a Fisher-Gaussian kernel centered on theta0.

  • emcee ensemble MCMC targeting the same DALI log-posterior.

The target log-posterior is evaluated with derivkit.forecasting.expansions.logposterior_dali(), optionally including user-defined priors and parameter support bounds.

Note: GetDist’s loglikes field stores -log(posterior), not -log(likelihoods).

derivkit.forecasting.getdist_dali_samples.dali_to_getdist_emcee(theta0: ndarray[tuple[Any, ...], dtype[floating]], fisher: ndarray[tuple[Any, ...], dtype[floating]], g_tensor: ndarray[tuple[Any, ...], dtype[floating]], h_tensor: ndarray[tuple[Any, ...], dtype[floating]] | None, *, names: Sequence[str], labels: Sequence[str], n_steps: int = 10000, burn: int = 2000, thin: int = 2, n_walkers: int | None = None, init_scale: float = 0.5, convention: str = 'delta_chi2', seed: int | None = None, prior_terms: Sequence[tuple[str, dict[str, Any]] | dict[str, Any]] | None = None, prior_bounds: Sequence[tuple[float | None, float | None]] | None = None, logprior: Callable[[ndarray[tuple[Any, ...], dtype[floating]]], float] | None = None, sampler_bounds: Sequence[tuple[float | None, float | None]] | None = None, label: str = 'DALI (emcee)') MCSamples#

Returns getdist.MCSamples from emcee sampling of a DALI posterior.

The target log-posterior is evaluated with derivkit.forecasting.expansions.logposterior_dali(). Walkers are initialized from a Fisher–Gaussian cloud around theta0 and evolved with emcee.EnsembleSampler. Optional priors and support bounds are applied through the target log-posterior.

Parameters:
  • theta0 – Fiducial parameter vector with shape (p,) with p parameters.

  • fisher – Fisher matrix at theta0 with shape (p, p).

  • g_tensor – Third-order DALI tensor with shape (p, p, p).

  • h_tensor – Optional fourth-order DALI tensor with shape (p, p, p, p).

  • names – Parameter names used to label the returned samples (length p).

  • labels – LaTeX-formatted parameter labels used to label the returned samples (length p).

  • n_steps – Total number of MCMC steps.

  • burn – Number of initial MCMC steps discarded as burn-in, allowing the chain to forget its initial starting positions before samples are retained.

  • thin – Thinning factor applied after burn-in; only every thin-th sample is kept to reduce autocorrelation in the chain.

  • n_walkers – Number of walkers. Defaults to max(32, 8 * p).

  • init_scale – Initial scatter scale for walker initialization.

  • convention – DALI convention passed through to derivkit.forecasting.expansions.logposterior_dali().

  • seed – Random seed for walker initialization.

  • prior_terms – Optional prior term specifications used to build a prior via derivkit.forecasting.priors.core.build_prior(). Mutually exclusive with logprior. Can be combined with prior_bounds to truncate prior support.

  • prior_bounds – Optional per-parameter bounds passed to derivkit.forecasting.priors.core.build_prior() to truncate the prior support. If provided with no prior_terms, this corresponds to a bounded-uniform (top-hat) prior. A bounded-uniform prior is proper (normalizable), unlike an unbounded flat prior which is improper. Mutually exclusive with logprior.

  • logprior – Optional custom log-prior logprior(theta). Mutually exclusive with prior_terms/prior_bounds. If none of these are provided, a flat (typically improper) prior is used.

  • sampler_bounds – Optional per-parameter sampling-domain bounds used for early rejection and walker initialization.

  • label – Label attached to the returned samples output (e.g., used by GetDist in plot legends/titles).

Returns:

getdist.MCSamples containing MCMC chains. getdist.MCSamples.loglikes stores -log(posterior) (likelihoods x prior) up to an additive constant, consistent with GetDist’s convention.

Raises:
  • ValueError – If shapes are inconsistent, mutually exclusive options are provided, or the effective support bounds are invalid (e.g., an empty intersection).

  • RuntimeError – If walker initialization fails (no valid starting points).

derivkit.forecasting.getdist_dali_samples.dali_to_getdist_importance(theta0: ndarray[tuple[Any, ...], dtype[floating]], fisher: ndarray[tuple[Any, ...], dtype[floating]], g_tensor: ndarray[tuple[Any, ...], dtype[floating]], h_tensor: ndarray[tuple[Any, ...], dtype[floating]] | None, *, names: Sequence[str], labels: Sequence[str], n_samples: int = 50000, kernel_scale: float = 1.5, convention: str = 'delta_chi2', seed: int | None = None, prior_terms: Sequence[tuple[str, dict[str, Any]] | dict[str, Any]] | None = None, prior_bounds: Sequence[tuple[float | None, float | None]] | None = None, logprior: Callable[[ndarray[tuple[Any, ...], dtype[floating]]], float] | None = None, sampler_bounds: Sequence[tuple[float | None, float | None]] | None = None, label: str = 'DALI (importance)') MCSamples#

Returns getdist.MCSamples for a DALI posterior via importance sampling.

The target log-posterior is evaluated with derivkit.forecasting.expansions.logposterior_dali(). Samples are drawn from a Fisher–Gaussian kernel centered on theta0 and reweighted by the difference between the target log-posterior and the kernel log-density.

Parameters:
  • theta0 – Fiducial parameter vector with shape (p,) for p parameters.

  • fisher – Fisher matrix at theta0 with shape (p, p).

  • g_tensor – Third-order DALI tensor with shape (p, p, p).

  • h_tensor – Optional fourth-order DALI tensor with shape (p, p, p, p).

  • names – Parameter names used to label the returned samples (length p).

  • labels – LaTeX-formatted parameter labels used to label the returned samples (length p).

  • n_samples – Number of importance samples to draw.

  • kernel_scale – Scale factor applied to the Fisher covariance for the kernel.

  • convention – DALI convention passed through to derivkit.forecasting.expansions.logposterior_dali().

  • seed – Random seed for kernel sampling.

  • prior_terms – Optional prior term specifications used to build a prior via derivkit.forecasting.priors.core.build_prior(). Mutually exclusive with logprior. Can be combined with prior_bounds to truncate prior support.

  • prior_bounds – Optional per-parameter bounds passed to derivkit.forecasting.priors.core.build_prior() to truncate the prior support. If provided with no prior_terms, this corresponds to a bounded-uniform (top-hat) prior. A bounded-uniform prior is proper (normalizable), unlike an unbounded flat prior which is improper. Mutually exclusive with logprior.

  • logprior – Optional custom log-prior logprior(theta). Mutually exclusive with prior_terms/prior_bounds. If none of these are provided, a flat (typically improper) prior is used.

  • sampler_bounds – Optional per-parameter sampling-domain bounds used for early rejection and walker initialization.

  • label – Label attached to the returned samples output (e.g., used by GetDist in plot legends/titles).

Returns:

getdist.MCSamples containing the importance weights. getdist.MCSamples.loglikes stores -log(posterior) (likelihoods x prior) up to an additive constant, consistent with GetDist’s convention.

Raises:
  • ValueError – If shapes are inconsistent, mutually exclusive options are provided, or the effective support bounds are invalid (e.g., an empty intersection).

  • RuntimeError – If all samples are rejected by bounds or prior support.