Skip to content

Commit

Permalink
feat: Update model and inference defaults (#1114)
Browse files Browse the repository at this point in the history
* Use the same defaults across the Python and CLI API
   - Use interpolation code4 and code4p in default modifier settings for models
   - Use qtilde as the default test stat for inference
* Link to test stat functions in docstrings
   - Migrate mention of approximation of test stat distributions to AsymptoticCalculator.distributions
  • Loading branch information
lukasheinrich authored Oct 28, 2020
1 parent 638e5c7 commit 69a5388
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
4 changes: 0 additions & 4 deletions src/pyhf/cli/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ def fit(
model = ws.model(
measurement_name=measurement,
patches=patches,
modifier_settings={
"normsys": {"interpcode": "code4"},
"histosys": {"interpcode": "code4p"},
},
)
data = ws.data(model)

Expand Down
8 changes: 4 additions & 4 deletions src/pyhf/infer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def hypotest(
init_pars=None,
par_bounds=None,
fixed_params=None,
qtilde=False,
qtilde=True,
**kwargs,
):
r"""
Expand Down Expand Up @@ -41,9 +41,9 @@ def hypotest(
init_pars (:obj:`tensor`): The initial parameter values to be used for minimization
par_bounds (:obj:`tensor`): The parameter value bounds to be used for minimization
fixed_params (:obj:`tensor`): Whether to fix the parameter to the init_pars value during minimization
qtilde (:obj:`bool`): When ``True`` perform the calculation using the alternative
test statistic, :math:`\tilde{q}_{\mu}`, as defined under the Wald
approximation in Equation (62) of :xref:`arXiv:1007.1727`.
qtilde (:obj:`bool`): When ``True`` use :func:`~pyhf.infer.test_statistics.qmu_tilde`
as the test statistic.
When ``False`` use :func:`~pyhf.infer.test_statistics.qmu`.
Keyword Args:
return_tail_probs (bool): Bool for returning :math:`\mathrm{CL}_{s+b}` and :math:`\mathrm{CL}_{b}`
Expand Down
10 changes: 7 additions & 3 deletions src/pyhf/infer/calculators.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(
init_pars=None,
par_bounds=None,
fixed_params=None,
qtilde=False,
qtilde=True,
):
"""
Asymptotic Calculator.
Expand All @@ -139,7 +139,9 @@ def __init__(
init_pars (:obj:`tensor`): The initial parameter values to be used for fitting.
par_bounds (:obj:`tensor`): The parameter value bounds to be used for fitting.
fixed_params (:obj:`tensor`): Whether to fix the parameter to the init_pars value during minimization
qtilde (:obj:`bool`): Whether to use qtilde as the test statistic.
qtilde (:obj:`bool`): When ``True`` use :func:`~pyhf.infer.test_statistics.qmu_tilde`
as the test statistic.
When ``False`` use :func:`~pyhf.infer.test_statistics.qmu`.
Returns:
~pyhf.infer.calculators.AsymptoticCalculator: The calculator for asymptotic quantities.
Expand All @@ -156,7 +158,9 @@ def __init__(

def distributions(self, poi_test):
"""
Probability Distributions of the test statistic value under the signal + background and and background-only hypothesis.
Probability distributions of the test statistic, as defined in
:math:`\S` 3 of :xref:`arXiv:1007.1727` under the Wald approximation,
under the signal + background and background-only hypotheses.
Args:
poi_test: The value for the parameter of interest.
Expand Down
4 changes: 2 additions & 2 deletions src/pyhf/infer/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def qmu(mu, data, pdf, init_pars, par_bounds, fixed_params):

def qmu_tilde(mu, data, pdf, init_pars, par_bounds, fixed_params):
r"""
The test statistic, :math:`\tilde{q}_{\mu}`, for establishing an upper
limit on the strength parameter, :math:`\mu`, for models with
The "alternative" test statistic, :math:`\tilde{q}_{\mu}`, for establishing
an upper limit on the strength parameter, :math:`\mu`, for models with
bounded POI, as defiend in Equation (16) in :xref:`arXiv:1007.1727`
.. math::
Expand Down
6 changes: 5 additions & 1 deletion src/pyhf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ def __init__(self, spec, **config_kwargs):
)
poi_name = config_kwargs.pop('poi_name', 'mu')

default_modifier_settings = {'normsys': {'interpcode': 'code1'}}
default_modifier_settings = {
'normsys': {'interpcode': 'code4'},
'histosys': {'interpcode': 'code4p'},
}

self.modifier_settings = config_kwargs.pop(
'modifier_settings', default_modifier_settings
)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ def test_validation(setup_and_tolerance):
setup, tolerance = setup_and_tolerance
source = setup['source']

pdf = pyhf.Model(setup['spec'])
pdf = pyhf.Model(
setup['spec'], modifier_settings={'normsys': {'interpcode': 'code1'}}
)

if 'channels' in source:
data = []
Expand Down

0 comments on commit 69a5388

Please sign in to comment.