Skip to main content

spey-pyhf

arxiv DOI DOI doc

Spey logo

github PyPI - Version Documentation Status GitHub License codecov

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spey_pyhf-0.2.2.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spey_pyhf-0.2.2-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file spey_pyhf-0.2.2.tar.gz.

File metadata

  • Download URL: spey_pyhf-0.2.2.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for spey_pyhf-0.2.2.tar.gz
Algorithm Hash digest
SHA256 43f44bcc7bb045b74c9b40d914d30f38f29c160e580d50c4aa7148916f23c97f
MD5 472f0bc927efe445e84a7f22febff8ac
BLAKE2b-256 bc4e70c959f99a38ec9f1b3336c9799a4c324e7bd2f9e86cdff93eef0434d4c1

See more details on using hashes here.

File details

Details for the file spey_pyhf-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: spey_pyhf-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for spey_pyhf-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a52c3da2c09253d1b79596abcc06b300bc85d66baae50e98e45bb42e0eb7bcf1
MD5 8051827487951f68192e54bdfa3bd5f2
BLAKE2b-256 491db7f7fd364f756d4fc372792be4e857831d5ed64259ac02dbfb035652baad

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.1

2 files

0.2.0

1 file

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page