Last active
April 22, 2020 18:27
-
-
Save vlavorini/41d5440d107cc19453c862458804787c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import lgamma | |
from numba import jit | |
#defining the functions used | |
@jit | |
def h(a, b, c, d): | |
num = lgamma(a + c) + lgamma(b + d) + lgamma(a + b) + lgamma(c + d) | |
den = lgamma(a) + lgamma(b) + lgamma(c) + lgamma(d) + lgamma(a + b + c + d) | |
return np.exp(num - den) | |
@jit | |
def g0(a, b, c): | |
return np.exp(lgamma(a + b) + lgamma(a + c) - (lgamma(a + b + c) + lgamma(a))) | |
@jit | |
def hiter(a, b, c, d): | |
while d > 1: | |
d -= 1 | |
yield h(a, b, c, d) / d | |
def g(a, b, c, d): | |
return g0(a, b, c) + sum(hiter(a, b, c, d)) | |
def calc_prob_between(beta1, beta2): | |
return g(beta1.args[0], beta1.args[1], beta2.args[0], beta2.args[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment