0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ヘッセ行列を用いたニュートン法の表記とその導出

0
Posted at

ニュートン法は関数の2次の導関数までを用いた最適化の手法です。当記事では下記を参考にヘッセ行列を用いたニュートン法の式表記とその導出について取り扱います。

1変数の最適化

関数$f(x)$の1次の導関数を$f'(x)$、2次の導関数を$f^{''}(x)$とおくとき、点$x + \Delta x$にけるテイラー展開の式は下記のように表されます。

\begin{align}
f(x + \Delta x) &= f(x) + f'(x) \Delta x + \frac{1}{2}f^{''}(x) \Delta x^{2} + \cdots \\
  & \simeq f(x) + f'(x) \Delta x + \frac{1}{2}f^{''}(x) \Delta x^{2} \quad (1)
\end{align}

上記に基づいて$f(x + \Delta x)$を$(1)$式に基づく2次式で近似するとき、この2次式を$\Delta x$で微分すると下記が得られます。

\begin{align}
\left( f(x) + f'(x) \Delta x + \frac{1}{2}f^{''}(x) \Delta x^{2} \right)' = f'(x) + f^{''}(x) \Delta x
\end{align}

ここで上記が$0$となるときの$\Delta x$は下記のように得ることができます。

\begin{align}
f'(x) + f^{''}(x) \Delta x &= 0 \\
f^{''}(x) \Delta x &= -f'(x) \\
\Delta x &= -\frac{f'(x)}{f^{''}(x)}
\end{align}

上記の式は「関数$f(x)$をテイラー展開によって2次近似する際に$x + \Delta x$が近似した2次式の極値を取る$\Delta x$は$\Delta x = -f'(x)/f^{''}(x)$である」のように解釈できます。ニュートン法はこの解釈に基づいて下記のような漸化式で最適化を行います。

\begin{align}
x & \longleftarrow x + \Delta x \\
  &= x - \frac{f'(x)}{f^{''}(x)}
\end{align}

1次のテイラー展開に基づく勾配法とニュートン法の使用にあたっては、勾配法では学習率$\alpha$によってステップ幅を調整する一方でニュートン法は2次の導関数を用いることによって学習率を定義する必要がない点に着目しておくと良いです。

\begin{align}
x_{n+1} &= x_{n} - \alpha f'(x_{n}) \quad (\mathrm{GradientDescent}) \\
x_{n+1} &= x_{n} - \frac{f'(x_{n})}{f^{''}(x_{n})} \quad (\mathrm{Newton})
\end{align}

上記の式より$\alpha$と$-1/f^{''}(x)$が対応するので「どちらの手法も傾きが大きい点ではステップ幅が大きくなる一方でニュートン法では傾きの変動が小さい場合にステップ幅が大きくなるように調整する」のように理解しておくと良いと思います。

多変数の最適化 (ヘッセ行列)

\begin{align}
f(x_{1} + \Delta x_{1}, \cdots , x_{n} + \Delta x_{n}) &= \bar{f} + \sum_{i=1}^{n} \frac{\partial^{2} \bar{f}}{\partial x_{i}} \Delta x_{i} + \frac{1}{2} \sum_{i,j=1}^{n} \frac{\partial^{2} \bar{f}}{\partial x_{i} \partial x_{j}} \Delta x_{i} \Delta x_{j} + \cdots \\
  & \simeq \bar{f} + \sum_{i=1}^{n} \frac{\partial \bar{f}}{\partial x_{i}} \Delta x_{i} + \frac{1}{2} \sum_{i,j=1}^{n} \frac{\partial \bar{f}}{\partial x_{i} \partial x_{j}} \Delta x_{i} \Delta x_{j} \quad (2) \\
\bar{f} &= f(x_{1}, \cdots , x_{n})
\end{align}

他変数のテイラー展開や2次近似は上記のような式で表すことができます。ここで$(2)$式を$\Delta x_{i}$で微分して$0$とするとき下記のような式が得られます。

\begin{align}
\frac{\partial \bar{f}}{\partial x_{i}} + \sum_{j=1}^{n} \frac{\partial^{2} \bar{f}}{\partial x_{i} \partial x_{j}} \Delta x_{j} &= 0 \\
\sum_{j=1}^{n} \frac{\partial^{2} \bar{f}}{\partial x_{i} \partial x_{j}} \Delta x_{j} &= -\frac{\partial \bar{f}}{\partial x_{i}} \quad (3)
\end{align}

ここで下記のようにベクトル$\mathbf{x}$とベクトル微分$\nabla$を定義します。

\begin{align}
\mathbf{x} &= \left(\begin{array}{c} x_{1} \\ \vdots \\ x_{n} \end{array} \right) \\
\nabla &= \left(\begin{array}{c} \displaystyle \frac{\partial}{\partial x_{1}} \\ \vdots \\ \displaystyle \frac{\partial}{\partial x_{n}} \end{array} \right)
\end{align}

また、下記のように$\Delta \mathbf{x}$とヘッセ行列$H$も定義します。

\begin{align}
\Delta \mathbf{x} &= \left(\begin{array}{c} \Delta x_{1} \\ \vdots \\ \Delta x_{n} \end{array} \right) \\
H &= \left(\begin{array}{ccc} \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{1}^{2}} & \cdots & \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{1} \partial x_{n}} \\ \vdots & \ddots & \vdots \\ \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{n} \partial x_{1}} & \cdots & \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{n}^{2}} \end{array} \right)
\end{align}

このとき$(3)$式のベクトル表記は下記のように変形できます。

\begin{align}
\left(\begin{array}{c} \displaystyle \sum_{j=1}^{n} \frac{\partial^{2} \bar{f}}{\partial x_{1}x_{j}} \Delta x_{j} \\ \vdots \\ \displaystyle \sum_{j=1}^{n} \frac{\partial^{2} \bar{f}}{\partial x_{n}x_{j}} \Delta x_{j} \end{array} \right) &= -\left(\begin{array}{c} \displaystyle \frac{\partial \bar{f}}{\partial x_{1}} \\ \vdots \\ \displaystyle \frac{\partial \bar{f}}{\partial x_{n}} \end{array} \right) \\
\left(\begin{array}{ccc} \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{1}^{2}} & \cdots & \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{1} \partial x_{n}} \\ \vdots & \ddots & \vdots \\ \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{n} \partial x_{1}} & \cdots & \displaystyle \frac{\partial^{2} \bar{f}}{\partial x_{n}^{2}} \end{array} \right) \left(\begin{array}{c} \Delta x_{1} \\ \vdots \\ \Delta x_{n} \end{array} \right) &= -\nabla \bar{f} \\
H \Delta \mathbf{x} &= -\nabla \bar{f}
\end{align}

このように多変数関数のニュートン法の式はヘッセ行列を用いて表すことができます。

\begin{align}
\mathbf{x} & \longleftarrow \mathbf{x} + \Delta \mathbf{x} \\
  &= \mathbf{x} - H^{-1} \nabla \bar{f}
\end{align}

ヘッセ行列$H$は2次の導関数に対応するので上記と下記の1変数関数のニュートン法の式を対応させながら理解すると良いと思います。

\begin{align}
x & \longleftarrow x + \Delta x \\
  &= x - \frac{f'(x)}{f^{''}(x)}
\end{align}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?