Skip to content

Commit

Permalink
Merge pull request guillermo-navas-palencia#2 from alonme/support-ver…
Browse files Browse the repository at this point in the history
…y-large-beta-numbers

Support very large beta numbers
  • Loading branch information
idoadiv committed Jun 12, 2022
2 parents 7b9c95e + 6c7b354 commit 90869a3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cprior/cdist/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
from .utils import check_ab_method
from .utils import check_mv_method

def get_integration_points(a, b):
if a == 1 and b == 1:
return None

return [(a-1)/(a+b-2)]

def func_ppf(x, a0, b0, a1, b1, p):
"""Function CDF ratio of beta function for root-finding."""
Expand Down Expand Up @@ -796,7 +801,9 @@ def probability_vs_all(self, method="quad", variant="B", lift=0,
a = self.models[variant].alpha_posterior
b = self.models[variant].beta_posterior

return integrate.quad(func=func_mv_prob, a=0, b=1, args=(
points = get_integration_points(a, b)

return integrate.quad(func=func_mv_prob, a=0, b=1, points=points, args=(
a, b, variant_params))[0]
else:
# prepare parameters
Expand Down Expand Up @@ -1031,18 +1038,20 @@ def expected_loss_relative_vs_all(self, method="quad", control="A",

return (maxall / xvariant).mean() - 1
else:
a = self.models[variant].alpha_posterior
b = self.models[variant].beta_posterior

if method == "quad":
variant_params = [(self.models[v].alpha_posterior,
self.models[v].beta_posterior)
for v in variants]

e_max = integrate.quad(func=func_mv_elr, a=0, b=1, args=(
points = get_integration_points(a, b)
e_max = integrate.quad(func=func_mv_elr, a=0, b=1, points=points, args=(
variant_params))[0]
else:
e_max = self._expected_value_max_mlhs(variants, mlhs_samples)

a = self.models[variant].alpha_posterior
b = self.models[variant].beta_posterior
e_inv_x = (a + b - 1) / (a - 1)

return e_max * e_inv_x - 1
Expand Down Expand Up @@ -1180,8 +1189,10 @@ def expected_loss_vs_all(self, method="quad", variant="B", lift=0,
b = self.models[variant].beta_posterior

if method == "quad":
return integrate.quad(func=func_mv_el, a=0, b=1, args=(
points = get_integration_points(a, b)
return integrate.quad(func=func_mv_el, a=0, b=1, points=points, args=(
a, b, variant_params))[0]

else:
r = np.arange(1, mlhs_samples + 1)
np.random.shuffle(r)
Expand Down

0 comments on commit 90869a3

Please sign in to comment.