Plug-ins#
Keyword |
Summary |
|---|---|
|
Combination of Poisson and Gaussian PDF, assuming uncorrelated bins. |
|
Combination of Poisson and Gaussian PDF, with correlated bins. |
|
Simplified likelihood, extended with third moments of the background. |
|
Simplified likelihood, extended with asymmetric uncertainties. |
|
|
|
|
|
|
|
External plug-in uses |
|
External plug-in constructs |
|
See doc. converts full |
|
EFT plug-in provides tools for full modeling of nuisance parameters and setting limits on Effective Field Theories. By Joe Egan. |
Spey seamlessly integrates with diverse packages that offer specific statistical model prescriptions. Its primary objective is to centralise these prescriptions within a unified interface, facilitating the combination of different likelihood sources. This section will overview the currently available plugins accessible through the Spey interface. The string-based accessors to the available plugins can be seen using the following command:
>>> spey.AvailableBackends()
>>> # ['default.correlated_background',
>>> # 'default.effective_sigma',
>>> # 'default.third_moment_expansion',
>>> # 'default.uncorrelated_background']
where once installed without any plug-ins AvailableBackends() function
only shows the default PDFs. In the following section, we will summarise their usability.
Once we know the accessor of the plug-in, it can be called using get_backend()
function e.g.
>>> pdf_wrapper = spey.get_backend('default.uncorrelated_background')
this will automatically create a wrapper around the likelihood prescription and allow spey to use it properly. We will demonstrate the usage for each of the default plugins below.
Note
Documentation of each plug-in has been included within the pdf_wrapper documentation.
Hence, if one types pdf_wrapper? in the ipython command line or a jupyter notebook, it is
possible to access the extended documentation for both the wrapper and the backend in use.
Attention
get_backend() function is a wrapper between the PDF prescription and spey package.
Once initialised, all PDF prescriptions are defined with StatisticalModel class
which provides a backend agnostic interface, i.e. all PDF prescriptions will have the same functionality.
Default Plug-ins#
All default plug-ins are defined using the following main likelihood structure
Main model term \(\mathcal{M}\): Describes how the signal hypothesis affects the observed event counts in each bin. Typically a Poisson or Gaussian distribution where the expected mean depends on both the signal strength \(\mu\) and nuisance parameters \(\theta\).
Constraint model term \(\mathcal{C}\): Encodes our prior knowledge of systematic uncertainties through Gaussian or multivariate distributions on the nuisance parameters. These constraints prevent the fit from indefinitely adjusting nuisances to arbitrarily improve the likelihood.
'default.third_moment_expansion'#
This plug-in implements the third-moment expansion from [3], which captures non-Gaussian (asymmetric) effects in the background distribution. When background distributions are skewed, this method provides better likelihood estimates than the quadratic approximation (Gaussian constraint).
The likelihood structure is
Mathematical interpretation: Instead of the nominal background estimate \(n_b^i\) with a linear uncertainty \(\theta^i \sigma_b^i\), the model expands to include a quadratic term \(S_i\theta_i^2\) to capture skewness. The coefficients are:
\(\bar{n}_b^i\): Shifted nominal background (accounts for skewness)
\(B_i\): Linear coefficient (analogous to standard deviation)
\(S_i\): Quadratic coefficient (encodes the skewness/third moment)
The multivariate Gaussian constraint \(\mathcal{N}(\theta|0, \rho)\) now has a correlation structure \(\rho\) that is computed from the full third-moment tensor to maintain consistency.
where \(\bar{n}_b^i,\ B_i,\ S_i\) and \(\rho\) are defined as:
iterating over the same example, this PDF can be accessed as follows
1>>> pdf_wrapper = spey.get_backend("default.third_moment_expansion")
2>>> statistical_model = pdf_wrapper(
3... signal_yields=[12.0, 15.0],
4... background_yields=[50.0,48.0],
5... data=[36, 33],
6... covariance_matrix=[[144.0,13.0], [25.0, 256.0]],
7... third_moment=[0.5, 0.8],
8... analysis="example",
9... xsection=0.123,
10... )
and the exclusion limit, as before, can be computed as follows
>>> statistical_model.exclusion_confidence_level()
>>> # [0.9614329616396733]
As can be seen from the result, slight skewness generated by the third moment presented in the function reduced the exclusion limit.
Arguments:
signal_yields: keyword for signal yields. It can take one or more values as a list or NumPy array.
background_yields: keyword for background-only expectations. It can take one or more values as a list or NumPy array.
data: keyword for observations. It can take one or more values as a list or NumPy array.
covariance_matrix: Covariance matrix which captures the correlations and absolute uncertainty values of the background hypothesis. For absolute uncertainty \(\sigma_b\); \(\sigma_b = \sqrt{{\rm diag}(\Sigma)}\). The covariance matrix should be a square matrix and both dimensions should match the number ofbackground_yieldsgiven as input.
third_moment: Diagonal elements of the third moments. These can be computed usingcompute_third_moments()function; however this function computes third moments using Bifurcated Gaussian, which may not be suitable for every case.
analysis(optional): Unique identifier for the analysis.
xsection(optional): Cross-section value for the signal hypothesis. Units determined by the user.
'default.effective_sigma'#
The skewness of the PDF distribution can also be captured by building an effective (theta-dependent) variance from the asymmetric upper (\(\sigma^+\)) and lower (\(\sigma^-\)) uncertainty envelopes, originally proposed in [4]. This method provides a simpler alternative to the third-moment expansion.
The effective uncertainty is
Physical interpretation: - When \(\theta^i = 0\) (nominal), \(\sigma_{\rm eff}^i(0) = \sqrt{\sigma^+_i\sigma^-_i}\) is the geometric mean - For \(\theta^i > 0\) (upward fluctuation), the effective uncertainty smoothly increases toward \(\sigma^+_i\) - For \(\theta^i < 0\) (downward fluctuation), it smoothly increases toward \(\sigma^-_i\) - This naturally captures asymmetric uncertainties without introducing explicit quadratic terms
The Poisson model is generalized as
where the expected count in bin \(i\) depends on both the nuisance parameter \(\theta^i\) and the effective uncertainty \(\sigma_{\rm eff}^i(\theta^i)\). The correlation matrix \(\rho\) encodes correlations between bins’ nuisance parameters.
This PDF can be utilised as follows:
1>>> pdf_wrapper = spey.get_backend("default.effective_sigma")
2>>> statistical_model = pdf_wrapper(
3... signal_yields=[12.0, 15.0],
4... background_yields=[50.0,48.0],
5... data=[36, 33],
6... correlation_matrix=[[1., 0.06770833], [0.13020833, 1.]],
7... absolute_uncertainty_envelops=[(10., 15.), (13., 18.)],
8... analysis="example",
9... xsection=0.123,
10... )
where absolute_uncertainty_envelops refers to each bin’s upper and lower uncertainty envelopes.
Once again, the exclusion limit can be computed as
>>> statistical_model.exclusion_confidence_level()
>>> # [0.8567802529243093]
Arguments:
signal_yields: keyword for signal yields. It can take one or more values as a list or NumPy array.
background_yields: keyword for background-only expectations. It can take one or more values as a list or NumPy array.
data: keyword for observations. It can take one or more values as a list or NumPy array.
correlation_matrix: The correlation matrix should be a square matrix, and both dimensions should match the number ofbackground_yieldsgiven as input. If only the covariance matrix is available, one can usecovariance_to_correlation()function to convert the covariance matrix to a correlation matrix.
absolute_uncertainty_envelops: This is a list of upper and lower uncertainty envelops where the first element of each input should be the upper uncertainty, and the second element should be the lower uncertainty envelop, e.g., for background given as \({n_b}_{-\sigma^-}^{+\sigma^+}\) the input should be [(\(|\sigma^+|\), \(|\sigma^-|\))].
analysis(optional): Unique identifier for the analysis.
xsection(optional): Cross-section value for the signal hypothesis. Units determined by the user.
'default.poisson'#
Simple Poisson implementation without any systematic uncertainties or nuisance parameters. This is the simplest likelihood model, appropriate when background yields are known with negligible uncertainty.
When to use: This model is appropriate when: - Background yields are precisely known from Monte Carlo or sideband measurements with negligible uncertainty - The analysis is limited by statistical fluctuations in the data, not systematic uncertainties - Simplicity is valued over accounting for all sources of uncertainty
The likelihood depends only on the signal strength \(\mu\) and the fixed background \(n_b^i\). Each bin’s observation follows a Poisson distribution with mean \(\lambda_i = \mu n_s^i + n_b^i\). It can accommodate any number of bins.
1>>> pdf_wrapper = spey.get_backend("default.poisson")
2>>> statistical_model = pdf_wrapper(
3... signal_yields=[12.0, 15.0],
4... background_yields=[50.0,48.0],
5... data=[36, 33],
6... analysis="example",
7... xsection=0.123,
8... )
Arguments:
signal_yields: keyword for signal yields. It can take one or more values as a list or NumPy array.
background_yields: keyword for background-only expectations. It can take one or more values as a list or NumPy array.
data: keyword for observations. It can take one or more values as a list or NumPy array.
analysis(optional): Unique identifier for the analysis.
xsection(optional): Cross-section value for the signal hypothesis. Units determined by the user.
'default.normal'#
Simple univariate Gaussian likelihood without nuisance parameters. Each bin is treated as a normally distributed random variable.
When to use: This model is appropriate when: - Event counts are large enough that the Poisson distribution is well-approximated by a Gaussian (large-N limit) - Bin yields are treated as continuous rather than discrete quantities - Background uncertainties are symmetric and well-described by a single absolute uncertainty \(\sigma^i\) - No correlated uncertainties between bins (use multivariate_normal if correlations exist)
Mathematical details: For each bin, the observation \(n^i\) is normally distributed with: - Mean: \(\mu n_s^i + n_b^i\) (signal-plus-background prediction) - Standard deviation: \(\sigma^i\) (absolute uncertainty on the background)
The log-likelihood is the sum of Gaussian log-pdfs across bins. Each bin’s contribution is independent. It can accommodate any number of yields.
1>>> pdf_wrapper = spey.get_backend("default.normal")
2>>> statistical_model = pdf_wrapper(
3... signal_yields=[12.0, 15.0],
4... background_yields=[50.0,48.0],
5... data=[36, 33],
6... absolute_uncertainties=[20.0, 10.0],
7... analysis="example",
8... xsection=0.123,
9... )
Arguments:
signal_yields: keyword for signal yields. It can take one or more values as a list or NumPy array.
background_yields: keyword for background-only expectations. It can take one or more values as a list or NumPy array.
data: keyword for observations. It can take one or more values as a list or NumPy array.
absolute_uncertainties: absolute uncertainties on the background
analysis(optional): Unique identifier for the analysis.
xsection(optional): Cross-section value for the signal hypothesis. Units determined by the user.
'default.multivariate_normal'#
Multivariate Gaussian likelihood that accounts for correlations between bin measurements. This is the proper extension of the univariate normal backend when bin observations are correlated.
Where: - \(k\) is the number of bins - \(\mathbf{n}_s, \mathbf{n}_b, \mathbf{n}\) are vectors of signal yields, background yields, and observations - \(\Sigma\) is the \(k \times k\) covariance matrix encoding both bin variances (diagonal) and correlations (off-diagonal elements)
When to use: This model is appropriate when: - Bin measurements are correlated (e.g., from a simultaneous fit to multiple channels or detector regions) - The uncertainty structure cannot be factorised into independent components - You have a full covariance matrix from your analysis
Mathematical details: The joint distribution is a multivariate Gaussian with: - Mean: \(\mu \mathbf{n}_s + \mathbf{n}_b\) - Covariance: \(\Sigma\)
The log-likelihood involves inverting the covariance matrix and computing the Mahalanobis distance. It can accommodate any number of yields, though the inversion of \(\Sigma\) becomes numerically expensive for very high dimensions.
1>>> pdf_wrapper = spey.get_backend("default.multivariate_normal")
2>>> statistical_model = pdf_wrapper(
3... signal_yields=[12.0, 15.0],
4... background_yields=[50.0,48.0],
5... data=[36, 33],
6... covariance_matrix=[[144.0,13.0], [25.0, 256.0]],
7... analysis="example",
8... xsection=0.123,
9... )
Arguments:
signal_yields: keyword for signal yields. It can take one or more values as a list or NumPy array.
background_yields: keyword for background-only expectations. It can take one or more values as a list or NumPy array.
data: keyword for observations. It can take one or more values as a list or NumPy array.
covariance_matrix: covariance matrix (square matrix)
analysis(optional): Unique identifier for the analysis.
xsection(optional): Cross-section value for the signal hypothesis. Units determined by the user.
External Plug-ins#
Useful links:
Spey-strathisla GitHub Repository: Provides external plugins suitable for a. full modelling of nuisance parameters and b. setting limits on Effective Field Theories.
spey-fastprof: TBA [6].