pyhf | pure-Python HistFactory implementation with tensors | Analytics library
kandi X-RAY | pyhf Summary
kandi X-RAY | pyhf Summary
pure-Python HistFactory implementation with tensors and autodiff
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Calculate the hypotest test for a polynomial
- Check that the hypothesis prerequisites are satisfied
- Returns the TensorBackend
- Inspect the model
- Retrieve a single measurement
- Create a model
- Plot the results
- Plot brazil band
- Plots cls components
- Parse a configfile
- Validate a specification
- Calculate the expected pvalues for each test
- Compute expected p - values for the expected distribution
- Create a ROOT stats file for the ROOT analysis
- Compute the expected value of the sample
- Compute the pvalue at given value
- Wraps tensorflow objective function
- Decorator to register a function
- Poisson Poisson Poisson distribution
- Computes the p - value for the given value
- Create a new measurement workspace
- Combine two Workspaces
- Compute the distributions of the polynomial distributions
- Compute test statistic
- Concatenate builder data
- Create a nominal and modifier based on a spec
pyhf Key Features
pyhf Examples and Code Snippets
import altair as alt
chart = alt.Chart('data.txt').mark_point().interactive()
chart + chart
# Javascript Error: Duplicate signal name: "selector001_tuple"
# This usually means there's a typo in your chart specification. See the javascript
import mylib
import sys
import logging
import pytest
from unittest import mock
from importlib import reload
from importlib import import_module
# ...
def test_missing_contrib_extra(caplog):
with mock.patch.dict(sys.modules):
(example) $ cat requirements.txt
pyhf~=0.4.0
black
matplotlib~=3.1
altair~=4.0
# answer.py
import pyhf
from pyhf import Model, infer
import numpy as np
import matplotlib.pyplot as plt
import pyhf.contrib.viz.brazi
Community Discussions
Trending Discussions on pyhf
QUESTION
I've been trying to replicate the text shown by selection of the following chart with this code:
But I get the following error:
Javascript Error: Duplicate signal name: "selector074_index" This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
I have dedicated all day trying to find out what I am doing wrong without any luck. Here's my code as a sample:
...ANSWER
Answered 2020-Dec-30 at 17:26TL;DR – remove .interactive()
from the definition of confirmed_line
.
The issue is that you called .interactive()
on a chart, and then layered it with itself. A minimal reproduction of this error looks like this:
QUESTION
I'm trying to learn more about pyhf and my understanding of what the goals are might be limited. I would love to fit my HEP data outside of ROOT, but I could be imposing expectations on pyhf which are not what the authors intended for it's use.
I'd like to write myself a hello-world example, but I might just not know what I'm doing. My misunderstanding could also be gaps in my statistical knowledge.
With that preface, let me explain what I'm trying to explore.
I have some observed set of events for which I calculate some observable and make a binned histogram of that data. I hypothesize that there are two contributing physics processes, which I call signal and background. I generate some Monte Carlo samples for these processes and the theorized total number of events is close to, but not exactly what I observe.
I would like to:
- Fit the data to this two process hypothesis
- Get from the fit the optimal values for the number of events for each process
- Get the uncertainties on these fitted values
- If appropriate, calculate an upper limit on the number of signal events.
My starter code is below, where all I'm doing is an ML fit but I'm not sure where to go. I know it's not set up to do what I want, but I'm getting lost in the examples I find on RTD. I'm sure it's me, this is not a criticism of the documentation.
...ANSWER
Answered 2020-Oct-10 at 18:46Note: this answer is based on pyhf v0.5.2.
Alright, so it looks like you've managed to figure most of the big pieces for sure. However, there's two different ways to do this depending on how you prefer to set things up. In both cases, I assume you want an unconstrained fit and you want to...
fit your signal+background model to observed data
fit your background model to observed data
First, let's discuss uncertainties briefly. At the moment, we default to numpy
for the tensor background and scipy
for the optimizer. See documentation:
However, one unfortunate drawback right now with the scipy
optimizer is that it cannot return the uncertainties. What you need to do anywhere in your code before the fit (although we generally recommend as early as possible) is to use the minuit
optimizer instead:
QUESTION
I want to make a plot that shows the 'best fit' after an maximum likelihood fit.
This snippet found somewhere in the docs
...ANSWER
Answered 2020-Oct-07 at 15:24With https://github.com/scikit-hep/pyhf/pull/731 merged, this is now possible using a construction like
QUESTION
I have a question regarding the implementation of the statistical uncertainty. In the pyhf documentation https://scikit-hep.org/pyhf/likelihood.html#sample you mention that the way to infer statistical uncertainty is with modifier with "type": "staterror" and data field=[0.1].
So let's assume that I have a background channel which is coming from MC and I split my distribution in 3 bins:
...ANSWER
Answered 2020-Aug-06 at 04:48I have a background channel which is coming from MC
Given that it sounds like you want to model the uncertainty in shape due to limited Monte Carlo sample size, the best modifier to use would be staterror
.
staterror
is shared across all samples (that have a staterror
modifier) in the bins it is applied with a Normal constraint, with the strength of the constraint being the per-sample uncertainties added in quadrature.
Here the data
key represents the absolute uncertainty in each bin of the sample (in this case being the Poisson uncertainty of the bin counts):
So, given your example of a single background sample with 3 bins, an example spec might look something like this (which I'll name bkg_only_spec.json
)
QUESTION
I am trying to write a likelihood model in which the POI affects two samples, but while one I have the regular POI*yield, the other I have f(POI)*yield where f is an arbitrary function.
Is there a simple way to implement that in pyhf?
Thanks in advance.
...ANSWER
Answered 2020-May-01 at 23:23pyhf currently does not support it, but it's something that is on our mind. Can you open an issue on our github with this as a feature request and we can work out how to do it.
QUESTION
I am trying to build a pretty minimal pyhf example: two gaussians, one signal and one background, but I can't get it to work. My python code is:
...ANSWER
Answered 2020-Mar-03 at 22:14Hi @robsol90 can you dump the full JSON spec pdf.spec
and share it here?
QUESTION
(This is a question that we (the pyhf dev team) recently got and thought was good and worth sharing. So we're posting a modified version of it here.)
I am trying to do a simple hypothesis test with pyhf v0.4.0
. The model I am using has a small signal and so I need to scan signal strengths almost all the way out to mu=100
. However, I am consistently getting a convergence problem. Why is the fit failing to converge?
The following is my environment, the code I'm using, and my error.
Environment ...ANSWER
Answered 2020-Feb-06 at 07:44Looking at the model, the background estimate shouldn't be zero, so add an epsilon of 1e-7
to it and then an 1%
background uncertainty. Though the issue here is that reasonable intervals for signal strength are between μ ∈ [0,10]
. If your model is such that you aren't sensitive to a signal strength in this range then you should test a new signal model which is the original signal scaled by some scale factor.
For visualization purposes let's extend the environment a bit
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pyhf
You can use pyhf like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page