Skip to content

Commit

Permalink
feat: Add hypotest kwargs to pyhf.infer.intervals.upperlimit (#1613)
Browse files Browse the repository at this point in the history
* Add hypotest_kwargs to pyhf.infer.intervals.upperlimit to allow passing in configuration options to the underlying hypotest call
* Add test for hypotest_kwargs use
* Add Aryan Roy to contributor list
  • Loading branch information
aryan26roy authored Oct 12, 2021
1 parent 54b44ad commit 9358f85
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/contributors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Contributors include:
- Saransh Chopra
- Sviatoslav Sydorenko
- Mason Proffitt
- Aryan Roy
6 changes: 4 additions & 2 deletions src/pyhf/infer/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def _interp(x, xp, fp):
return tb.astensor(np.interp(x, xp.tolist(), fp.tolist()))


def upperlimit(data, model, scan, level=0.05, return_results=False):
def upperlimit(data, model, scan, level=0.05, return_results=False, **hypotest_kwargs):
"""
Calculate an upper limit interval ``(0, poi_up)`` for a single
Parameter of Interest (POI) using a fixed scan through POI-space.
Expand Down Expand Up @@ -44,6 +44,8 @@ def upperlimit(data, model, scan, level=0.05, return_results=False):
scan (:obj:`iterable`): Iterable of POI values.
level (:obj:`float`): The threshold value to evaluate the interpolated results at.
return_results (:obj:`bool`): Whether to return the per-point results.
hypotest_kwargs (:obj:`string`): Kwargs for the calls to
:class:`~pyhf.infer.hypotest` to configure the fits.
Returns:
Tuple of Tensors:
Expand All @@ -56,7 +58,7 @@ def upperlimit(data, model, scan, level=0.05, return_results=False):
"""
tb, _ = get_backend()
results = [
hypotest(mu, data, model, test_stat="qtilde", return_expected_set=True)
hypotest(mu, data, model, return_expected_set=True, **hypotest_kwargs)
for mu in scan
]
obs = tb.astensor([[r[0]] for r in results])
Expand Down
16 changes: 16 additions & 0 deletions tests/test_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ def test_upperlimit(tmpdir, hypotest_args):
)


def test_upperlimit_with_kwargs(tmpdir, hypotest_args):
"""
Check that the default return structure of pyhf.infer.hypotest is as expected
"""
_, data, model = hypotest_args
results = pyhf.infer.intervals.upperlimit(
data, model, scan=np.linspace(0, 5, 11), test_stat="qtilde"
)
assert len(results) == 2
observed_limit, expected_limits = results
assert observed_limit == pytest.approx(1.0262704738584554)
assert expected_limits == pytest.approx(
[0.65765653, 0.87999725, 1.12453992, 1.50243428, 2.09232927]
)


def test_mle_fit_default(tmpdir, hypotest_args):
"""
Check that the default return structure of pyhf.infer.mle.fit is as expected
Expand Down

0 comments on commit 9358f85

Please sign in to comment.