pyhf | pure-Python HistFactory implementation with tensors | Analytics library

 by   scikit-hep Python Version: 0.7.6 License: Apache-2.0

kandi X-RAY | pyhf Summary

kandi X-RAY | pyhf Summary

pyhf is a Python library typically used in Analytics, Pytorch, Numpy applications. pyhf has no bugs, it has no vulnerabilities, it has a Permissive License and it has high support. However pyhf build file is not available. You can install using 'pip install pyhf' or download it from GitHub, PyPI.

pure-Python HistFactory implementation with tensors and autodiff
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              pyhf has a highly active ecosystem.
              It has 249 star(s) with 71 fork(s). There are 10 watchers for this library.
              There were 1 major release(s) in the last 6 months.
              There are 354 open issues and 540 have been closed. On average issues are closed in 128 days. There are 33 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of pyhf is 0.7.6

            kandi-Quality Quality

              pyhf has 0 bugs and 0 code smells.

            kandi-Security Security

              pyhf has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              pyhf code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              pyhf is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              pyhf releases are available to install and integrate.
              Deployable package is available in PyPI.
              pyhf has no build file. You will be need to create the build yourself to build the component from source.
              pyhf saves you 6836 person hours of effort in developing the same functionality from scratch.
              It has 16342 lines of code, 1071 functions and 159 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed pyhf and discovered the below as its top functions. This is intended to give you an instant insight into pyhf implemented functionality, and help decide if they suit your requirements.
            • 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
            Get all kandi verified functions for this library.

            pyhf Key Features

            No Key Features are available at this moment for pyhf.

            pyhf Examples and Code Snippets

            Altair selection error: "Javascript Error: Duplicate signal name: "selector074_index""
            Pythondot img1Lines of Code : 10dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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 
            How to remove a library with monkeypatch or mock in pytest?
            Pythondot img2Lines of Code : 28dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            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):
                    
            Fit convergence failure in pyhf for small signal model
            Pythondot img3Lines of Code : 188dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            (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

            QUESTION

            Altair selection error: "Javascript Error: Duplicate signal name: "selector074_index""
            Asked 2020-Dec-30 at 17:26

            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:26

            TL;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:

            Source https://stackoverflow.com/questions/65503289

            QUESTION

            Trying to put together a teaching-example with pyhf
            Asked 2020-Oct-26 at 13:34

            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:46

            Note: 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...

            1. fit your signal+background model to observed data

            2. 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:

            Source https://stackoverflow.com/questions/64257667

            QUESTION

            Expected data split by sample
            Asked 2020-Oct-07 at 15:24

            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:24

            With https://github.com/scikit-hep/pyhf/pull/731 merged, this is now possible using a construction like

            Source https://stackoverflow.com/questions/63297304

            QUESTION

            pyhf: implementation of statistical uncertainty
            Asked 2020-Aug-06 at 04:48

            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:48

            I 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)

            Source https://stackoverflow.com/questions/63251753

            QUESTION

            pyhf: POI application using formula
            Asked 2020-May-01 at 23:23

            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:23

            pyhf 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.

            Source https://stackoverflow.com/questions/61543239

            QUESTION

            Minimal pyhf example failing with 'Inequality constraints incompatible'
            Asked 2020-Mar-09 at 19:40

            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:14

            Hi @robsol90 can you dump the full JSON spec pdf.spec and share it here?

            Source https://stackoverflow.com/questions/60514470

            QUESTION

            Fit convergence failure in pyhf for small signal model
            Asked 2020-Feb-06 at 17:12

            (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:44

            Looking 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.

            Environment

            For visualization purposes let's extend the environment a bit

            Source https://stackoverflow.com/questions/60089405

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install pyhf

            You can install using 'pip install pyhf' or download it from GitHub, PyPI.
            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

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install pyhf

          • CLONE
          • HTTPS

            https://github.com/scikit-hep/pyhf.git

          • CLI

            gh repo clone scikit-hep/pyhf

          • sshUrl

            git@github.com:scikit-hep/pyhf.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Analytics Libraries

            superset

            by apache

            influxdb

            by influxdata

            matomo

            by matomo-org

            statsd

            by statsd

            loki

            by grafana

            Try Top Libraries by scikit-hep

            awkward

            by scikit-hepPython

            awkward-1.0

            by scikit-hepPython

            uproot3

            by scikit-hepPython

            uproot

            by scikit-hepPython

            iminuit

            by scikit-hepPython