Softmax回归

From Ufldl

Jump to: navigation, search
(Introduction介绍)
(Introduction介绍)
Line 6: Line 6:
== Introduction介绍 ==
== Introduction介绍 ==
 +
'''原文''':
'''原文''':
Line 37: Line 38:
h_\theta(x) = \frac{1}{1+\exp(-\theta^Tx)},
h_\theta(x) = \frac{1}{1+\exp(-\theta^Tx)},
\end{align}</math>
\end{align}</math>
-
 
Line 44: Line 44:
,其中 m为样本数,<math>x^{(i)} \in \Re^{n+1}</math>为特征。
,其中 m为样本数,<math>x^{(i)} \in \Re^{n+1}</math>为特征。
由于 logistic 回归是针对二分类问题的,因此类标 <math>y^{(i)} \in \{0,1\}</math>。假设函数如下:
由于 logistic 回归是针对二分类问题的,因此类标 <math>y^{(i)} \in \{0,1\}</math>。假设函数如下:
 +
<math>\begin{align}
 +
h_\theta(x) = \frac{1}{1+\exp(-\theta^Tx)},
 +
\end{align}</math>
'''一审''':
'''一审''':
Line 53: Line 56:
'''原文''':
'''原文''':
 +
and the model parameters <math>\theta</math> were trained to minimize
and the model parameters <math>\theta</math> were trained to minimize
the cost function
the cost function
-
 
<math>
<math>
\begin{align}
\begin{align}
Line 64: Line 67:
'''译文''':
'''译文''':
-
 
+
模型参数 θ 用于最小化损失函数
 +
<math>
 +
\begin{align}
 +
J(\theta) = -\frac{1}{m} \left[ \sum_{i=1}^m y^{(i)} \log h_\theta(x^{(i)}) + (1-y^{(i)}) \log (1-h_\theta(x^{(i)})) \right]
 +
\end{align}
 +
</math>
'''一审''':
'''一审''':
 +
我们将训练模型参数 θ ,使其能够最小化 代价函数 :
 +
 +
<math>
 +
\begin{align}
 +
J(\theta) = -\frac{1}{m} \left[ \sum_{i=1}^m y^{(i)} \log h_\theta(x^{(i)}) + (1-y^{(i)}) \log (1-h_\theta(x^{(i)})) \right]
 +
\end{align}
 +
</math>
'''原文''':
'''原文''':
Line 80: Line 95:
'''译文''':
'''译文''':
 +
在 softmax回归中,我们解决的是多分类问题(相对于 logistic 回归解决的二分类问题),类标 y 可以取 k个不同的值(而不是 2 个)。因此,对于训练集 <math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math>,我们有 <math>y^{(i)} \in \{1, 2, \ldots, k\}</math>。(注意此处的类别下标从 1 开始,而不是 0)。例如,在 MNIST 数字识别任务中,我们有 k=10 个不同的类别。
'''一审''':
'''一审''':
 +
在 softmax回归中,我们 感兴趣的是 多元分类 (相对于 只能辨识两种类型的 二元分类 ), 所以类型标记 y 可以取 k个不同的值(而不 只限于 2个)。 于是 ,对于我们的 训练集<math>\{ (x^{(1)}, y^{(1)}), \ldots, (x^{(m)}, y^{(m)}) \}</math> 便有<math>y^{(i)} \in \{1, 2, \ldots, k\}</math>。(注意, 我们约定 类别下标从 1 开始,而不是 0)。例如,在 MNIST 数字识别任务中,我们有 k=10 个不同的类别。
 +
'''原文''':
'''原文''':
Line 113: Line 131:
'''译文''':
'''译文''':
 +
给定一个测试样本 x ,我们想让假设函数去估计该样本在每一个类别  上的概率 p(y = j | x),例如,我们想要估计类标在 k 个不同类别上的概率。因此,我们的假设函数会输出一个 k 维的向量(向量元素的和为 1 )来表示样本 x在 k 个类别上的概率值。具体地说,我们的假设函数 hθ(x) 形式如下:
 +
<math>
 +
\begin{align}
 +
h_\theta(x^{(i)}) =
 +
\begin{bmatrix}
 +
p(y^{(i)} = 1 | x^{(i)}; \theta) \\
 +
p(y^{(i)} = 2 | x^{(i)}; \theta) \\
 +
\vdots \\
 +
