首页 > 其他 > 详细

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

时间:2019-05-25 15:36:22      阅读:1182      评论:0      收藏:0      [点我收藏+]

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函数的替代:overflow encountered in exp in computing the logistic function

原文:https://www.cnblogs.com/houjun/p/10922352.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!