第12章最適化アルゴリズム
12.3.3. Adaptive Methods12.3.3 適応的な手法
As we could see in Section 12.3.1.1, getting the learning rate “just right” is tricky. If we pick it too small, we make little progress. If we pick it too large, the solution oscillates and in the worst case it might even diverge. What if we could determine automatically or get rid of having to select a learning rate at all? Second-order methods that look not only at the value and gradient of the objective function but also at its curvature can help in this case. While these methods cannot be applied to deep learning directly due to the computational cost, they provide useful intuition into how to design advanced optimization algorithms that mimic many of the desirable properties of the algorithms outlined below.
英語のヒント
12.3.1.1節で見たように、学習率を「ちょうどよく」するのは難しい。小さすぎるとほとんど前進しない。大きすぎると解が振動し、最悪の場合には発散さえするかもしれない。を自動的に決められたら、あるいは学習率を選ばなければならないこと自体をなくせたらどうだろうか。目的関数の値と勾配だけでなく、その曲率も見る2次の手法が、この場合に役立つ。こうした手法は、計算のコストのために深層学習に直接は当てはめられないが、以下で概説するアルゴリズムの望ましい性質の多くをまねる高度な最適化アルゴリズムをどう設計するかについて、役に立つ直観を与えてくれる。
12.3.3.1. Newton’s Method12.3.3.1 ニュートン法
Reviewing the Taylor expansion of some function there is no need to stop after the first term. In fact, we can write it as
英語のヒント
ある関数のテイラー展開を見直すと、最初の項の後で止める必要はない。実際、次のように書ける。
(12.3.8)
To avoid cumbersome notation we define to be the Hessian of , which is a matrix. For small and simple problems is easy to compute. For deep neural networks, on the other hand, may be prohibitively large, due to the cost of storing entries. Furthermore it may be too expensive to compute via backpropagation. For now let’s ignore such considerations and look at what algorithm we would get.
英語のヒント
面倒な記法を避けるため、をのヘッセ行列と定義する。これはの行列である。小さなと単純な問題では、は簡単に計算できる。一方、深いニューラルネットワークでは、個の成分を格納するコストのため、は手に負えないほど大きくなるかもしれない。さらに、逆伝播で計算するには高くつきすぎるかもしれない。いまはそうした事情を無視し、どんなアルゴリズムが得られるかを見よう。
After all, the minimum of satisfies . Following calculus rules in Section 2.4.3, by taking derivatives of (12.3.8) with regard to and ignoring higher-order terms we arrive at
英語のヒント
(12.3.9)
That is, we need to invert the Hessian as part of the optimization problem.
英語のヒント
つまり、最適化問題の一部として、ヘッセ行列の逆行列を求める必要がある。
As a simple example, for we have and . Hence for any we obtain . In other words, a single step is sufficient to converge perfectly without the need for any adjustment! Alas, we got a bit lucky here: the Taylor expansion was exact since .
英語のヒント
単純な例として、ではかつである。したがって、どのについてもが得られる。言い換えると、まったく調整しなくても、1ステップで完全に収束するのに十分である。残念ながら、ここでは少し運がよかった。なので、テイラー展開が厳密だったのである。
Let’s see what happens in other problems. Given a convex hyperbolic cosine function for some constant , we can see that the global minimum at is reached after a few iterations.
英語のヒント
ほかの問題で何が起こるかを見よう。ある定数についての凸の双曲線余弦関数が与えられたとき、数回の反復の後にでの大域的な最小値に達するのがわかる。
c = torch.tensor(0.5)
def f(x): # Objective function
return torch.cosh(c * x)
def f_grad(x): # Gradient of the objective function
return c * torch.sinh(c * x)
def f_hess(x): # Hessian of the objective function
return c**2 * torch.cosh(c * x)
def newton(eta=1):
x = 10.0
results = [x]
for i in range(10):
x -= eta * f_grad(x) / f_hess(x)
results.append(float(x))
print('epoch 10, x:', x)
return results
show_trace(newton(), f)epoch 10, x: tensor(0.)Now let’s consider a nonconvex function, such as for some constant . After all, note that in Newton’s method we end up dividing by the Hessian. This means that if the second derivative is negative we may walk into the direction of increasing the value of . That is a fatal flaw of the algorithm. Let’s see what happens in practice.
英語のヒント
では、ある定数についてのような非凸の関数を考えよう。結局のところ、ニュートン法ではヘッセ行列で割ることになる点に注意してほしい。これは、2階導関数が負なら、の値が増える向きへ進んでしまうかもしれないことを意味する。それはこのアルゴリズムの致命的な欠陥である。実際に何が起こるかを見よう。
c = torch.tensor(0.15 * np.pi)
def f(x): # Objective function
return x * torch.cos(c * x)
def f_grad(x): # Gradient of the objective function
return torch.cos(c * x) - c * x * torch.sin(c * x)
def f_hess(x): # Hessian of the objective function
return - 2 * c * torch.sin(c * x) - x * c**2 * torch.cos(c * x)
show_trace(newton(), f)epoch 10, x: tensor(26.8341)This went spectacularly wrong. How can we fix it? One way would be to “fix” the Hessian by taking its absolute value instead. Another strategy is to bring back the learning rate. This seems to defeat the purpose, but not quite. Having second-order information allows us to be cautious whenever the curvature is large and to take longer steps whenever the objective function is flatter. Let’s see how this works with a slightly smaller learning rate, say . As we can see, we have quite an efficient algorithm.
英語のヒント
これは見事に失敗した。どう直せばよいだろうか。一つのやり方は、代わりにヘッセ行列の絶対値をとって「直す」ことだろう。別の戦略は、学習率を戻すことである。これは目的に反するように見えるが、そうでもない。2次の情報があれば、曲率が大きいときには慎重になり、目的関数が平らなときには長いステップをとれる。学習率を少し小さく、たとえばにして、これがどう働くかを見よう。見てのとおり、かなり効率のよいアルゴリズムになっている。
show_trace(newton(0.5), f)epoch 10, x: tensor(7.2699)12.3.3.2. Convergence Analysis12.3.3.2 収束の解析
We only analyze the convergence rate of Newton’s method for some convex and three times differentiable objective function , where the second derivative is nonzero, i.e., . The multivariate proof is a straightforward extension of the one-dimensional argument below and omitted since it does not help us much in terms of intuition.
英語のヒント
ここでは、2階導関数がゼロでない、つまりである、凸で3回微分可能な目的関数について、ニュートン法の収束の速さだけを解析する。多変数の証明は、下の1次元の議論を素直に拡張したものであり、直観の面ではあまり助けにならないので省く。
Denote by the value of at the iteration and let be the distance from optimality at the iteration. By Taylor expansion we have that the condition can be written as
英語のヒント
の反復でのの値をで表し、の反復での最適からの距離をとする。テイラー展開により、条件は次のように書ける。
(12.3.10)
which holds for some . Dividing the above expansion by yields
英語のヒント
これは、あるについて成り立つ。上の展開をで割ると、次が得られる。
(12.3.11)
Recall that we have the update . Plugging in this update equation and taking the absolute value of both sides, we have
英語のヒント
更新がであることを思い出そう。この更新式を代入し、両辺の絶対値をとると、次が得られる。
(12.3.12)
Consequently, whenever we are in a region of bounded , we have a quadratically decreasing error
英語のヒント
その結果、と有界な領域にいるときはいつでも、誤差は次のように2次的に減少する。
(12.3.13)
As an aside, optimization researchers call this linear convergence, whereas a condition such as would be called a constant rate of convergence. Note that this analysis comes with a number of caveats. First, we do not really have much of a guarantee when we will reach the region of rapid convergence. Instead, we only know that once we reach it, convergence will be very quick. Second, this analysis requires that is well-behaved up to higher-order derivatives. It comes down to ensuring that does not have any “surprising” properties in terms of how it might change its values.
英語のヒント
余談だが、最適化の研究者はこれを線形収束と呼び、のような条件は一定の速さの収束と呼ばれる。この解析にはいくつかの注意点があることに注意してほしい。第一に、速い収束の領域にいつ到達するかについては、あまり保証がない。代わりにわかっているのは、いったんそこに到達すれば収束がとても速いということだけである。第二に、この解析では、が高階の導関数まで行儀がよいことが要る。つまり、値がどう変わりうるかについて、が「意外な」性質をまったくもたないようにすることに帰着する。
12.3.3.3. Preconditioning12.3.3.3 前条件づけ
Quite unsurprisingly computing and storing the full Hessian is very expensive. It is thus desirable to find alternatives. One way to improve matters is preconditioning. It avoids computing the Hessian in its entirety but only computes the diagonal entries. This leads to update algorithms of the form
英語のヒント
当然ながら、ヘッセ行列全体を計算して格納するのはとても高くつく。したがって、代わりのものを見つけるのが望ましい。事態を改善する一つの方法は前条件づけである。前条件づけでは、ヘッセ行列全体を計算するのを避け、対角成分だけを計算する。これは、次の形の更新アルゴリズムにつながる。
(12.3.14)
While this is not quite as good as the full Newton’s method, it is still much better than not using it. To see why this might be a good idea consider a situation where one variable denotes height in millimeters and the other one denotes height in kilometers. Assuming that for both the natural scale is in meters, we have a terrible mismatch in parametrizations. Fortunately, using preconditioning removes this. Effectively preconditioning with gradient descent amounts to selecting a different learning rate for each variable (coordinate of vector ). As we will see later, preconditioning drives some of the innovation in stochastic gradient descent optimization algorithms.
英語のヒント
これは完全なニュートン法ほどよくはないが、使わないよりはずっとよい。これがなぜよい考えでありうるかを見るため、一方の変数が高さをミリメートルで表し、もう一方の変数が高さをキロメートルで表す状況を考えよう。どちらも自然な尺度はメートルだとすると、パラメータ化にひどい食い違いがある。幸い、前条件づけを使えばこれが取り除かれる。実質的に、勾配降下法で前条件づけをすることは、変数(ベクトルの座標)ごとに違う学習率を選ぶことにあたる。後で見るように、前条件づけは、確率的勾配降下法の最適化アルゴリズムでの革新の一部を推し進めている。
12.3.3.4. Gradient Descent with Line Search12.3.3.4 直線探索つきの勾配降下法
One of the key problems in gradient descent is that we might overshoot the goal or make insufficient progress. A simple fix for the problem is to use line search in conjunction with gradient descent. That is, we use the direction given by and then perform binary search as to which learning rate minimizes .
英語のヒント
勾配降下法の主な問題の一つは、目標を行き過ぎたり、十分に前進できなかったりするかもしれないことである。この問題の簡単な直し方は、勾配降下法と一緒に直線探索を使うことである。つまり、で与えられる向きを使い、どの学習率がを最小化するかについて二分探索を行う。
This algorithm converges rapidly (for an analysis and proof see e.g., Boyd and Vandenberghe (2004)). However, for the purpose of deep learning this is not quite so feasible, since each step of the line search would require us to evaluate the objective function on the entire dataset. This is way too costly to accomplish.
英語のヒント
このアルゴリズムは速く収束する(解析と証明は、たとえばBoyd and Vandenberghe (2004)を参照)。しかし、深層学習の目的には、これはあまり実行可能ではない。直線探索の各ステップで、データセット全体で目的関数を評価する必要があるからである。これは、やり遂げるにはあまりに高くつく。