can*_*his 2 python floating-point statistics numpy rounding
我在python中进行似然比测试时遇到了数值问题.关于统计数据的含义,我不会详细说明,我的问题归结为计算:
LR = LR_H0 / LR_h1
Run Code Online (Sandbox Code Playgroud)
LR感兴趣的数量在哪里,LR_H0而且LR_H1数字可能非常接近于零.这导致了一些数值问题; 如果LR_H1太小,那么python会将其识别为零除以.
ZeroDivisionError: float division by zero
Run Code Online (Sandbox Code Playgroud)
此外,虽然这不是主要问题,但如果LR_H1小到足以允许除法,那么分数LR_H0 / LR_h1可能变得太大(我假设python也有浮点数的上限值).
关于解决这个问题的最佳方法的任何提示?我正在考虑做类似的事情:
def small_enough( num ):
if num == 0.0:
return *other small number*
else:
return num
Run Code Online (Sandbox Code Playgroud)
但这并不理想,因为它会接近这个LR值,我想保证一些精确度.