Statisical Model Plugins for Spey
Various likelihood plugins for Spey. The package is named after the Strathisla, the Speyside distillery.
Available models:
FullNuisanceParameters: Poisson likelihood with nuisance parameters on the signal, background and data.SimpleMultivariateGaussianEFT: Multivariate Gaussian likelihood with no nuisance parameters. Two signal inputs: the first scales linearly with the parameter of interest, the second quadratically.MultivariateGaussianCovarianceScaledEFT: As above, but the signal covariance matrices are scaled by the parameter of interest
Installation
To use these plugins with Spey:
- (Optional) Setup a virtual environment
python -m venv spey_venv
source spey_venv/bin/activate
pip install spey
- Clone this repo
git@github.com:joes-git/strathisla.git
- Add this repo to your environment
cd strathisla
pip install -e .
- Check the plugins are available in Spey
import spey
installed_plugins = [
'strathisla.full_nuisance_parameters',
'strathisla.simple_multivariate_gaussian_eft',
'strathisla.multivariate_gaussian_scaled_covariance_eft'
]
print(all(plugin in spey.AvailableBackends() for plugin in installed_plugins))
# True
FullNuisanceParameters
From equation 8 of arXiv:2102.04377, this is the likelihood for a histogram with $i$ bins and covariance matrices ($\Sigma$) for the signal ($s$), background ($b$) and data ($n$) yields. This likelihood has the following form:
$$ L(\mu, \theta) = \prod_{i \in {\rm bins}} {\rm Poiss} (n_i \vert \mu s_i+b_i + \sum_{j \in n,s,b} \theta_i^{(j)} \sigma_i^{(j)}) \prod_{j \in n,s,b} {\rm Gauss}(\theta^{(j)}|0,\Sigma^{(j)}) $$
where $\mu$ is the parameter of interest, and $\theta$ are nuisance parameters.
Example
import spey
import numpy as np
data = np.array([30, 35, 40])
signal_yields = np.array([8.0, 10.0, 12.0])
background_yields = np.array([25.0, 28.0, 32.0])
signal_covariance = np.array([[1.0, 0.2, 0.1],
[0.2, 1.5, 0.3],
[0.1, 0.3, 2.0]])
background_covariance = np.array([[16.0, 4.0, 2.0],
[4.0, 25.0, 5.0],
[2.0, 5.0, 36.0]])
data_covariance = np.array([[30.0,2.0,0.5],
[4.3, 35.0, 9.0],
[6.2, 13.0, 40.0]])
backend = spey.get_backend("strathisla.full_nuisance_parameters")
stat_model = backend(
signal_yields=signal_yields,
background_yields=background_yields,
data=data,
signal_covariance=signal_covariance,
background_covariance=background_covariance,
data_covariance=data_covariance
)
CLs = stat_model.exclusion_confidence_level()[0]
print(CLs)
SimpleMultivariateGaussianEFT
Simple multivariate Gaussian likelihood (no nuisance parameters) for a histogram with $i$ correlated bins and two signal contributions: A term $s_{\text{lin}}$ with scales linearly with the signal strength $\mu$, and a term $s_{\text{quad}}$, which scales with $\mu^2$. The form of this likelihood is:
$$ L(\mu) = \frac{1}{\sqrt{(2\pi)^k \det(\Sigma)}} \exp \left( -\frac{1}{2} (\mu^2 s_{\text{quad}} + \mu s_{\text{lin}} + b - n)^{\text{T}} \Sigma^{-1} (\mu^2 s_{\text{quad}} + \mu s_{\text{lin}} + b - n) \right), $$
where $\Sigma$ is the covariance matrix, $b$ is the background and $n$ is the data.
Example
import spey
import numpy as np
quadratic_term = np.array([9.908565e-04, 1.082060e-02, 4.402903e-02])
linear_term = np.array([0.00045349, 0.00304028, 0.0090483])
background = np.array([0.25291, 0.59942, 1.52996])
data = np.array([0.2325, 0.5385, 1.25734])
covariance = np.array([
[0.06427483, 0.05824, 0.01225],
[0.05824, 0.06694904, 0.01207],
[0.01225, 0.01207, 0.02126036]])
backend = spey.get_backend("strathisla.simple_multivariate_gaussian_eft")
stat_model = backend(
quadratic_term=quadratic_term,
linear_term=linear_term,
background=background,
data=data,
covariance=covariance
)
CLs = stat_model.exclusion_confidence_level()
print(CLs[0])
MultivariateGaussianCovarianceScaledEFT
The multivariante Gaussian likelihood above, but the signal contributions to the covariance matrix are scaled by the parameter of interest as:
$$ \Sigma(\mu) = \mu^4 \Sigma_{\text{quad}} + \mu^2 \Sigma_{\text{lin}} + \Sigma_b + \Sigma_n $$
Example
import spey
import numpy as np
quadratic_term = np.array([9.908565e-04, 1.082060e-02, 4.402903e-02])
linear_term = np.array([0.00045349, 0.00304028, 0.0090483])
background = np.array([0.25291, 0.59942, 1.52996])
data = np.array([0.2325, 0.5385, 1.25734])
covariance = np.array([
[0.06427483, 0.05824, 0.01225],
[0.05824, 0.06694904, 0.01207],
[0.01225, 0.01207, 0.02126036]])
background_covariance = np.zeros_like(covariance) # assume 'covariance' has both data and background
quadratic_term_covariance = np.diag([1.42421005e-07, 8.57147040e-07, 1.99661509e-06])
linear_term_covariance = np.diag([3.60939969e-08, 4.65573038e-07, 9.61593099e-07])
backend = spey.get_backend("strathisla.multivariate_gaussian_scaled_covariance_eft")
stat_model = backend(
quadratic_term=quadratic_term,
linear_term=linear_term,
background=background,
data=data,
data_covariance=covariance,
background_covariance=background_covariance,
quadratic_term_covariance=quadratic_term_covariance,
linear_term_covariance=linear_term_covariance
)
CLs = stat_model.exclusion_confidence_level()
print(CLs[0])
Metadata
Release files for strathisla 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| strathisla-1.0.0.tar.gz | 15.8 kB | Without provenance | Details for strathisla-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| strathisla-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for strathisla-1.0.0-py3-none-any.whl |
Total release size: 29.5 kB
Release files / strathisla-1.0.0.tar.gz
| Download URL | strathisla-1.0.0.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6c14755ff9b08c9330d7455ee6f1da967ceb5087e918077d7649f9e8cf21559
|
|
BLAKE2b-256 checksum How to use checksums |
89c5039f6507d5a42d415495de3847100ff4a2c281063b690cc65a3fbed5baf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / strathisla-1.0.0-py3-none-any.whl
| Download URL | strathisla-1.0.0-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b588f135f94aa1eb4ad49da83b20fed42e696ed44ea45a24988582cf6d4a3ad9
|
|
BLAKE2b-256 checksum How to use checksums |
c00199a88af83b97dda010d1a5039a46fec5f91a3c8b5c61838a0ec27a1febc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for strathisla 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.