|
12 | 12 | from smodels.base.smodelsLogging import logger |
13 | 13 | import numpy as np |
14 | 14 | from smodels.statistics.exceptions import SModelSStatisticsError as SModelSError |
15 | | -from typing import Text |
| 15 | +from typing import Text, Union |
16 | 16 | from collections.abc import Callable |
17 | 17 |
|
18 | 18 | __all__ = [ "CLsfromNLL", "determineBrentBracket", "chi2FromLmax" ] |
19 | 19 |
|
| 20 | +from enum import Enum |
| 21 | + |
| 22 | +class NllEvalType(Enum): |
| 23 | + """ an enum to account for the different types of likelihood values: observed, |
| 24 | + a priori expected, a posteriori expected """ |
| 25 | + observed = 0 |
| 26 | + aposteriori = 1 |
| 27 | + apriori = 2 |
| 28 | + |
| 29 | + @classmethod |
| 30 | + def init ( cls, evaluationType : Union[str,bool] ): |
| 31 | + """ get evaluationtype either from a string (e.g. 'priori') or a bool |
| 32 | + (true is posteriori, false is observed) |
| 33 | + """ |
| 34 | + evaluationType = str(evaluationType).lower().replace("_","") |
| 35 | + if evaluationType in [ "posteriori", "aposteriori", "posterior" ]: |
| 36 | + return cls.aposteriori |
| 37 | + if evaluationType in [ "apriori", "prior", "priori", "true" ]: |
| 38 | + return cls.apriori |
| 39 | + if evaluationType in [ "false", "observed", "obs" ]: |
| 40 | + return cls.observed |
| 41 | + raise SModelSError ( f"NllEvalType {evaluationType} unknown" ) |
| 42 | + |
| 43 | + def __eq__ ( self, other ): |
| 44 | + if type ( other ) == NllEvalType: |
| 45 | + return super().__eq__ ( other ) |
| 46 | + if type ( other ) in [ bool, str ]: |
| 47 | + return super().__eq__ ( NllEvalType.init ( other ) ) |
| 48 | + raise SModelSError ( f"comparing a NllEvalType with {type(other)}" ) |
| 49 | + |
20 | 50 | def CLsfromNLL( |
21 | 51 | nllA: float, nll0A: float, nll: float, nll0: float, big_muhat : bool, |
22 | 52 | return_type: Text = "CLs-alpha" ) -> float: |
|
0 commit comments