Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lorenzennio
Copy link

Solves #478 by passing fixed parameters to model_utils.unconstrained_parameter_count.

Copy link

codecov bot commented May 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7167074) to head (60c75da).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #479   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         2093      2096    +3     
  Branches       346       347    +1     
=========================================
+ Hits          2093      2096    +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

model: pyhf.pdf.Model,
data: List[float],
best_twice_nll: float,
fix_pars: Optional[List[bool]] = None,
Copy link
Member

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 using fix_pars as a positional argument still and relying on the order.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

"""Returns the number of unconstrained parameters in a model.
def unconstrained_parameter_count(
model: pyhf.pdf.Model,
fix_pars: Optional[List[bool]] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here about , *

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

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)
Copy link
Member

Choose a reason for hiding this comment

The 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 model.config.suggested_fixed() in https://github.com/scikit-hep/pyhf/blob/1af5ed423cfbdda40dedabf93fed772c729adee3/src/pyhf/pdf.py#L437-L441, that seems to be using the exact same interface though so I think for the fix_pars=None case, the new approach is fully consistent with the old one. I will run with some example workspaces to sanity check this but tests look good too so I think this solution is exactly what we need!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Member

@alexander-held alexander-held left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks all good to me, I just want to give it a try with a few workspaces to sanity check this before merging. Thanks a lot for also having updated the tests too already!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants