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.GaussianNDwith meantheta0and covariance from the (pseudo-)inverse Fisher matrix.Monte Carlo samples drawn from the Fisher Gaussian as
getdist.MCSamples, with optional prior support hard bounds, andgetdist.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.GaussianNDfor the Fisher Gaussian.- Parameters:
theta0 – Fiducial parameter vector with shape
(p,)withpparameters.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.GaussianNDwith meantheta0and covariance fromfisher.- Raises:
ValueError – If
names/labelslengths do not matchp.
- 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
theta0and covariancekernel_scale**2 * pinv(fisher). Optionally, samples are truncated by hard bounds and/or by a prior (vialogpriororprior_terms/prior_bounds).GetDist stores
getdist.MCSamples.loglikesas-log(posterior)up to an additive constant. Whenstore_loglikes=True, this function stores:-log p(theta|d) = 0.5 * (theta-theta0)^T F (theta-theta0) - logprior(theta) + C
where
Cis an arbitrary additive constant andFdefines the Fisher-Gaussian approximation to-log(likelihoods)aroundtheta0. In this implementation,Cis 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,)withpparameters.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 storegetdist.MCSamples.loglikes.label – Label for the returned
getdist.MCSamples.
- Returns:
getdist.MCSamplescontaining the retained samples and optionalgetdist.MCSamples.loglikes.- Raises:
ValueError – If
n_samplesis non-positive, ifnamesorlabelshave incorrect length, or if mutually exclusive options are provided.RuntimeError – If all samples are rejected by bounds or prior support.