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))
相關文章
相關標籤/搜索