RuntimeWarning: overflow encountered in exp in computing the logistic function
以下是sigmoid函数的标准写法,但是如果x很大或导致函数exp(-x)溢出
def logistic_function(x): # x = np.float64(x) return 1.0 / (1.0 + np.exp(-x))
安全的替代写法如下:
def logistic_function(x): return .5 * (1 + np.tanh(.5 * x))
本文介绍了在计算Sigmoid函数时可能遇到的溢出问题,并提供了一种安全的替代写法,使用np.tanh函数避免了exp函数在大数值下引起的溢出错误。

1134

被折叠的 条评论
为什么被折叠?



