question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auto scan for hypothesis test inversion (Implemented)

See original GitHub issue

Description

An auto scan feature for hypothesis test inversion can provide faster and more precise upper limits. One good way I’ve found to do this is to use the TOMS748 root finding algorithm.

Describe the solution you’d like

An upperlimit_auto (or some other appropriate name) function that runs an auto scan instead of a linear scan.

Implementation

An implementation is below. I can make a PR including this in pyhf.infer.intevals if this issue has support.

from scipy.optimize import toms748 as _toms748

def upperlimit_auto(data, model, low, high, level=0.05, atol=2e-12, rtol=1e-15):
    """
    Calculate an upper limit interval ``(0, poi_up)`` for a single
    Parameter of Interest (POI) using an automatic scan through
    POI-space, using the TOMS748 algorithm.
    
    ..., mostly copied from upperlimit docstring.
    """

    def f_all(mu):
        return hypotest(mu, data, model, test_stat="qtilde", return_expected_set=True)

    def f(mu, limit=0):
        # Use integers for limit so we don't need a string comparison
        if limit == 0:
            # Obs
            return f_all(mu)[0] - level
        else:
            # Exp
            # (These are in the order -2, -1, 0, 1, 2 sigma)
            return f_all(mu)[1][limit - 1] - level

    tb, _ = get_backend()
    obs = tb.astensor(_toms748(f, low, high, args=(0), k=2, xtol=atol, rtol=rtol))
    exp = [
        tb.astensor(_toms748(f, low, high, args=(i), k=2, xtol=atol, rtol=rtol))
        for i in range(1, 6)
    ]
    return obs, exp

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
lukasheinrichcommented, Jan 18, 2021

It would be ince to find a way to be able to inject algorithms that can perform scans without taking them on fully (maybe ismilar to the work on toy calculator API)… scikit optimize has the ask/tell API

https://scikit-optimize.github.io/stable/auto_examples/ask-and-tell.html

probably would fit into pyhf.infer.intervals

0reactions
beojancommented, Jan 21, 2021

I’ve opened a PR with the implementation I have. I included the suggestions @alexander-held made, but otherwise I stuck to the same return format as the linear scan so that anyone using the linear scan can move over easily.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Inversion of Hypothesis Tests
Inversion of Hypothesis Tests one-to-one mapping between hypothesis tests and confidence intervals. 2 hypothesis test”. Classical Hypothesis Testing (cont.).
Read more >
6: Hypothesis Testing, Part 2
Recall that there is an inverse relationship between sample size and the standard error (i.e., standard deviation of the sampling distribution). Very small ......
Read more >
Hypothesis test in admixture models
The goal of this vignette is to introduce the functionalities that enable to perform hypothesis tests on the unknown component distribution F. We...
Read more >
Hypothesis Testing for Binomial Distribution
Provides various examples demonstrating how to use Excel functions to perform hypothesis testing using the binomial distribution.
Read more >
Statistical Hypothesis Testing for Postreconstructed and ...
This type of analysis is underused in applied inverse problems. Hypothesis testing should be an integral part of medical diagnostics.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found