derivkit.forecast_kit module#

Provides the ForecastKit class.

A light wrapper around the core forecasting utilities (derivkit.forecasting.fisher.build_fisher_matrix(), derivkit.forecasting.dali.build_dali(), derivkit.forecasting.fisher.build_delta_nu(), and derivkit.forecasting.fisher.build_fisher_bias()) that exposes a simple API for Fisher and DALI tensors.

Typical usage example:

>>> import numpy as np
>>> from derivkit import ForecastKit
>>>
>>> # Toy linear model: 2 params -> 2 observables
>>> def model(theta: np.ndarray) -> np.ndarray:
...     theta = np.asarray(theta, dtype=float)
...     return np.array([theta[0] + 2.0 * theta[1], 3.0 * theta[0] - theta[1]], dtype=float)
>>>
>>> theta0 = np.array([0.1, -0.2])
>>> cov = np.eye(2)
>>>
>>> fk = ForecastKit(function=model, theta0=theta0, cov=cov)
>>> fisher_matrix = fk.fisher(method="finite", n_workers=1)
>>> fisher_matrix.shape
(2, 2)
>>> dali = fk.dali(forecast_order=2, method="finite", n_workers=1)
>>> F = dali[1][0]
>>> D1, D2 = dali[2]
>>>
>>> data_unbiased = model(theta0)
>>> data_biased = data_unbiased + np.array([1e-3, -2e-3])
>>> dn = fk.delta_nu(data_unbiased=data_unbiased, data_biased=data_biased)
>>> dn.shape
(2,)
>>>
>>> bias_vec, delta_theta = fk.fisher_bias(
...     fisher_matrix=fisher_matrix,
...     delta_nu=dn,
...     method="finite",
...     n_workers=1,
... )
>>> bias_vec.shape, delta_theta.shape
((2,), (2,))