From b08c624393d7309cc9b78f895602bd77f0164065 Mon Sep 17 00:00:00 2001 From: Alexander Held Date: Fri, 29 Jul 2022 16:50:30 +0200 Subject: [PATCH 1/2] set post-fit parameter errors to 0 for fixed parameters --- src/cabinetry/fit/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cabinetry/fit/__init__.py b/src/cabinetry/fit/__init__.py index e26ddf47..c6a6675d 100644 --- a/src/cabinetry/fit/__init__.py +++ b/src/cabinetry/fit/__init__.py @@ -85,7 +85,10 @@ def _fit_model_pyhf( log.info(f"MINUIT status:\n{result_obj.minuit.fmin}") bestfit = pyhf.tensorlib.to_numpy(result[:, 0]) - uncertainty = pyhf.tensorlib.to_numpy(result[:, 1]) + # set errors for fixed parameters to 0 (see iminuit#762) + uncertainty = np.where( + result_obj.minuit.fixed, 0.0, pyhf.tensorlib.to_numpy(result[:, 1]) + ) labels = model.config.par_names() corr_mat = pyhf.tensorlib.to_numpy(corr_mat) best_twice_nll = float(best_twice_nll) # convert 0-dim np.ndarray to float @@ -180,7 +183,8 @@ def twice_nll_func(pars: np.ndarray) -> Any: log.info(f"MINUIT status:\n{m.fmin}") bestfit = np.asarray(m.values) - uncertainty = np.asarray(m.errors) + # set errors for fixed parameters to 0 (see iminuit#762) + uncertainty = np.where(m.fixed, 0.0, m.errors) corr_mat = m.covariance.correlation() # iminuit.util.Matrix, subclass of np.ndarray best_twice_nll = m.fval From 6eb239d2d2eb764afb9a537676d967f3b870ca86 Mon Sep 17 00:00:00 2001 From: Alexander Held Date: Fri, 29 Jul 2022 17:23:27 +0200 Subject: [PATCH 2/2] remove initial step size settings --- src/cabinetry/fit/__init__.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/cabinetry/fit/__init__.py b/src/cabinetry/fit/__init__.py index c6a6675d..8b36acbf 100644 --- a/src/cabinetry/fit/__init__.py +++ b/src/cabinetry/fit/__init__.py @@ -150,10 +150,6 @@ def _fit_model_custom( labels = model.config.par_names() - # set initial step size to 0 for fixed parameters - # this will cause the associated parameter uncertainties to be 0 post-fit - step_size = [0.1 if not fix_pars[i_par] else 0.0 for i_par in range(len(init_pars))] - def twice_nll_func(pars: np.ndarray) -> Any: """The objective for minimization: twice the negative log-likelihood. @@ -170,7 +166,6 @@ def twice_nll_func(pars: np.ndarray) -> Any: return twice_nll[0] m = iminuit.Minuit(twice_nll_func, init_pars, name=labels) - m.errors = step_size m.fixed = fix_pars m.limits = par_bounds m.errordef = 1