Skip to content

Commit

Permalink
Merge pull request #4 from FINRAOS/hotfix-credibility
Browse files Browse the repository at this point in the history
Hotfix credibility
  • Loading branch information
aeftimia authored Aug 17, 2022
2 parents 57bf478 + 9e4ef5e commit f9b31f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mvtk/credibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def credible_interval(positive, negative, credibility=0.5, prior=(1, 1)):
returns:
(lower bound, upper bound)
"""
distribution = beta(positive + prior[0], negative + prior[1])
positive += prior[0]
negative += prior[1]
distribution = beta(positive, negative)
if positive + negative <= 0:
raise ValueError("Counts plus pseudocounts must be positive")
mode = positive / (positive + negative)
cdf_mode = distribution.cdf(mode)
cred_2 = credibility / 2
Expand Down
2 changes: 1 addition & 1 deletion mvtk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.1"
__version__ = "0.1.2"
14 changes: 14 additions & 0 deletions tests/credibility/test_credibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
from mvtk import credibility


def test_value_error():
try:
credibility.credible_interval(0, 0, prior=(0, 0))
except ValueError:
return
raise Exception("Expected ValueError")


def test_equivalence():
assert credibility.credible_interval(0, 0) == credibility.credible_interval(
1, 1, prior=(0, 0)
)


def test_prob_greater_cmp():
nprng = numpy.random.RandomState(0)
prior_sample_size = 10**6
Expand Down

0 comments on commit f9b31f8

Please sign in to comment.