derivkit.forecasting.getdist_fisher_samples module#

Provides conversion helpers for Fisher–Gaussian forecasts and GetDist objects.

This module converts Fisher-matrix Gaussian approximations into GetDist-compatible representations for plotting and analysis.

Two outputs are supported:

  • An analytic Gaussian approximation via getdist.gaussian_mixtures.GaussianND with mean theta0 and covariance from the (pseudo-)inverse Fisher matrix.

  • Monte Carlo samples drawn from the Fisher Gaussian as getdist.MCSamples, with optional prior support hard bounds, and getdist.MCSamples.loglikes.

These helpers are intended for quick visualization (e.g. triangle plots) and simple prior truncation without running an MCMC sampler.

derivkit.forecasting.getdist_fisher_samples.fisher_to_getdist_gaussiannd(theta0: ndarray[tuple[Any, ...], dtype[floating]], fisher: ndarray[tuple[Any, ...], dtype[floating]], *, names: Sequence[str] | None = None, labels: Sequence[str] | None = None, label: str = 'Fisher (Gaussian)', rcond: float | None = None) GaussianND#

Returns getdist.gaussian_mixtures.GaussianND for the Fisher Gaussian.

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

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

  • names – Optional parameter names (length p). Defaults to ["p" + str(x) for x in range(len(theta0))].

  • labels – Optional parameter labels (length p). Defaults to ["p" + str(x) for x in range(len(theta0))].

  • label – Label attached to the returned object.

  • rcond – Cutoff passed to the Fisher (pseudo-)inverse when forming the covariance.

Returns:

A getdist.gaussian_mixtures.GaussianND with mean theta0 and covariance from fisher.

Raises:

ValueError – If names/labels lengths do not match p.

derivkit.forecasting.getdist_fisher_samples.fisher_to_getdist_samples(theta0: ndarray[tuple[Any, ...], dtype[floating]], fisher: ndarray[tuple[Any, ...], dtype[floating]], *, names: Sequence[str], labels: Sequence[str], n_samples: int = 30000, seed: int | None = None, kernel_scale: float = 1.0, 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, hard_bounds: Sequence[tuple[float | None, float | None]] | None = None, store_loglikes: bool = True, label: str = 'Fisher (samples)') MCSamples#

Draws samples from the Fisher Gaussian as getdist.MCSamples.

Samples are drawn from a multivariate Gaussian with mean theta0 and covariance kernel_scale**2 * pinv(fisher). Optionally, samples are truncated by hard bounds and/or by a prior (via logprior or prior_terms/prior_bounds).

GetDist stores getdist.MCSamples.loglikes as -log(posterior) up to an additive constant. When store_loglikes=True, this function stores:

-log p(theta|d) = 0.5 * (theta-theta0)^T F (theta-theta0) - logprior(theta) + C

where C is an arbitrary additive constant and F defines the Fisher-Gaussian approximation to -log(likelihoods) around theta0. In this implementation, C is effectively zero since no additional shifting is applied. If no prior is provided, the prior term is omitted.

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

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

  • names – Parameter names (length p).

  • labels – Parameter labels (length p).

  • n_samples – Number of samples to draw.

  • seed – Random seed.

  • kernel_scale – Multiplicative scale applied to the Gaussian covariance.

  • prior_terms – Optional prior term specifications used to build a prior. Can be provided with or without prior_bounds.

  • prior_bounds – Optional bounds used to truncate prior support. Can be provided with or without prior_terms.

  • logprior – Custom log-prior callable. Mutually exclusive with prior_terms/prior_bounds.

  • hard_bounds – Hard bounds applied by rejection (samples outside are dropped). Mutually exclusive with encoding support via prior_terms/prior_bounds.

  • store_loglikes – If True, compute and store getdist.MCSamples.loglikes.

  • label – Label for the returned getdist.MCSamples.

Returns:

getdist.MCSamples containing the retained samples and optional getdist.MCSamples.loglikes.

Raises:
  • ValueError – If n_samples is non-positive, if names or labels have incorrect length, or if mutually exclusive options are provided.

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