第12章最適化アルゴリズム
12.7.3. The Algorithm12.7.3 アルゴリズム
Let’s formalize the discussion from above. We use the variable to accumulate past gradient variance as follows.
英語のヒント
上の議論を形式化しよう。変数を使って、過去の勾配の分散を次のようにためていく。
(12.7.5)
Here the operation are applied coordinate wise. That is, has entries . Likewise has entries and has entries . As before is the learning rate and is an additive constant that ensures that we do not divide by . Last, we initialize .
英語のヒント
ここで演算は座標ごとに当てはめられる。つまり、の成分はである。同じように、の成分はであり、の成分はである。前と同じように、は学習率であり、はで割らないようにするための加法的な定数である。最後に、と初期化する。
Just like in the case of momentum we need to keep track of an auxiliary variable, in this case to allow for an individual learning rate per coordinate. This does not increase the cost of Adagrad significantly relative to SGD, simply since the main cost is typically to compute and its derivative.
英語のヒント
モメンタムの場合と同じように、補助変数を追跡する必要がある。この場合は、座標ごとに個別の学習率を使えるようにするためである。主なコストはふつうとその導関数を計算することなので、これでSGDと比べてAdagradのコストが大きく増えることはない。
Note that accumulating squared gradients in means that grows essentially at linear rate (somewhat slower than linearly in practice, since the gradients initially diminish). This leads to an learning rate, albeit adjusted on a per coordinate basis. For convex problems this is perfectly adequate. In deep learning, though, we might want to decrease the learning rate rather more slowly. This led to a number of Adagrad variants that we will discuss in the subsequent chapters. For now let’s see how it behaves in a quadratic convex problem. We use the same problem as before:
英語のヒント
勾配の2乗をにためることは、が本質的に線形の速さで増えることを意味する点に注意してほしい(勾配は最初のうち小さくなっていくので、実際には線形より少し遅い)。これは、座標ごとに調整されるとはいえ、の学習率につながる。凸の問題では、これでまったく十分である。しかし深層学習では、学習率をもっとゆっくり下げたいかもしれない。このことから、後の章で論じるAdagradの変種がいくつも生まれた。いまは、2次の凸の問題でそれがどうふるまうかを見よう。前と同じ問題を使う。
(12.7.6)
We are going to implement Adagrad using the same learning rate previously, i.e., . As we can see, the iterative trajectory of the independent variable is smoother. However, due to the cumulative effect of , the learning rate continuously decays, so the independent variable does not move as much during later stages of iteration.
英語のヒント
前と同じ学習率、つまりを使ってAdagradを実装する。見てのとおり、独立変数の反復の軌跡はもっとなめらかである。しかし、の累積の効果のため、学習率は減衰し続けるので、反復の後の段階では独立変数はあまり動かない。
%matplotlib inline
import math
import torch
from d2l import torch as d2l
def adagrad_2d(x1, x2, s1, s2):
eps = 1e-6
g1, g2 = 0.2 * x1, 4 * x2
s1 += g1 ** 2
s2 += g2 ** 2
x1 -= eta / math.sqrt(s1 + eps) * g1
x2 -= eta / math.sqrt(s2 + eps) * g2
return x1, x2, s1, s2
def f_2d(x1, x2):
return 0.1 * x1 ** 2 + 2 * x2 ** 2
eta = 0.4
d2l.show_trace_2d(f_2d, d2l.train_2d(adagrad_2d))epoch 20, x1: -2.382563, x2: -0.158591As we increase the learning rate to we see much better behavior. This already indicates that the decrease in learning rate might be rather aggressive, even in the noise-free case and we need to ensure that parameters converge appropriately.
英語のヒント
学習率をに上げると、ずっとよいふるまいが見られる。これはすでに、ノイズのない場合でさえ学習率の下がり方がかなり急であるかもしれず、パラメータが適切に収束するようにする必要があることを示している。
eta = 2
d2l.show_trace_2d(f_2d, d2l.train_2d(adagrad_2d))epoch 20, x1: -0.002295, x2: -0.000000