Skip to main content

pyhf plugin for spey interface

Project description

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.

Project details


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.1.tar.gz (39.7 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.1-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

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

Hashes for spey_pyhf-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3415938fadf06fde944097a7c571e4d4bbf8cfd1740687154464f3d4c337214f
MD5 124d5fa9f26a7fe550445e55b22cbb73
BLAKE2b-256 6bf9058b7be5a1bf0c8fa5bac81f95a11073768c704845561647be51a29520b0

See more details on using hashes here.

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

Hashes for spey_pyhf-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4919afce0f6e4cab8d93a53b46bf889c07cf93fedeacb9cb314a00758ec92913
MD5 bbc4cbbdd930a7253ef848c3cc7433aa
BLAKE2b-256 cccf8e3d5ab879001ad4df2bdb906b559fec290e42c537506a7d189bd27ab267

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page