p(y^{(i)} = k | x^{(i)}; \theta)
 +
\end{bmatrix}
 +
=
 +
\frac{1}{ \sum_{j=1}^{k}{e^{ \theta_j^T x^{(i)} }} }
 +
\begin{bmatrix}
 +
e^{ \theta_1^T x^{(i)} } \\
 +
e^{ \theta_2^T x^{(i)} } \\
 +
\vdots \\
 +
e^{ \theta_k^T x^{(i)} } \\
 +
\end{bmatrix}
 +
\end{align}
 +
</math>
'''一审''':
'''一审''':
 +
对于给定的测试输入,我们想让 估值函数 针对每一个  估算出概率值 p(y = j | x) 。也就是说, 我们想估计出分类结果在每一个分类标记值上出现的概率 ( 一审注:而不是估算出具体是取哪一个值,这一点和基本神经网络估值函数输出最终值是有区别的 ) 。因此,我们的 估值函数 将要 输出一个 k维的向量(向量元素的和为 1 )来表示这 k 被估计出的概率值。 具体地说,我们的 估值函数hθ(x) 形式如下:
 +
<math>
 +
\begin{align}
 +
h_\theta(x^{(i)}) =
 +
\begin{bmatrix}
 +
p(y^{(i)} = 1 | x^{(i)}; \theta) \\
 +
p(y^{(i)} = 2 | x^{(i)}; \theta) \\
 +
\vdots \\
 +
p(y^{(i)} = k | x^{(i)}; \theta)
 +
\end{bmatrix}
 +
=
 +
\frac{1}{ \sum_{j=1}^{k}{e^{ \theta_j^T x^{(i)} }} }
 +
\begin{bmatrix}
 +
e^{ \theta_1^T x^{(i)} } \\
 +
e^{ \theta_2^T x^{(i)} } \\
 +
\vdots \\
 +
e^{ \theta_k^T x^{(i)} } \\
 +
\end{bmatrix}
 +
\end{align}
 +
</math>
'''原文''':
'''原文''':
Line 124: Line 182:
'''译文''':
'''译文''':
 +
其中 <math>\theta_1, \theta_2, \ldots, \theta_k \in \Re^{n+1}</math>  均为模型参数, the term <math>\frac{1}{ \sum_{j=1}^{k}{e^{ \theta_j^T x^{(i)} }} } </math> 是模型的归一化因子,使得向量的和为 1 。
'''一审''':
'''一审''':
 +
其中  <math>\theta_1, \theta_2, \ldots, \theta_k \in \Re^{n+1}</math>是我们模型的参数。请注意<math>\frac{1}{ \sum_{j=1}^{k}{e^{ \theta_j^T x^{(i)} }} } </math>,这一项对概率分布进行归一化,使得所有概率之和为 1 。
 +
'''原文''':
'''原文''':
Line 134: Line 195:
stacking up <math>\theta_1, \theta_2, \ldots, \theta_k</math> in rows, so that
stacking up <math>\theta_1, \theta_2, \ldots, \theta_k</math> in rows, so that
 +
<math>
 +
\theta = \begin{bmatrix}
 +
\mbox{---} \theta_1^T \mbox{---} \\
 +
\mbox{---} \theta_2^T \mbox{---} \\
 +
\vdots \\
 +
\mbox{---} \theta_k^T \mbox{---} \\
 +
\end{bmatrix}
 +
</math>
 +
 +
'''译文''':
 +
为了简便,我们使用 θ 来表示模型参数。在实现 softmax 回归的时候,往往使用一个 k-by-(n + 1) 的矩阵来表示 θ。我们将  按行表示,得到
 +
<math>
 +
\theta = \begin{bmatrix}
 +
\mbox{---} \theta_1^T \mbox{---} \\
 +
\mbox{---} \theta_2^T \mbox{---} \\
 +
\vdots \\
 +
\mbox{---} \theta_k^T \mbox{---} \\
 +
\end{bmatrix}
 +
</math>
 +
 +
'''一审''':
 +
为了方便起见,我们同样使用符号 θ 来表示全部的模型参数。在实现 softmax 回归时,你通常会发现,将 θ 用一个k × (n+1)的矩阵来表示会十分便利,该矩阵是将  按行罗列起来得到的,如下所示:
<math>
<math>
\theta = \begin{bmatrix}
\theta = \begin{bmatrix}

Revision as of 08:54, 10 March 2013

Personal tools