pyhf plugin for spey interface
Project description
spey-pyhf
About
spey-pyhf is a pyhf plug-in for the spey statistical inference interface. It exposes pyhf's full likelihood-building machinery — including HistFactory-style JSON workspaces and signal patches — through Spey's backend-agnostic API, so any analysis that ships a pyhf likelihood can be consumed by Spey alongside other backends. Once installed, Spey automatically detects the plug-in and registers three backends: pyhf (full statistical model from a background-only workspace plus a signal patch), pyhf.uncorrelated_background (a lightweight uncorrelated-background helper) and pyhf.simplify (workspace simplification).
Installation
The plug-in is published on PyPI and can be installed with:
python -m pip install spey-pyhf
To install directly from the main branch:
python -m pip install --upgrade "git+https://github.com/SpeysideHEP/spey-pyhf"
Note that the main branch may not be the stable version.
Quick example
Given a pyhf background-only workspace and a signal patch, you can build a Spey statistical model and compute the exclusion confidence level in a few lines:
import spey
background_only = {
"channels": [
{
"name": "singlechannel",
"samples": [
{
"name": "background",
"data": [50.0, 52.0],
"modifiers": [
{"name": "uncorr_bkguncrt", "type": "shapesys", "data": [3.0, 7.0]}
],
}
],
}
],
"observations": [{"name": "singlechannel", "data": [51.0, 48.0]}],
"measurements": [{"name": "Measurement", "config": {"poi": "mu", "parameters": []}}],
"version": "1.0.0",
}
signal_patch = [
{
"op": "add",
"path": "/channels/0/samples/1",
"value": {
"name": "signal",
"data": [12.0, 11.0],
"modifiers": [{"name": "mu", "type": "normfactor", "data": None}],
},
}
]
wrapper = spey.get_backend("pyhf")
model = wrapper(
analysis="simple_pyhf",
background_only_model=background_only,
signal_patch=signal_patch,
)
print(model.exclusion_confidence_level()) # [0.9474850259721279]
Because Spey is fully backend-agnostic, every method of spey.StatisticalModel (likelihood scans, upper limits, combinations, etc.) works the same way on top of pyhf. For the full API and tutorials, see the online documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spey_pyhf-0.2.1.tar.gz.
File metadata
- Download URL: spey_pyhf-0.2.1.tar.gz
- Upload date:
- Size: 39.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3415938fadf06fde944097a7c571e4d4bbf8cfd1740687154464f3d4c337214f
|
|
| MD5 |
124d5fa9f26a7fe550445e55b22cbb73
|
|
| BLAKE2b-256 |
6bf9058b7be5a1bf0c8fa5bac81f95a11073768c704845561647be51a29520b0
|
File details
Details for the file spey_pyhf-0.2.1-py3-none-any.whl.
File metadata
- Download URL: spey_pyhf-0.2.1-py3-none-any.whl
- Upload date:
- Size: 35.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4919afce0f6e4cab8d93a53b46bf889c07cf93fedeacb9cb314a00758ec92913
|
|
| MD5 |
bbc4cbbdd930a7253ef848c3cc7433aa
|
|
| BLAKE2b-256 |
cccf8e3d5ab879001ad4df2bdb906b559fec290e42c537506a7d189bd27ab267
|