Skip to content

#DeepLearning #Softmax #Argmax

Softmax and Argmax

  • argmax
  • softmax

Argmax

The argmax function returns the index of the maximum value in a given array or function. Mathematically, it can be represented as:

argmaxif(xi)={if(xi)f(xj) for all j}
  • 简单的说, 有一个数组x1,x2,,xn, argmax 会找到最大数字的下标

[!example]+ 给定数组如下

  • [1.5,3.2,0.7,4.1]
  • argmax 将会返回3,因为最大值 4.1在数组的下标是3
  • 优点在于可以简单直接的解释输出
  • 缺点在与argmax不可导,不可用于训练模型

所以一般可以用argmax输出,softmax训练

Softmax

The softmax function converts a vector of values into probabilities, such that the sum of all probabilities equals 1. The formula for softmax is:

softmax(xi)=exij=1nexj

Where:

  • xi is the ith element of the input vector.

  • exi represents the exponential of the ith element.

  • The denominator is the sum of the exponentials of all elements in the input vector.

  • 这种转换在多类分类问题中特别有用,其中softmax函数的输出表示不同类的预测概率。

[!example]+ 给定数组如下

  • [1.0,2.0,3.0]
  • softmax函数将返回一个概率向量:
softmax(x)=[e1e1+e2+e3,e2e1+e2+e3,e3e1+e2+e3]