类似于Python:OverflowError:数学范围错误。以下是我的代码,以及尝试调试时遇到的错误(和变量值)。在python控制台中手动进行数学运算可以正常工作。是因为sigma是整数吗?对于它的价值,MSE变量是通过对一个numpy数组求和而生成的,而simga变量只是经过硬编码的“ 100”。
def normalize_error(sigma, mse):
return math.exp(-mse/(2*(sigma**2)))
如果您的指数值太大,则会出现此错误。由于您正在使用math.exp
,因此该值将是一个浮点数。
根据您的系统,系统中最大的浮点数将由定义sys.float_info
。
>>> import sys
>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
因此,在我的系统上,1.7976931348623157e+308
是我可能拥有的最大浮子。
您可以检查以下运行以进行相同的分析:
>>> import math
>>> def normalize_error(sigma, mse):
... return math.exp(-mse/(2*(sigma**2)))
...
>>> normalize_error(3, 4)
0.36787944117144233
>>> normalize_error(3, -4)
1.0
>>> normalize_error(.3, -4)
4477014353.361036
>>> normalize_error(.3, -100)
1.8824011022575583e+241
>>> normalize_error(.02, -100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in normalize_error
OverflowError: math range error
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句