You will get this error if your exponential value becomes too great. Since you are using math.exp
, this value will be a float.
Depending on your system, the largest float number in your system will be defined by your 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)
So on my system, 1.7976931348623157e+308
is the largest float I could possibly have.
You can check the following runs for an analysis of the same:
>>> 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