我需要找出如何计算'超几何cdf':
我知道函数是怎么样的以及它是如何工作的但我在将函数转换为python时遇到了一些问题:
def hypergeometricCDF(N,K,n,x):
"""
Call:
p = hypergeometricCDF(N,K,n,x)
Input argument:
N: integer
K: integer
n: integer
x: integer
Output argument:
p: float
Example:
hypergeometricCDF(120,34,12,7)
=>
0.995786
"""
f=sum(range(x+1))
p = log_binomial_coeff(N-K,n-f) + log_binomial_coeff(K,f) - log_binomial_coeff(N,n)
return(p)
问题是,如何将i的sum函数与x集成?我用sum(范围(x + 1))尝试了它但它不起作用。
答案 0 :(得分:0)
试试这个:
def hypergeometricCDF(N,K,n,x):
"""
Call:
p = hypergeometricCDF(N,K,n,x)
Input argument:
N: integer
K: integer
n: integer
x: integer
Output argument:
p: float
Example:
hypergeometricCDF(120,34,12,7)
=>
0.995786
"""
k = arange(x+1)
p = sum(exp(log_hypergeometricPMF(N,K,n,k)))
return(p)
log_hypergeometricPMF定义在文件的顶部;)