Avoid overflow with softplus function in python

前端 未结 4 697
不思量自难忘°
不思量自难忘° 2021-02-14 05:20

I am trying to implement the following softplus function:

log(1 + exp(x))

I\'ve tried it with math/numpy and float64 as data type, but whenever

4条回答
  •  忘掉有多难
    2021-02-14 06:08

    i use this code to work in arrays

    def safe_softplus(x):
        inRanges = (x < 100)
        return np.log(1 + np.exp(x*inRanges))*inRanges + x*(1-inRanges)
    

提交回复
热议问题