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

feat: limit parameter variations in rankings to stay within parameter bounds #490

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

Conversation

alexander-held
Copy link
Member

@alexander-held alexander-held commented Oct 22, 2024

As identified by @malin-horstmann, we can run into scenarios where the ranking will attempt to vary parameters beyond their bounds. This can happen with parameters that have asymmetric uncertainties when only a symmetric estimate was done from the Hessian (for shapesys in particular this is likely to happen).

This PR limits the variations to stick within bounds. Things to think about before finishing this:

  • raise a warning? (seems useful, but hard to miss in verbose ranking output)
  • allow for a way to propagate MINOS uncertainties through instead?
  • visually flag such cases in the plot?

The CI fail is currently expected (bounds kwarg changes).

* force parameter variations in ranking to stay within parameter bounds

@alexander-held alexander-held marked this pull request as draft October 22, 2024 15:20
@MoAly98
Copy link
Collaborator

MoAly98 commented Feb 28, 2025

Hi @alexander-held,

I think it is sensible to print a warning to the user, and also add a visual hint (a double-dash of some sort on the side that was bound?). Would you like to finish working on it or should I have a go ?

@alexander-held
Copy link
Member Author

I think I got stuck figuring out how we would visually indicate the bound and also how we best would transport that information through. You're welcome to give this a try!

@@ -588,6 +588,10 @@ def ranking(
init_pars = init_pars or model.config.suggested_init()
fix_pars = fix_pars or model.config.suggested_fixed()

par_bounds = par_bounds or [
tuple(bound) for bound in model.config.suggested_bounds()
Copy link
Collaborator

Choose a reason for hiding this comment

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

would this behave correctly if some parameters are bound but not others? I am guessing then the bound will be None for unboun ones and we have the same issue in variations?

Copy link
Member Author

Choose a reason for hiding this comment

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

All parameters are meant to have bounds as far as I am aware so a None should not happen here. I am however unsure if this is technically a guarantee from pyhf, if so at least I do not see it explicitly mentioned. I do not remember ever running into an example where the bounds are not set (other than scikit-hep/pyhf#1516 which I would call a bug). I thought iminuit also requires bounds but that turns out to be wrong, it only requires starting values.

Copy link
Collaborator

Choose a reason for hiding this comment

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

what I meant here was that If par_bounds is not None or a "falsy"-valued object, it will be chosen instead of the suggested bounds list. So if par_bounds is for example (None, (0,10), None), we still have two unbound parameters. Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Now I understand your point I think, if a user provides an invalid value then yes this will cause problems. Such an example would not follow the expected format Optional[List[Tuple[float, float]]].

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah so something like:

model, data = model_utils.model_and_data(spec)
fit_results = fit.fit(model,data)
ranking_results = fit.ranking(model, data, fit_results=fit_results, par_bounds=[None, None, (-2,2)])

fails with the current implementation. I guess ideally this user input should be fine, and we should be checking be updating individual bounds which are not set. I don't see why we should completely stop user from specifying only one parameter bound. A simple insertion of elements from suggested_bounds where there is a None entry can fix this issue.

Copy link
Member Author

@alexander-held alexander-held Mar 5, 2025

Choose a reason for hiding this comment

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

[None, None, (-2,2)] is an invalid input at the moment, it has to be either None or a list of tuples of floats according to the desired type. This is mostly done to align with the pyhf API. I'm not opposed to supporting what you suggest, though it does feel a bit complicated to me to have a user create a list of None and then update it at the right index. In that case they might as well get the suggested_bounds themselves as a starting point and update that index?

Copy link
Member Author

Choose a reason for hiding this comment

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

But either way the addition doesn't hurt so I'm fine with it.

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