Skip to main content

Produce simplified likelihoods of different formats

Project description

simplify

CI status codecov PyPI version python version Code style: black

A package that creates simplified likelihoods from full likelihoods. Method documented in ATLAS PUB Note (currently internal access) and in chapter 10 of my PhD thesis. Currently, only one format is implemented for simplified likelihoods, but the idea is to support additional forms of (not so) simplified likelihoods.

Table of contents

  1. Introduction
  2. Installation
  3. How To Run
  4. Example Likelihood

Introduction

In high energy physics (HEP), searches for new physics are typically interested in making inferences about a probabilistic model given some observed collision data. This approach can be formalised using a statistical model f(x|φ), i.e. a parametric family of probability density functions (PDFs) describing the probability of observing data x given some model parameters φ. The likelihood function L(φ) then referrs to the value of f as a function of φ given fixed x.

For binned data, the HistFactory template for building statistical models and likelihoods finds ample usage in HEP.

Although many searches for supersymmetry (SUSY) are sensitive to a variety of beyond the Standard Model (BSM) physics models, for reasons of computational cost and complexity they are often only interpreted in a limited set of simplified models. While statistical inference and interpretation of limits on individual SUSY production and decay topologies is straightforward and very convenient, their lack of model complexity leads to poor approximations to the true underlying constraints on the respective model parameters of a more complete SUSY model. In order to investigate realistic SUSY scenarios, large-scale re-interpretation efforts scanning a large number of dimensions is needed, resulting in a significant increase in computational cost for the statistical inference.

The approximation method put forward in ATLAS PUB Note and implemented in this repository introduces the notion of simplified likelihoods that come with low computational cost but high statistical precision, therefore offering a viable solution for large-scale re-interpretation efforts over large model spaces.

Installation

Follow good practice and start by creating a virtual environment

python3 -m venv simplify

and then activating it

source simplify/bin/activate

Default installation from pip

You can install simplify directly from pip with

python3 -m pip install simplify[contrib]

Notice that simplify is supported and tested for python 3.7 and python 3.8.

Development installation

If you want to contribute to simplify, install the development version of the package. Fork the repository, clone your fork, and then install from local resources with

python3 -m pip install --ignore-installed -U -e .[complete]

Next, setup the git pre-commit hook for Black

pre-commit install

Now you should be able to run all the tests with

python3 -m pytest

How to run

You can use simplify either through your command line, or integrate it directly into your scripts.

CLI

Run with e.g.

simplify convert < fullLH.json > simplifiedLH.json

or e.g.

curl http://foo/likelihood.json | simplify convert

where fullLH.json is the full likelihood you want to convert into a simplified likelihood. Simplify is able to read/write from/to stdin/stdout.

Hit simplify --help for detailled information on the CLI.

In python script

You can also use simplify in a python script, e.g. to create some validation and cross-check plots and tables.

import pyhf
import json

import simplify

pyhf.set_backend(pyhf.tensorlib, "minuit")
spec = json.load(open("likelihood.json", "r"))

ws = pyhf.Workspace(spec) # ws from full LH

# get model and data for each ws we just created
model = ws.model(modifier_settings = {"normsys": {"interpcode": "code4"},"histosys": {"interpcode": "code4p"},})
data = ws.data(model)

# run fit
fit_result = simplify.fitter.fit(ws)

plt = simplify.plot.pulls(
    fit_result,
    "plots/"
)

plt = simplify.plot.correlation_matrix(
    fit_result,
    "plots/",
    pruning_threshold=0.1
)

tables = simplify.plot.yieldsTable(
    ws,
    "plots/",
    fit_result,
)

Example Likelihood

Let's go through an example likelihood. We'll use the full likelihood of an ATLAS search for direct production of electroweakinos in final states with one lepton and a Higgs boson (10.1140/epjc/s10052-020-8050-3). The full likelihood in JSON format as specified by ATL-PHYS-PUB-2019-029 is publicly available to download from doi.org/10.17182. It contains the full statistical model of the original analysis given the full observed dataset from Run-2 of the LHC.

You can either download the likelihood by hand from HEPData, or just let pyhf do the work for you by using

pyhf contrib download https://doi.org/10.17182/hepdata.90607.v3/r3 1Lbb-likelihoods && cd 1Lbb-likelihoods

From there, provided you have already setup simplify previously (which also sets up pyhf), you can produce a simplified likelihood of this analysis with

simplify convert < BkgOnly.json > simplify_BkgOnly.json

And you're done. Well, at least you've got yourself a simplified version of that likelihood, which approximates the total background using a single background sample that is set to the post-fit total background determined from the full likelihood. The uncertainties (the expensive part) are approximated using only the final uncertainty on the background estimate in each bin of the analysis.

If you think about it, this gives you quite a simple likelihood function. Let's compare them quickly. For the full likelihood, we can inspect the full likelihood with pyhf (and only look at the first 17 lines containing summary of what pyhf spits out):

pyhf inspect BkgOnly.json | head -n 17

This should give you

       Summary
  ------------------
    channels  8
     samples  9
  parameters  115
   modifiers  115

    channels  nbins
  ----------  -----
 SRHMEM_mct2    3
 SRLMEM_mct2    3
 SRMMEM_mct2    3
 STCREM_cuts    1
 TRHMEM_cuts    1
 TRLMEM_cuts    1
 TRMMEM_cuts    1
   WREM_cuts    1

Think about this for a second. You've got 8 channels with a total of 14 bins. Each bin contains information about 9 samples, and each event rate for each sample is subject to a total of 115 additional parameters (the uncertainties of the model). This makes for quite a complicated likelihood function.

On to the simplified one then.

pyhf inspect simplify_BkgOnly.json | head -n 17

gives us

       Summary
  ------------------
    channels  8
     samples  1
  parameters  1
   modifiers  1

    channels  nbins
  ----------  -----
 SRHMEM_mct2    3
 SRLMEM_mct2    3
 SRMMEM_mct2    3
 STCREM_cuts    1
 TRHMEM_cuts    1
 TRLMEM_cuts    1
 TRMMEM_cuts    1
   WREM_cuts    1

i.e, we still have the original number of bins and samples (this is what drives our sensitivity, so we don't want to compromise here), but we end up with only one sample and one uncertainty per bin.

It's not surprising to see then, that the computational performance of both is quite different. Let's have a look at a benchmark for this specific analysis:

Benchmark of ANA-SUSY-2019-08

Ignore the green bars for now and focus on the orange and blue ones instead. The orange (blue) ones show the wall times in seconds for the full (simplified) likelihood. In their fastest configurations, the simplified likelihood obviously is two orders of magnitude faster than the full likelihood.

But this isn't worth anything if the approximation isn't a good one. So let's have a look at how it performs. All the original signal models investigated by the analysis are contained in the 1Lbb-likelihoods as a JSON patch file. Just patch each one onto the full and simplified likelihood, perform statistical inference using pyhf and then plot the results:

Performance of ANA-SUSY-2019-08

Given the two orders of magnitude we gain in computational speed, this small loss in statistical precision is impressive! Within the one standard deviation uncertainties, there is basically no difference at all in both contours!

P.S. I skipped quite a few steps to get to this figure. All of the necessary tools and scripts are available (and sometimes described) in my CERN GitLab.

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

simplify-0.1.9.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

simplify-0.1.9-py3-none-any.whl (24.1 kB view details)

Uploaded Python 3

File details

Details for the file simplify-0.1.9.tar.gz.

File metadata

  • Download URL: simplify-0.1.9.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for simplify-0.1.9.tar.gz
Algorithm Hash digest
SHA256 c3550d149ca9011d1030b9aef6ba50ea20aec119dc3221381335fb0e59de7b5c
MD5 468abb2e33dc4698a573650d2401957d
BLAKE2b-256 de920dc428877a025d69a0ac194afcf38c823f7ccaa306e3786e1eca10c93a9d

See more details on using hashes here.

File details

Details for the file simplify-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: simplify-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 24.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for simplify-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f64cebd4cc25a5a9fcbaa2630f912bcd03095613d701bc69910b1ed809ba2cd7
MD5 131e8296cb04f2ae09a647d9f101c2ee
BLAKE2b-256 1eec835303cbb8df7208faa0b6e3407c05c20f852bedb01a07d6ae847c14a384

See more details on using hashes here.

Supported by

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