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. An optional systematic bias shifts the mean.

  • 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[floating], fisher: NDArray[floating], *, bias: NDArray[floating] | None = None, 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).

  • bias – Optional Fisher systematic bias vector of shape (p,). Shifts the Gaussian mean by covariance @ bias.

  • 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. If bias is provided, the mean is shifted by covariance @ bias.

Raises:

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

derivkit.forecasting.getdist_fisher_samples.fisher_to_getdist_samples(theta0: NDArray[floating], fisher: NDArray[floating], *, names: Sequence[str], labels: Sequence[str], bias: NDArray[floating] | None = None, 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[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 centered at theta0 with covariance kernel_scale**2 * pinv(fisher). An optional systematic bias shifts the sampling mean by pinv(fisher) @ bias.

Samples can be truncated by hard bounds or prior support.

When requested, loglikes stores the negative log posterior, up to an additive constant:

-log p(theta|d) = 0.5 * delta.T @ F @ delta
                  - bias @ delta - logprior(theta) + C

where delta = theta - theta0 and F is the Fisher matrix. The bias and prior terms are omitted when not provided.

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).

  • bias – Optional Fisher systematic bias vector of shape (p,). Shifts the Gaussian sampling mean by pinv(fisher) @ bias and contributes to the stored negative log posterior.

  • 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.