Softmax回归

From Ufldl

Jump to: navigation, search
(简介)
(代价函数 Cost Function)
Line 67: Line 67:
== 代价函数 Cost Function ==
== 代价函数 Cost Function ==
-
现在我们来介绍softmax回归算法的代价函数。在下面的公式中,<math>1\{\cdot\}</math>是示性函数,其取值规则为:
+
现在我们来介绍softmax回归算法的代价函数。在下面的公式中,<math>\textstyle 1\{\cdot\}</math>是示性函数,其取值规则为:
-
<math>1\{</math> 值为真的表达式<math>\}=1</math>
+
<math>\textstyle 1\{</math> 值为真的表达式<math>\textstyle \}=1</math>
-
,<math>1\{</math> 值为假的表达式<math>\}=0</math>。举例来说,表达式<math>1\{2+2=4\}</math>的值为1 ,<math>1\{1+1=5\}</math>的值为 0。我们的代价函数为:
+
,<math>\textstyle 1\{</math> 值为假的表达式<math>\textstyle \}=0</math>。举例来说,表达式<math>\textstyle 1\{2+2=4\}</math>的值为1 ,<math>\textstyle 1\{1+1=5\}</math>的值为 0。我们的代价函数为:
<math>
<math>
Line 78: Line 78:
-
值得注意的是,上述公式是logistic回归代价函数的推广。 logistic回归代价函数可以改为:
+
值得注意的是,上述公式是logistic回归代价函数的推广。logistic回归代价函数可以改为:
<math>
<math>
Line 88: Line 88:
-
可以看到,Softmax代价函数与logistic 代价函数在形式上非常类似,只是在Softmax损失函数中对类标记的<math>k</math>个可能值进行了累加。注意在Softmax回归中将<math>x</math>分类为类别<math>j</math>的概率为:
+
可以看到,Softmax代价函数与logistic 代价函数在形式上非常类似,只是在Softmax损失函数中对类标记的<math>\textstyle k</math>个可能值进行了累加。注意在Softmax回归中将<math>\textstyle x</math>分类为类别<math>\textstyle j</math>的概率为:
<math>
<math>
Line 95: Line 95:
-
对于<math>J(\theta)</math>的最小化问题,目前还没有闭式解法。因此,我们使用迭代的优化算法(例如梯度下降法,或 L-BFGS)。经过求导,我们得到梯度公式如下:
+
对于<math>\textstyle J(\theta)</math>的最小化问题,目前还没有闭式解法。因此,我们使用迭代的优化算法(例如梯度下降法,或 L-BFGS)。经过求导,我们得到梯度公式如下:
<math>
<math>
Line 104: Line 104:
-
让我们来回顾一下符号"<math>\nabla_{\theta_j}</math>"的含义。<math>\nabla_{\theta_j} J(\theta)</math>本身是一个向量,它的第<math>l</math>个元素<math>\frac{\partial J(\theta)}{\partial \theta_{jl}}</math>是<math>J(\theta)</math>对<math>\theta_j</math>的第<math>l</math>个分量的偏导数。
+
让我们来回顾一下符号"<math>\textstyle \nabla_{\theta_j}</math>"的含义。<math>\textstyle \nabla_{\theta_j} J(\theta)</math>本身是一个向量,它的第<math>\textstyle l</math>个元素<math>\textstyle \frac{\partial J(\theta)}{\partial \theta_{jl}}</math>是<math>\textstyle J(\theta)</math>对<math>\textstyle \theta_j</math>的第<math>\textstyle l</math>个分量的偏导数。
-
有了上面的偏导数公式以后,我们就可以将它代入到梯度下降法等算法中,来最小化<math>J(\theta)</math>。 例如,在梯度下降法的标准实现中,每一次迭代需要进行如下更新:<math>\theta_j := \theta_j - \alpha \nabla_{\theta_j} J(\theta)</math>(<math>j=1,\ldots,k</math>)。
+
有了上面的偏导数公式以后,我们就可以将它代入到梯度下降法等算法中,来最小化<math>\textstyle J(\theta)</math>。 例如,在梯度下降法的标准实现中,每一次迭代需要进行如下更新:<math>\textstyle \theta_j := \theta_j - \alpha \nabla_{\theta_j} J(\theta)</math>(<math>\textstyle j=1,\ldots,k</math>)。
当实现 softmax 回归算法时, 我们通常会使用上述代价函数的一个改进版本。具体来说,就是和权重衰减(weight decay)一起使用。我们接下来介绍使用它的动机和细节。
当实现 softmax 回归算法时, 我们通常会使用上述代价函数的一个改进版本。具体来说,就是和权重衰减(weight decay)一起使用。我们接下来介绍使用它的动机和细节。

Revision as of 06:05, 16 March 2013

Personal tools