機械学習に詳しくなりたいブログ

機械学習や数学について勉強した内容を中心に書きます。100%趣味です。記事は数学的に厳密でなかったり誤りを含んでいるかもしれません。ご指摘頂ければ幸いです。

サポートベクターマシン(ハードマージン)(2)

サポートベクターマシン(ハードマージン)(1)の続きです。 先回、求める解は


\displaystyle  \frac{1}{2}\|\mathbf{w}\|^{2}  \tag{1}

を、


t_n(\mathbf{w}^{T}\phi(\mathbf{x}_n)+b) \ge 1 \quad\quad  (n=1,\cdots,N) \tag{2}

という2次計画問題となることを確認しました。この問題を解きやすい形にするため、2次計画における双対問題の手順に沿って双対問題を導出します。手順は、

  1. ラグランジュ関数を作る
  2. \displaystyle \frac{\partial L}{\partial \mathbf{w}}=0\displaystyle \frac{\partial L}{\partial b}=0を求める
  3. 求めた\mathbf{w},bを使って、ラグランジュ関数から\mathbf{w},bを消去する
  4. 双対問題が完成。もとのラグランジュ関数に比べ、制約条件が少なく、解くのが簡単になる。

です。まず手順1。不等式制約におけるラグランジュの未定乗数法(KKT条件)より、ラグランジュ乗数a_nを用いれば、ラグランジュ関数は


\displaystyle L(\mathbf{w},b,\mathbf{a}) = \frac{1}{2} \| \mathbf{w} \|^{2} - \sum_{n=1}^{N} a_n ( t_n (\mathbf{w}^{T} \phi(\mathbf{x}_n)+b)-1) \,\,\,\,\,\,\,\, (a_n\ge0)\tag{3}

と書けます。

次に手順2。\displaystyle \frac{\partial L}{\partial \mathbf{w}}=0\displaystyle \frac{\partial L}{\partial b}=0を計算すれば*1


\begin{eqnarray*}
\displaystyle \frac{\partial L}{\partial \mathbf{w}}=\mathbf{w} - \sum_{n=1}^{N}a_n t_n \phi(\mathbf{x}_n) &=& 0 \tag{4} \\
\mathbf{w} &=& \sum_{n=1}^{N}a_n t_n \phi(\mathbf{x}_n)  \tag{5}
\end{eqnarray*}


\displaystyle \frac{\partial L}{\partial b} = \sum_{n=1}^{N}a_n t_n = 0 \tag{6}

です。

次に手順3・4。式(5)、(6)を、式(3)のラグランジュ関数に代入して\mathbf{w},bを消去して双対問題\tilde{L}を作ります。まずそのまま代入すれば、


\begin{equation*}
\begin{split}
\displaystyle \tilde{L}(\mathbf{a})&= \frac{1}{2} \left( \sum_{n=1}^{N}a_n t_n \phi(\mathbf{x}_n) \right)^{T} \left(  \sum_{n=1}^{N}a_n t_n \phi(\mathbf{x}_n)\right)  \\
&- \sum_{n=1}^{N}a_n t_n \left( \sum_{m=1}^{N}a_m t_m \phi(\mathbf{x}_m) \right)^{T} \phi(\mathbf{x}_n) +\sum_{n=1}^{N}a_n
\end{split}
\end{equation*}
\tag{7}

です。式(7)右辺の1番目の項は、カーネル関数を用いてk(\mathbf{x}_i,\mathbf{x}_j) = \phi^{T}(\mathbf{x}_i)\phi(\mathbf{x}_j)とすれば、


\displaystyle  \frac{1}{2} \sum_{n=1}^{N}\sum_{m=1}^{N} a_n t_n a_m t_m k(\mathbf{x}_n,\mathbf{x}_m) \tag{8}

と書けます。同様に式(7)右辺の2番目の項も計算すれば、


\displaystyle  - \sum_{n=1}^{N}\sum_{m=1}^{N} a_n t_n a_m t_m k(\mathbf{x}_n,\mathbf{x}_m) \tag{9}

です。したがって、双対問題は


\displaystyle \tilde{L}(\mathbf{a}) =  \sum_{n=1}^{N}a_n -\frac{1}{2} \sum_{n=1}^{N}\sum_{m=1}^{N} a_n t_n a_m t_m k(\mathbf{x}_n,\mathbf{x}_m) \tag{10}

となります。なおここで、


\displaystyle  \sum_{n=1}^{N} a_n t_n =0 \tag{11}


a_n \ge 0 \tag{12}

です。

最適解においては、不等式制約におけるラグランジュの未定乗数法(KKT条件)で示すKKT条件が成立します。今回の問題におけるKKT条件は以下です。


a_n \ge 0 \tag{13}


t_n(\mathbf{w}^{T}\phi(\mathbf{x}_n)+b) -1 \ge 0 \tag{14}


a_n  \{ t_n ( \mathbf{w}^{T}\phi(\mathbf{x}_n)+b)  -1  \} = 0 \tag{15}

続きは次回。