首页 > 其他 > 详细

softmax

时间:2019-12-04 17:24:49      阅读:109      评论:0      收藏:0      [点我收藏+]

1、what ?

 Softmax function, a wonderful activation function that turns numbers aka logits into probabilities that sum to one. Softmax function outputs a vector that represents the probability distributions of a list of potential outcomes. 

 

技术分享图片

 

 2、how ?

  two component

  special number e  & sum 

  

3、Why not just divide each logits by the sum of logits? Why do we need exponents?

  When logits are negative, adding it together does not give us the correct normalizationexponentiate logitsturn them them zero or positive!  参考补充知识Logits。

 

4、python 实现代码:

import numpy as np

def softmax(logits):
    ## 以e 为底,list 元素为指数,求幂次方 ,python 方法 np.exp
    exps = [np.exp(logit) for logit in logits]
    # 求指数和
    sum_of_exps = sum(exps)

    #利用softmax公式,y_i/y_j
    softmax = [j / sum_of_exps for j in exps]

    return softmax

if __name__ == ‘__main__‘:

    # print(np.exp(-100))

    logits = [2.0, 1.0, 0.1]
    softmax = softmax(logits)

    print(softmax)

  

补充知识:

  1、对数 

技术分享图片

 

  2、自然对数:以常数e为底数的对数,记作lnN(N>0)

 

  3、Odds 与 probability

    概率(Probability)和Odds都是用来描述某件事情发生的可能性的。

    概率技术分享图片是一个0到1之间的实数;技术分享图片表示一定不会发生,而技术分享图片则表示一定会发生。

    Odds指的是事件发生的概率与事件不发生的概率之比。

    事件A的Odds 等于 事件A出现的次数 和 其它(非A)事件出现的次数 之比;相比之下,事件A的概率 等于 事件A出现的次数 与 所有事件的次数 之比。

    概率技术分享图片的变化范围是技术分享图片,而Odds的变化范围是技术分享图片。再进一步,如果对Odds取自然对数,lnOdds范围为技术分享图片。换句话就是将概率P从范围技术分享图片映射到技术分享图片

 

    4、Logits 

      Odds的对数称之为Logit。取之范围技术分享图片

 

参考资料:

https://medium.com/data-science-bootcamp/understand-the-softmax-function-in-minutes-f3a59641e86d

https://zhuanlan.zhihu.com/p/27188729

 

softmax

原文:https://www.cnblogs.com/unicorn2105/p/11984155.html

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