I\'m trying to create a sigmoid function in Python, however, I get the following error:
RuntimeWarning: overflow encountered in exp
Here my
A warning is not an error. You could just ignore it.
That said, it happens when the result of exp(-value)
exceeds the maximum number representable by value
's floating point data type format.
You can prevent the overflow by checking if value
is too small:
def sigmoid(value):
if -value > np.log(np.finfo(type(value)).max):
return 0.0
a = np.exp(-value)
return 1.0/ (1.0 + a)