プリンキピア

第12章最適化アルゴリズム

12.6.3. Theoretical Analysis12.6.3 理論的な解析

So far the 2D example of f(x)=0.1x12+2x22 seemed rather contrived. We will now see that this is actually quite representative of the types of problem one might encounter, at least in the case of minimizing convex quadratic objective functions.
英語のヒント
ここまで、f(x)=0.1x12+2x22という2次元の例はかなり作為的に見えた。ここでは、少なくとも凸の2次の目的関数を最小化する場合には、これが実は出会いうる種類の問題をかなりよく代表していることを見る。

12.6.3.1. Quadratic Convex Functions12.6.3.1 2次の凸関数

Consider the function
英語のヒント
次の関数を考えよう。
h(𝐱)=12𝐱⊤𝐐𝐱+𝐱⊤𝐜+b.(12.6.6)
This is a general quadratic function. For positive definite matrices 𝐐≻0, i.e., for matrices with positive eigenvalues this has a minimizer at 𝐱∗=−𝐐−1𝐜 with minimum value b−12𝐜⊤𝐐−1𝐜. Hence we can rewrite h as
英語のヒント
これは一般的な2次関数である。正定値行列𝐐≻0、つまり固有値が正の行列については、これは𝐱∗=−𝐐−1𝐜に最小化点をもち、最小値はb−12𝐜⊤𝐐−1𝐜である。したがって、hは次のように書き直せる。
h(𝐱)=12(𝐱−𝐐−1𝐜)⊤𝐐(𝐱−𝐐−1𝐜)+b−12𝐜⊤𝐐−1𝐜.(12.6.7)
The gradient is given by ∂𝐱h(𝐱)=𝐐(𝐱−𝐐−1𝐜). That is, it is given by the distance between 𝐱 and the minimizer, multiplied by 𝐐. Consequently also the velocity is a linear combination of terms 𝐐(𝐱t−𝐐−1𝐜).
英語のヒント
勾配は∂𝐱h(𝐱)=𝐐(𝐱−𝐐−1𝐜)で与えられる。つまり、それは𝐱と最小化点との距離に𝐐を掛けたもので与えられる。その結果、速度も項𝐐(𝐱t−𝐐−1𝐜)の線形結合になる。
Since 𝐐 is positive definite it can be decomposed into its eigensystem via 𝐐=𝐎⊤𝚲𝐎 for an orthogonal (rotation) matrix 𝐎 and a diagonal matrix 𝚲 of positive eigenvalues. This allows us to perform a change of variables from 𝐱 to 𝐳=def𝐎(𝐱−𝐐−1𝐜) to obtain a much simplified expression:
英語のヒント
𝐐は正定値なので、直交(回転)行列𝐎と正の固有値の対角行列𝚲によって、𝐐=𝐎⊤𝚲𝐎と固有系に分解できる。これにより、変数を𝐱から𝐳=def𝐎(𝐱−𝐐−1𝐜)へ変換して、ずっと簡単な式が得られる。
h(𝐳)=12𝐳⊤𝚲𝐳+b′.(12.6.8)
Here b′=b−12𝐜⊤𝐐−1𝐜. Since 𝐎 is only an orthogonal matrix this does not perturb the gradients in a meaningful way. Expressed in terms of 𝐳 gradient descent becomes
英語のヒント
ここでb′=b−12𝐜⊤𝐐−1𝐜である。𝐎は直交行列にすぎないので、これは勾配を意味のある形でかき乱さない。𝐳で表すと、勾配降下法は次のようになる。
𝐳t=𝐳t−1−𝚲𝐳t−1=(𝐈−𝚲)𝐳t−1.(12.6.9)
The important fact in this expression is that gradient descent does not mix between different eigenspaces. That is, when expressed in terms of the eigensystem of 𝐐 the optimization problem proceeds in a coordinate-wise manner. This also holds for
英語のヒント
この式の重要な事実は、勾配降下法が異なる固有空間のあいだで混ざり合わないことである。つまり、𝐐の固有系で表すと、最適化問題は座標ごとに進む。これは次についても成り立つ。
𝐯t=β𝐯t−1+𝚲𝐳t−1𝐳t=𝐳t−1−η(β𝐯t−1+𝚲𝐳t−1)=(𝐈−η𝚲)𝐳t−1−ηβ𝐯t−1.(12.6.10)
In doing this we just proved the following theorem: gradient descent with and without momentum for a convex quadratic function decomposes into coordinate-wise optimization in the direction of the eigenvectors of the quadratic matrix.
英語のヒント
こうして、次の定理を証明したことになる。凸の2次関数に対するモメンタムありとなしの勾配降下法は、2次の行列の固有ベクトルの向きでの座標ごとの最適化に分解される。

