-
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
fix: respect fixed parameters in n_dof calculation #479
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -481,24 +481,35 @@ def prediction( | |
) | ||
|
||
|
||
def unconstrained_parameter_count(model: pyhf.pdf.Model) -> int: | ||
"""Returns the number of unconstrained parameters in a model. | ||
def unconstrained_parameter_count( | ||
model: pyhf.pdf.Model, | ||
fix_pars: Optional[List[bool]] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment here about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
) -> 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 | ||
n_pars += model.config.param_set(parname).suggested_fixed.count(False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am trying to remind myself if there was a particular reason I wrote this in this fashion because it felt slightly unusual to me upon revisiting. Looking at the implementation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! |
||
par_slice = model.config.par_slice(parname) | ||
n_pars += fix_pars[par_slice].count(False) | ||
|
||
return n_pars | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a
, *
between the mandatory and optional arguments to force the optional arguments to be keyword-only (see also other functions in this file for examples). This is done to allow re-ordering keyword arguments in the future without fear of breaking the setup for anyone, as otherwise people could be usingfix_pars
as a positional argument still and relying on the order.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!