Skip to content

Commit

Permalink
some protection against failing maximum likelihood fits
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangWaltenberger committed Mar 23, 2024
1 parent 03ab812 commit 91b95f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 6 additions & 5 deletions smodels/matching/theoryPrediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,12 @@ def computeStatistics(self, expected=False):
# Compute likelihoods and related parameters:
llhdDict = self.statsComputer.get_five_values(expected = expected,
return_nll = True )
self.cachedObjs[expected]["nll"] = llhdDict["lbsm"]
self.cachedObjs[expected]["nll_sm"] = llhdDict["lsm"]
self.cachedObjs[expected]["nllmax"] = llhdDict["lmax"]
self.cachedObjs[expected]["muhat"] = llhdDict["muhat"]
self.cachedObjs[expected]["sigma_mu"] = llhdDict["sigma_mu"]
if llhdDict not in [ None, {} ]:
self.cachedObjs[expected]["nll"] = llhdDict["lbsm"]
self.cachedObjs[expected]["nll_sm"] = llhdDict["lsm"]
self.cachedObjs[expected]["nllmax"] = llhdDict["lmax"]
self.cachedObjs[expected]["muhat"] = llhdDict["muhat"]
self.cachedObjs[expected]["sigma_mu"] = llhdDict["sigma_mu"]


class TheoryPredictionsCombiner(TheoryPrediction):
Expand Down
2 changes: 2 additions & 0 deletions smodels/statistics/statsTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ def get_five_values ( self, expected : Union [ bool, Text ],
correct, if necessary
"""
ret = self.maximize_likelihood ( expected = expected, return_nll = return_nll )
if ret is None:
return {}
lmax = ret['lmax']

lbsm = self.likelihood ( poi_test = 1., expected=expected, return_nll = return_nll )
Expand Down

0 comments on commit 91b95f3

Please sign in to comment.