第22章付録:深層学習のための数学
22.4.6. Hessians22.4.6 ヘッセ行列
As with single variable calculus, it is useful to consider higher-order derivatives in order to get a handle on how we can obtain a better approximation to a function than using the gradient alone.
英語のヒント
1変数の微積分と同じように、勾配だけを使うよりもよい関数の近似をどう得られるかをつかむには、高階導関数を考えると役に立つ。
There is one immediate problem one encounters when working with higher order derivatives of functions of several variables, and that is there are a large number of them. If we have a function of variables, then we can take many second derivatives, namely for any choice of and :
英語のヒント
多変数の関数の高階導関数を扱うときにすぐに出会う問題が一つある。それは、高階導関数の数が多いことである。変数の関数があるとき、個の2階導関数をとれる。すなわち、任意のとの選び方について、
(22.4.25)
This is traditionally assembled into a matrix called the Hessian:
英語のヒント
これは伝統的に、ヘッセ行列と呼ばれる行列にまとめられる。
(22.4.26)
Not every entry of this matrix is independent. Indeed, we can show that as long as both mixed partials (partial derivatives with respect to more than one variable) exist and are continuous, we can say that for any , and ,
英語のヒント
この行列のすべての成分が独立なわけではない。実際、両方の混合偏導関数(複数の変数についての偏導関数)が存在して連続であるかぎり、任意のとについて次が言えることを示せる。
(22.4.27)
This follows by considering first perturbing a function in the direction of , and then perturbing it in and then comparing the result of that with what happens if we perturb first and then , with the knowledge that both of these orders lead to the same final change in the output of .
英語のヒント
これは、まず関数をの方向に摂動させ、それからの方向に摂動させた結果と、まず、それからの順に摂動させたときに起きることとを比べ、どちらの順序でもの出力の最終的な変化は同じになることを知っていれば、そこから従う。
As with single variables, we can use these derivatives to get a far better idea of how the function behaves near a point. In particular, we can use it to find the best fitting quadratic near a point , as we saw in a single variable.
英語のヒント
1変数の場合と同じように、これらの導関数を使うと、ある点の近くで関数がどうふるまうかについてはるかによい考えが得られる。とくに、1変数で見たように、点の近くで最もよく当てはまる2次式を見つけるのに使える。
Let’s see an example. Suppose that . This is the general form for a quadratic in two variables. If we look at the value of the function, its gradient, and its Hessian (22.4.26), all at the point zero:
英語のヒント
例を見よう。とする。これは2変数の2次式の一般形である。関数の値、勾配、ヘッセ行列(式(22.4.26))を、すべて点0で見ると、
(22.4.28)
we can get our original polynomial back by saying
英語のヒント
次のように言うことで、もとの多項式を取り戻せる。
(22.4.29)
In general, if we computed this expansion any point , we see that
英語のヒント
一般に、この展開を任意の点で計算すると、次がわかる。
(22.4.30)
This works for any dimensional input, and provides the best approximating quadratic to any function at a point. To give an example, let’s plot the function
英語のヒント
これはどんな次元の入力でもうまくいき、任意の関数に対して、ある点で最もよく近似する2次式を与える。例として、次の関数をプロットしよう。
(22.4.31)
One can compute that the gradient and Hessian are
英語のヒント
勾配とヘッセ行列は次のように計算できる。
(22.4.32)
And thus, with a little algebra, see that the approximating quadratic at is
英語のヒント
したがって、少し代数計算をすると、での近似2次式は次のようになることがわかる。
(22.4.33)
# Construct grid and compute function
x, y = torch.meshgrid(torch.linspace(-2, 2, 101),
torch.linspace(-2, 2, 101))
z = x*torch.exp(- x**2 - y**2)
# Compute approximating quadratic with gradient and Hessian at (1, 0)
w = torch.exp(torch.tensor([-1.]))*(-1 - (x + 1) + 2 * (x + 1)**2 + 2 * y**2)
# Plot function
ax = d2l.plt.figure().add_subplot(111, projection='3d')
ax.plot_wireframe(x.numpy(), y.numpy(), z.numpy(),
**{'rstride': 10, 'cstride': 10})
ax.plot_wireframe(x.numpy(), y.numpy(), w.numpy(),
**{'rstride': 10, 'cstride': 10}, color='purple')
d2l.plt.xlabel('x')
d2l.plt.ylabel('y')
d2l.set_figsize()
ax.set_xlim(-2, 2)
ax.set_ylim(-2, 2)
ax.set_zlim(-1, 1)
ax.dist = 12This forms the basis for Newton’s Algorithm discussed in Section 12.3, where we perform numerical optimization iteratively finding the best fitting quadratic, and then exactly minimizing that quadratic.
英語のヒント
これは、12.3節で論じるニュートン法の基礎となる。そこでは、最もよく当てはまる2次式を見つけ、それからその2次式を厳密に最小化することを繰り返して、数値的な最適化を行う。