Sigmoid函数的替代:overflow encountered in exp in computing the logistic function


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))

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM