softmax 归一化

在数学,尤其是概率论和相关领域中,归一化指数函数,或称Softmax函数,是逻辑函数的一种推广。它能将一个含任意实数的K维向量z“压缩”到另一个K维实向量σ(z)中,使得每一个元素的范围都在(0,1)之间,并且所有元素的和为1。该函数多于多分类问题中。

https://baike.baidu.com/item/%E5%BD%92%E4%B8%80%E5%8C%96%E6%8C%87%E6%95%B0%E5%87%BD%E6%95%B0/22660782?fr=aladdin

import  math
 
=  [ 1.0 2.0 3.0 4.0 1.0 2.0 3.0 ]
 
z_exp  =  [math.exp(i)  for  in  z]  
 
print (z_exp)   # Result: [2.72, 7.39, 20.09, 54.6, 2.72, 7.39, 20.09] 
 
sum_z_exp  =  sum (z_exp)  
print (sum_z_exp)   # Result: 114.98 
# Result: [0.024, 0.064, 0.175, 0.475, 0.024, 0.064, 0.175]
 
softmax  =  [ round (i  /  sum_z_exp,  3 for  in  z_exp]
print (softmax)  
 

猜你喜欢

转载自www.cnblogs.com/kuipertan/p/12769517.html