Skip to content

Commit

Permalink
Force risk to be non-negative (growthbook#939)
Browse files Browse the repository at this point in the history
* Force risk to be non-negative

* lint
  • Loading branch information
lukesonnet authored Jan 25, 2023
1 parent b33a6ec commit 199675f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/stats/gbstats/bayesian/dists.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def risk(cls, a_par1, a_par2, b_par1, b_par2, n=24):
)
out = gq - cls.dist.mean((a_par1, b_par1), (a_par2, b_par2))

return out
return np.maximum(out, 0)


class Beta(BayesABDist):
Expand Down
6 changes: 6 additions & 0 deletions packages/stats/tests/bayesian/test_dists.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ def test_gq(self):
roundsum(np.log(x) * w), roundsum(digamma(a) - digamma(a + b))
)

def test_risk_nonnegative(self):
# Test used to fail before solution to GH issue
risk = Beta.risk(5563, 1281, 4605, 2888).tolist()
for r in risk:
self.assertGreaterEqual(r, 0)


class TestNorm(TestCase):
def test_posterior(self):
Expand Down

0 comments on commit 199675f

Please sign in to comment.