12.6.3.2. Scalar Functions12.6.3.2 スカラー関数

Given the above result let’s see what happens when we minimize the function f(x)=λ2x2. For gradient descent we have
英語のヒント
上の結果を踏まえて、関数f(x)=λ2x2を最小化すると何が起こるかを見よう。勾配降下法では次が成り立つ。
xt+1=xt−ηλxt=(1−ηλ)xt.(12.6.11)
Whenever |1−ηλ|<1 this optimization converges at an exponential rate since after t steps we have xt=(1−ηλ)tx0. This shows how the rate of convergence improves initially as we increase the learning rate η until ηλ=1. Beyond that things diverge and for ηλ>2 the optimization problem diverges.
英語のヒント
|1−ηλ|<1であるときはいつでも、tステップの後にxt=(1−ηλ)tx0となるので、この最適化は指数的な速さで収束する。これは、学習率ηをηλ=1まで上げていくと、最初は収束の速さがどう改善するかを示している。それを超えると発散に向かい、ηλ>2では最適化問題は発散する。
lambdas = [0.1, 1, 10, 19]
eta = 0.1
d2l.set_figsize((6, 4))
for lam in lambdas:
    t = torch.arange(20).detach().numpy()
    d2l.plt.plot(t, (1 - eta * lam) ** t, label=f'lambda = {lam:.2f}')
d2l.plt.xlabel('time')
d2l.plt.legend();
To analyze convergence in the case of momentum we begin by rewriting the update equations in terms of two scalars: one for x and one for velocity v. This yields:
英語のヒント
モメンタムの場合の収束を解析するため、まず更新式を二つのスカラーで書き直す。一つはxについて、もう一つは速度vについてである。すると次が得られる。
[vt+1xt+1]=[βλ−ηβ(1−ηλ)][vtxt]=𝐑(β,η,λ)[vtxt].(12.6.12)
We used 𝐑 to denote the 2×2 governing convergence behavior. After t steps the initial choice [v0,x0] becomes 𝐑(β,η,λ)t[v0,x0]. Hence, it is up to the eigenvalues of 𝐑 to determine the speed of convergence. See the Distill post of Goh (2017) for a great animation and Flammarion and Bach (2015) for a detailed analysis. One can show that 0<ηλ<2+2β velocity converges. This is a larger range of feasible parameters when compared to 0<ηλ<2 for gradient descent. It also suggests that in general large values of β are desirable. Further details require a fair amount of technical detail and we suggest that the interested reader consult the original publications.
英語のヒント
収束のふるまいを支配する2×2の行列を𝐑で表した。tステップの後、最初の選択[v0,x0]は𝐑(β,η,λ)t[v0,x0]になる。したがって、収束の速さを決めるのは𝐑の固有値次第である。すばらしいアニメーションについてはGoh (2017)のDistillの記事を、詳しい解析についてはFlammarion and Bach (2015)を参照。0<ηλ<2+2βなら速度が収束することが示せる。これは、勾配降下法での0<ηλ<2と比べて、実行可能なパラメータの範囲が広い。それはまた、一般にβの値が大きいのが望ましいことも示唆している。これ以上の詳しいことにはかなりの技術的な詳細が要るので、興味のある読者には元の文献にあたることを勧める。