derivkit.forecasting.forecast_core module#
Core utilities for likelihoods-based forecasts.
This module provides functional helpers to
compute model derivatives through fourth order with respect to its parameters, and
build Fisher and DALI forecast tensors through fourth derivative order from those derivatives and a covariance matrix.
These functions are the low-level building blocks used by higher-level forecasting interfaces in DerivKit. For details on the DALI expansion, see e.g. https://doi.org/10.1103/PhysRevD.107.103506.
- derivkit.forecasting.forecast_core.SUPPORTED_FORECAST_ORDERS = (1, 2, 3, 4)#
The supported orders of the DALI expansion.
A value of 1 corresponds to the Fisher matrix. A value of 2 corresponds to the DALI doublet. A value of 3 corresponds to the DALI triplet. A value of 4 corresponds to the DALI quadruplet.
- derivkit.forecasting.forecast_core.get_forecast_tensors(function: Callable[[Sequence[float] | NDArray[floating]], float | NDArray[floating]], theta0: Sequence[float] | NDArray[floating], cov: Sequence[Sequence[float]] | NDArray[floating], *, forecast_order: int = 1, method: str | None = None, symmetrize_dali: bool = True, n_workers: int = 1, **dk_kwargs: Any) dict[int, tuple[NDArray[float64], ...]]#
Returns a set of tensors according to the requested order of the forecast.
- Parameters:
function – The scalar or vector-valued function to differentiate. It should accept a list or array of parameter values as input and return either a scalar or a
np.ndarrayof observable values.theta0 – The points at which the derivative is evaluated. A 1D array or list of parameter values matching the expected input of the function.
cov – The covariance matrix of the observables. Should be a square matrix with shape
(n_observables, n_observables), wheren_observablesis the number of observables returned by the function.forecast_order – The requested order of the forecast. Currently supported values and their meaning are given in
SUPPORTED_FORECAST_ORDERS.method – Method name or alias (e.g.,
"adaptive","finite"). IfNone, thederivkit.derivative_kit.DerivativeKitdefault ("adaptive") is used.symmetrize_dali – If set to
True, fully symmetrize each DALI tensor over its axes. IfFalse, return the raw derivative contractions.n_workers – Number of workers for per-parameter parallelization/threads. Default
1(serial). Inner batch evaluation is kept serial to avoid nested pools.**dk_kwargs – Additional keyword arguments passed to
derivkit.derivative_kit.DerivativeKit.differentiate.
- Returns:
A dict mapping
order -> tensorsfor allorder = 1..forecast_order.The tensors are grouped by the forecast order at which they first appear:
order 1:
(F,)order 2:
(D_{(2,1)}, D_{(2,2)})order 3:
(T_{(3,1)}, T_{(3,2)}, T_{(3,3)})order 4:
(Qa_{(4,1)}, Qa_{(4,2)}, Qa_{(4,3)}, Qa_{(4,4)})
Here
D_{(k,l)},T_{(k,l)}, andQa_{(k,l)}denote tensors obtained by contracting thek-th order derivative with thel-th order derivative via the inverse covariance.Each tensor axis has length
p = len(theta0). Shapes are:F:(p, p)D_{(2,1)}:(p, p, p)D_{(2,2)}:(p, p, p, p)T_{(3,1)}:(p, p, p, p)T_{(3,2)}:(p, p, p, p, p)T_{(3,3)}:(p, p, p, p, p, p)Q_{(4,1)}:(p, p, p, p, p)Q_{(4,2)}:(p, p, p, p, p, p)Q_{(4,3)}:(p, p, p, p, p, p, p)Q_{(4,4)}:(p, p, p, p, p, p, p, p)
- Raises:
ValueError – If
forecast_orderis not inSUPPORTED_FORECAST_ORDERS.- Warns:
RuntimeWarning – If
covis not symmetric (proceeds as-is, no symmetrization), is ill-conditioned (large condition number), or inversion falls back to the pseudoinverse.