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