Fast sigmoid algorithm

后端 未结 11 1895
庸人自扰
庸人自扰 2020-12-12 15:55

The sigmoid function is defined as

I found that using the C built-in function exp() to calculate the value of f(x) is slow. Is th

11条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 16:35

    You can use a simple but effective method by using two formulas:

    if x < 0 then f(x) = 1 / (0.5/(1+(x^2)))
    if x > 0 then f(x) = 1 / (-0.5/(1+(x^2)))+1
    

    This will look like this:

    Two graphs for a sigmoid {Blue: (0.5/(1+(x^2))), Yellow: (-0.5/(1+(x^2)))+1}

提交回复
热议问题