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: Improve handling of parameter bounds when computing impacts in ranking #512

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

Conversation

MoAly98
Copy link
Collaborator

@MoAly98 MoAly98 commented Mar 5, 2025

This is based on #490.

Summary

When building parameter rankings based on impact, 5 fits must be evaluated for each NP. The fits are evaluated at:

  • The best-fit value of the NP
  • NP + up uncertainty (pre-fit)
  • NP + down uncertainty (pre-fit)
  • NP + up uncertainty (post-fit)
  • NP + down uncertainty (post-fit)

The uncertainties so far have been extracted from the Hessian. If the bounds of the parameter, which specify valid range of values of this parameter, are not specified by the user, one of the NP values above may step out of the appropriate bound. For example, for a poisson-constrained NP (shapesys). If the best-fit value is 1.0 and pre/post-fit uncertainty is >1, the NP value will be negative for some of the above fits. Negative parameter values are not allowed in the poisson terms, and hence the corresponding fits fails.

This can indicate a defective model, or it can be the result of the Hessian uncertainty being symmetrised without respecting parameter bounds. If the user is sure their model is good, some options are added in this PR to help the firs converge:

1- Use suggested bounds from pyhf to force the ranking to cap the value of an NP at its physical limit, independently of the uncertainty extracted from the fit.
2- Use the uncertainty from MINOS on the NP which will respect the parameter boundaries by construction.

In this MR, an option to the fit.ranking function is added to specify that suggested bounds should be used to set limits on the parameters bounds are not set by user. In addition, the ranking function can now read MINOS uncertainties for relevant parameters if the fit results are provided to it. If the fit results are not provided, the ranking function can now perform the fit itself while allowing the use of MINOS for model parameters.

Example spec

The following spec fails even for pre-fit uncertainties.

spec = {
    "channels": [
        {
            "name": "Signal_region",
            "samples": [
                {
                    "data": [50.0],
                    "modifiers": [
                        {
                            "data": None,
                            "name": "mu",
                            "type": "normfactor"
                        },
                        {
                            "data": [80.0],
                            "name": "test_shapesys",
                            "type": "shapesys"
                        }
                    ],
                    "name": "Signal"
                },
                {
                    "data": [200.0],
                    "modifiers": [],
                    "name": "Background"
                }
            ]
        }
    ],
    "measurements": [
        {
            "config": {
                "parameters": [],
                "poi": "mu"
            },
            "name": "minimal_example"
        }
    ],
    "observations": [
        {
            "data": [250.0],
            "name": "Signal_region"
        }
    ],
    "version": "1.0.0"

With this PR the following setups are possible, utilising suggested bounds:

model, data = model_utils.model_and_data(spec)
fit_results = fit.fit(model, data, minos=["test_shapesys[0]"])
rank = fit.ranking(model, data, fit_results=fit_results) # fails
rank = fit.ranking(model, data, fit_results=fit_results, par_bounds=[(0,10),(1e-10,10.0)]) # works and already supported
rank = fit.ranking(model, data, fit_results=fit_results, use_suggested_bounds=True) # works and new 
rank = fit.ranking(model, data, fit_results=fit_results, par_bounds=[(0,10),None], use_suggested_bounds=True) # works and 

To utilise MINOS, consider the following setup:

# We want the fit results to be problematic to check use of minos
bestfit = np.asarray([1.0, 1.0])
uncertainty = np.asarray([0.85, 1.1])
labels = ["POI", "SHAPESYS"]
fit_results = FitResults(bestfit, uncertainty, labels, np.empty(0), 0.0)
fit_results_with_minos = FitResults(bestfit, uncertainty, labels, np.empty(0), 0.0, minos_uncertainty={'test_shapesys[0]': (-0.89, 2.55)})

rank = fit.ranking(model, data, fit_results=fit_results) # fails
rank = fit.ranking(model, data, fit_results=fit_results_with_minos) # works because MINOS is limiting the bounds
* Added `bool` option for user to specify if suggested bounds should be used for parameters with no user-set bounds
* Ranking now accepts minos arguments when` fit_results` object is not provided
* Ranking now uses post-fit MINOS uncertainties from fit results if they are available for a parameter

@MoAly98 MoAly98 self-assigned this Mar 5, 2025
@MoAly98 MoAly98 requested a review from alexander-held March 5, 2025 11:43
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 29.41176% with 12 lines in your changes missing coverage. Please review.

Project coverage is 99.43%. Comparing base (19ce6a1) to head (f01114d).

Files with missing lines Patch % Lines
src/cabinetry/fit/__init__.py 29.41% 7 Missing and 5 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##            master     #512      +/-   ##
===========================================
- Coverage   100.00%   99.43%   -0.57%     
===========================================
  Files           22       22              
  Lines         2094     2111      +17     
  Branches       347      355       +8     
===========================================
+ Hits          2094     2099       +5     
- Misses           0        7       +7     
- Partials         0        5       +5     

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

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

Successfully merging this pull request may close these issues.

2 participants