-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong n_dof
for fixed unconstrained parameters in _goodness_of_fit
#478
Comments
Thanks a lot for raising this! I see that |
How would we deal with fixed constrained parameters then? Would you rather correct for this in the |
Good point, sounds like we should pass the information through to handle constrained parameters correctly. |
What do you think of this fix? def unconstrained_parameter_count(model: pyhf.pdf.Model, fix_pars: Optional[List[bool]] = None,) -> int:
"""Returns the number of unconstrained, non-constant parameters in a model.
The number is the sum of all independent parameters in a fit. A shapefactor that
affects multiple bins enters the count once for each independent bin. Parameters
that are set to constant are not included in the count.
Args:
model (pyhf.pdf.Model): model to count parameters for
fix_pars (Optional[List[bool]], optional): list of booleans specifying which
parameters are held constant, defaults to None (use ``pyhf`` suggestion)
Returns:
int: number of unconstrained parameters
"""
n_pars = 0
# custom fixed parameters overrule suggested fixed parameters
if fix_pars is None:
fix_pars = model.config.suggested_fixed()
for parname in model.config.par_order:
if not model.config.param_set(parname).constrained:
# only consider non-constant parameters
par_slice = model.config.par_slice(parname)
n_pars += fix_pars[par_slice].count(False)
return n_pars Can PR this, if you are happy. |
Thanks for opening the PR! Looking at the original implementation, I was trying to remember why I wrote it in that specific way. I cannot think of any obvious issues with what you have though. I'll have a closer look at the PR. |
No worries, let me know if you want me to change anything. |
Hey,
I think I found a small bug in the
_goodness_of_fit
function, when working with fixed unconstrained parameters. When you fix an unconstrained parameter in the fit using thefix_pars
argument, then_dof
is still calculated with all (fixed or free) unconstrained parameters of the model.Code to reproduce:
The text was updated successfully, but these errors were encountered: