SpeysideHEP / spey

Smooth inference for reinterpretation studies
https://spey.readthedocs.io
MIT License
8 stars 1 forks source link

Error when computing likelihood from uncorrelated model with an absurdly high number of observed yields. #6

Closed APMDSLHC closed 1 year ago

APMDSLHC commented 1 year ago

System Settings

Fedora Linux 35 python v.3.9.12 spey commit 872edff

Describe the bug

When I try to compute the likelihood with a 1 SR model with absurdly high number of observed yields I get the following error:

File "/home/pascal/SModelS/spey/src/spey/interface/statistical_model.py", line 109, in likelihood
    twice_nll, _ = fit(
  File "/home/pascal/SModelS/spey/src/spey/optimizer/core.py", line 31, in fit
    return minimize(
  File "/home/pascal/SModelS/spey/src/spey/optimizer/scipy_tools.py", line 72, in minimize
    bounds[bdx] = (bounds[bdx][0] * 10.0, bounds[bdx][1] * 10.0)
TypeError: list indices must be integers or slices, not tuple

I did not really dig up the reason of the error and if it can actually happen in a realistic case, but in doubt I share it with you. I also tried to reasonably change the bounds of the model (i.e. order of magnitude 100) but it didn't work.

The error shows up for both simplified_likelihoods and pyhf backends.

To Reproduce

import spey

statModel = spey.get_uncorrelated_region_statistical_model(observations=1e20,
                                                           backgrounds=2.2,
                                                           background_uncertainty=1.1,
                                                           signal_yields=2.,
                                                           xsection=None,
                                                           analysis="Test",
                                                           backend="simplified_likelihoods" # or "pyhf"
                                                           )

llhd = statModel.likelihood(poi_test=1.,return_nll=False)

Expected behaviour

A likelihood of 0.

Additional information

No response

jackaraz commented 1 year ago

Hi @APMDSLHC this is actually a bug, good catch thanks will fix it on Monday!

jackaraz commented 1 year ago

Hi @APMDSLHC, this should be fixed now. Please let me know if it gives you the same error. you can turn this feature off by setting ntrials=0.

APMDSLHC commented 1 year ago

Thanks it fixed the issue. I now have a bunch of warning messages, but I guess that's what you want.

jackaraz commented 1 year ago

Hi @APMDSLHC you should be getting warning about why optimiser failed and it should sayspey::Expanding the bounds. if you are getting something else could you let me know? thanks

jackaraz commented 1 year ago

Hi @APMDSLHC you should be getting warning about why optimiser failed and it should sayspey::Expanding the bounds. if you are getting something else could you let me know? thanks

APMDSLHC commented 1 year ago

Yes that's the warning I get:

RuntimeWarning: Inequality constraints incompatible
spey::Expanding the bounds.