问题描述
有没有人实现了一个省时且相对准确的较低不完整 beta 函数?我目前的尝试产生了一些不准确的结果,如果我降低增量值,脚本就会超时;由于在每个数据点上计算长循环,在其他脚本中按原样包含函数会使它们超时。
看着其他有点related problems的解决方案,我不禁觉得有一个类似的技巧,但我不明白为什么他们的解决方案有效(使用看似任意的浮点值)。一个理想的解决方案是以某种方式最大限度地减少循环的使用。
这里的目标是使用此函数,以便使用学生 t 分布在 pinescript 中计算准确的 P 值,这需要 beta 的 CDF,而 beta 又需要此函数。
_beta_incomplete(x,a,b) =>
var float i = 0.000001
float _a = a - 1
float _b = b - 1
float integral = 0.0
for t = i to x by i
integral := integral + pow(t,_a) * pow(1 - t,_b)
integral * i
更新:我尝试复制 this implementation。输出完全错误,但我不确定我哪里出错了。
// The functions gamma_incomplete,standard_normal_pdf and standard_normal_cdf have already been vetted
_h(z,x2,c,v) =>
float q = v * pow(z + c,2) / x2
-log(2) - 0.5 * (q - v - (v - 2) * log(q / v) + log(v) + log(2 * pi) + pow(z,2))
_g(z,v) => _gamma_incomplete(v * pow(z + c,2) / (2 * x2),v / 2) * standard_normal_pdf(z)
_t_distribution_cdf(x,dof) =>
var float er = pow(10,-16)
var float ler = log(er)
var float th = 37.5194
// Non-centrality parameter...don't kNow what it's for,so set to 0
var float c = 0
float x2 = pow(x,2)
float sdof = sqrt(dof)
float zmod = (-c * (x2 + 2 * dof) + x * sqrt(4 * dof * (dof - 2) + x2 * (pow(c,2) + 4 * (dof - 2)))) / (2 * (x2 + dof))
float qer = dof + 2 * er + 1.62 * sqrt(dof * er) + 0.63012 * sdof * ler - 1.12032 * sdof - 2.48 * sqrt(er) - 0.65381 * ler - 0.22872
// Todo: Is "ea" the right term to use here?
float ea = exp(_h(zmod,dof) + ler)
float a = max(max(max(-c,-th),sqrt(x2 * abs(qer) / dof) - c),ea)
float b = min(th,ea)
// This is my attempt to implement "nsubs" (page 7). I think they want to
// "bin" the integrands into 16 separate calculations which are summed to the integral
float factor = abs(a - b) / 16
float integral = standard_normal_cdf(a)
for z = a to b by factor
integral := integral + _g(z,dof)
integral
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)