sigmoid RuntimeWarning: overflow encountered in exp

前端 未结 1 1891
我寻月下人不归
我寻月下人不归 2021-01-20 05:08

I\'m trying to create a sigmoid function in Python, however, I get the following error:

RuntimeWarning: overflow encountered in exp

Here my

相关标签:
1条回答
  • 2021-01-20 05:24

    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)
    
    0 讨论(0)
提交回复
热议问题