pyhf icon indicating copy to clipboard operation
pyhf copied to clipboard

Warn when parameter hits bounds

Open lorenzennio opened this issue 1 year ago • 3 comments

Summary

Hey, I recently ran a lot of toys for a very large model and had a hard time debugging, as some nuisance parameters hit the parameter bounds for some of the toys. It would be great if a warning could be added in that case. What do you think?

Additional Information

A simple example:

import pyhf

bkg = [5]
sig = [3]

data = bkg

samples = [
    dict(name="signal", data=list(sig), modifiers=[dict(name="mu", type="normfactor", data=None)]),
    dict(name="background", data=list(bkg), modifiers=[]),
]
model = pyhf.Model(dict(channels=[dict(name="singlechannel", samples=samples)]))

init = [5]
bounds =[(3, 10)]
pyhf.infer.mle.fit(data, model, init_pars=init, par_bounds=bounds)

Code of Conduct

  • [X] I agree to follow the Code of Conduct

lorenzennio avatar Jun 26 '24 09:06 lorenzennio

Where do you forsee the error being raised? Would it be as part of optimization (which scipy's fortran routines have a warning for that I added a long time ago; but minuit really doesn't) or do you imagine this being done after the fit is done and we're checking all returned fitted parameter values (for non-fixed parameters) to see if any of them are matching the upper or lower bounds of those parameters?

kratsg avatar Jun 26 '24 12:06 kratsg

Either is fine, I guess. I would have just checked after the fit is done. Or do you see any complications with this?

lorenzennio avatar Jun 26 '24 12:06 lorenzennio

Or do you see any complications with this?

harder to do it as part of the fit, mostly because scipy and minuit are entirely different and trying to add a check while doing optimization will slow down the optimization at each stage. It should be somewhat straightforward to add a way to check the bounds are hit. Given you provided an example, then we have a good way to test that we catch it.

kratsg avatar Jun 26 '24 13:06 kratsg