spey.backends.default_pdf.DefaultPDFBase#
- class spey.backends.default_pdf.DefaultPDFBase(signal_yields: ndarray | Callable[[ndarray], ndarray], background_yields: ndarray, data: ndarray, covariance_matrix: ndarray | Callable[[ndarray], ndarray] = None, modifiers: List[Dict[str, Any]] | None = None, n_signal_parameters: int = 0, signal_parameter_bounds: List[Tuple[float | None, float | None]] | None = None)[source]#
Abstract base class shared by all default PDF backends.
This class handles the common infrastructure:
storing signal, background, and observed yields as
autograd-compatible arrays to enable automatic differentiation of the likelihood;constructing the
ModelConfigwith the minimum POI, suggested initialisations, and parameter bounds;computing the lower bound on the POI as
\[\mu_{\min} = -\min_{i:\,n^s_i>0} \frac{n^b_i}{n^s_i},\]which is the most negative signal strength for which no bin has negative expected yield;
providing default implementations of
get_objective_function(),get_logpdf_func(),get_hessian_logpdf_func(),get_sampler(), andexpected_data()that delegate to the per-subclassmain_modelandconstraint_modelproperties.
Subclasses must override
main_modelandconstraint_modelto supply the appropriate \(\lambda(\mu,\boldsymbol{\theta})\) function and constraint distribution.- Parameters:
signal_yields (
np.ndarray | Callable[[np.ndarray], np.ndarray]) –Per-bin signal yields \(\{n^s_i\}\), or a callable that accepts the extra signal parameters
pars[1 : 1 + n_signal_parameters]and returns the per-bin yields as anp.ndarray. When a callable is suppliedn_signal_parametersmust be set to the number of extra parameters the function expects.Note
When
signal_yieldsis callable the minimum POI is set to \(-\infty\) andmodifierscannot be used simultaneously.background_yields (
np.ndarray) – Per-bin expected background yields \(\{n^b_i\}\).data (
np.ndarray) – Per-bin observed counts \(\{n^{\rm obs}_i\}\).covariance_matrix (
np.ndarray | Callable | None) –Background covariance matrix \(\Sigma\). Diagonal elements are squared absolute uncertainties; off-diagonal elements encode inter-bin correlations. May be
Nonefor backends that do not use a covariance matrix (e.g.UncorrelatedBackground), or a callable that returns the matrix given an array of parameters.Warning
The diagonal entries must be squared absolute uncertainties, not standard deviations. For uncorrelated bins pass a diagonal matrix with \(\Sigma_{ii} = \sigma_i^2\).
modifiers (
List[Dict[str, Any]], defaultNone) –Optional list of signal-uncertainty modifier configuration dictionaries. Each dictionary must contain:
"type"(str, required): morphing mode, either"normalization"— one shared nuisance parameter for all bins (e.g. PDF uncertainties, luminosity);"shape"— one independent nuisance parameter per bin (e.g. scale uncertainties, theory prediction statistics).
"uncertainties"(List[float] | List[Tuple[float, float]], required): absolute uncertainty values per bin. Use a flatlist[float]for symmetric uncertainties, or alist[(up, down)]for asymmetric ones."name"(str, optional): label used for parameter naming; defaults to"mod0","mod1", …
Not supported when
signal_yieldsis a callable.Example:
modifiers = [ {"type": "normalization", "name": "pdf", "uncertainties": [0.6, 1.0]}, {"type": "shape", "name": "scale", "uncertainties": [(0.3, 0.4), (0.5, 0.6)]}, ]
n_signal_parameters (
int, default0) –Number of additional free parameters that a callable
signal_yieldsfunction accepts. These parameters are inserted into the parameter vector after \(\mu\) and before the background nuisance parameters:pars = [μ, sig_par_0, …, sig_par_{n-1}, θ_bkg_1, …, θ_bkg_N, θ_sig_1, …]Has no effect when
signal_yieldsis a plain array.signal_parameter_bounds (
List[Tuple[Optional[float], Optional[float]]] | None) – Optimiser bounds for each of then_signal_parametersextra signal parameters. Each entry is a(lower, upper)pair; useNonefor either element to leave that side unbounded. When the argument itself isNoneevery extra signal parameter receives(None, None). Must have exactlyn_signal_parametersentries when provided.
Note
All array inputs are immediately cast to
autograd.numpy.array()withdtype=float64so that the full parameter-space gradient and Hessian of the likelihood can be computed via automatic differentiation.- __init__(signal_yields: ndarray | Callable[[ndarray], ndarray], background_yields: ndarray, data: ndarray, covariance_matrix: ndarray | Callable[[ndarray], ndarray] = None, modifiers: List[Dict[str, Any]] | None = None, n_signal_parameters: int = 0, signal_parameter_bounds: List[Tuple[float | None, float | None]] | None = None)[source]#
Methods
__init__(signal_yields, background_yields, data)asimov_negative_loglikelihood([poi_test, ...])Compute the profiled negative log-likelihood at fixed \(\mu\) on Asimov data.
combine(other, **kwargs)Combine this statistical model with another backend instance.
config([allow_negative_signal, poi_upper_bound])Model configuration.
expected_data(pars[, include_auxiliary])Compute the expected data vector at the given parameter point.
get_hessian_logpdf_func([expected, data])Return a callable that evaluates the Hessian of \(\ln\mathcal{L}(\mu, \boldsymbol{\theta})\).
get_logpdf_func([expected, data])Return a callable that evaluates \(\ln\mathcal{L}(\mu, \boldsymbol{\theta})\).
get_objective_function([expected, data, do_grad])Return the objective function \(-\ln\mathcal{L}(\mu, \boldsymbol{\theta})\) used by the optimiser.
get_sampler(pars)Return a callable that draws pseudo-data from the statistical model.
minimize_asimov_negative_loglikelihood([...])Find the global minimum of the negative log-likelihood on Asimov data (free fit).
minimize_negative_loglikelihood([expected, ...])Find the global minimum of the negative log-likelihood (free fit).
negative_loglikelihood([poi_test, expected])Compute the profiled negative log-likelihood at a fixed \(\mu\).
Attributes
constraintsConstraints to be used during optimisation process
signal_uncertainty_configurationauthorAuthor of the backend
constraint_modelConstraint model distribution \(\mathcal{C}(\boldsymbol{\theta})\).
is_aliveReturns True if at least one bin has non-zero signal yield.
main_modelMain model distribution — the Poisson term of the likelihood.
nameName of the backend
spey_requiresSpey version required for the backend
versionVersion of the backend