Skip to content

Commit

Permalink
allow changing confidence level for minos
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-held committed Feb 2, 2025
1 parent 34d4030 commit d23272c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cabinetry/fit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ def _run_minos(
minuit_obj: iminuit.Minuit,
minos: Union[List[str], Tuple[str, ...]],
labels: List[str],
*,
cl: Optional[float] = None,
) -> Dict[str, Tuple[float, float]]:
"""Determines parameter uncertainties for a list of parameters with MINOS.
Expand All @@ -337,6 +339,8 @@ def _run_minos(
labels (List[str]]): names of all parameters known to ``iminuit``, these names
are used in output (may be the same as the names under which ``iminiuit``
knows parameters)
cl (Optional[float]), optional): confidence level for the confidence interval,
defaults to None (use ``iminuit`` default of 68.27%)
Returns:
Dict[str, Tuple[float, float]]: uncertainties indexed by parameter name
Expand All @@ -347,7 +351,7 @@ def _run_minos(
log.warning(f"parameter {par_name} not found in model")
continue
log.info(f"running MINOS for {par_name}")
minuit_obj.minos(par_name)
minuit_obj.minos(par_name, cl=cl)

minos_results = {}

Expand Down
6 changes: 6 additions & 0 deletions tests/fit/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ def func_to_minimize(pars):
assert "b = 1.5909 -0.7262 +0.4738" in [rec.message for rec in caplog.records]
caplog.clear()

# custom confidence interval
minos_results = fit._run_minos(m, ["b"], ["a", "b"], cl=0.95)
assert np.allclose(minos_results["b"][0], -1.47037911)
assert np.allclose(minos_results["b"][1], 0.81994008)
caplog.clear()

# unknown parameter, MINOS does not run
m = iminuit.Minuit(func_to_minimize, [1.0, 1.0])
m.errordef = 1
Expand Down

0 comments on commit d23272c

Please sign in to comment.