プリンキピア

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

12.1.1. Goal of Optimization12.1.1 最適化の目標

Although optimization provides a way to minimize the loss function for deep learning, in essence, the goals of optimization and deep learning are fundamentally different. The former is primarily concerned with minimizing an objective whereas the latter is concerned with finding a suitable model, given a finite amount of data. In Section 3.6, we discussed the difference between these two goals in detail. For instance, training error and generalization error generally differ: since the objective function of the optimization algorithm is usually a loss function based on the training dataset, the goal of optimization is to reduce the training error. However, the goal of deep learning (or more broadly, statistical inference) is to reduce the generalization error. To accomplish the latter we need to pay attention to overfitting in addition to using the optimization algorithm to reduce the training error.
英語のヒント
最適化は深層学習のために損失関数を最小化する方法を与えるが、本質的には、最適化と深層学習の目標は根本的に違う。前者は主に目的を最小化することを扱い、後者は有限の量のデータが与えられたときに適切なモデルを見つけることを扱う。3.6節では、この二つの目標の違いを詳しく論じた。たとえば、訓練誤差と汎化誤差はふつう異なる。最適化アルゴリズムの目的関数はふつう訓練データセットにもとづく損失関数なので、最適化の目標は訓練誤差を減らすことである。しかし、深層学習(もっと広くは統計的推論)の目標は、汎化誤差を減らすことである。後者を達成するには、最適化アルゴリズムで訓練誤差を減らすことに加えて、過学習に注意を払う必要がある。
%matplotlib inline
import numpy as np
import torch
from mpl_toolkits import mplot3d
from d2l import torch as d2l
To illustrate the aforementioned different goals, let’s consider the empirical risk and the risk. As described in Section 4.7.3.1, the empirical risk is an average loss on the training dataset while the risk is the expected loss on the entire population of data. Below we define two functions: the risk function f and the empirical risk function g. Suppose that we have only a finite amount of training data. As a result, here g is less smooth than f.
英語のヒント
前に述べた異なる目標を示すため、経験リスクとリスクを考えよう。4.7.3.1節で説明したように、経験リスクは訓練データセットでの平均の損失であり、リスクはデータの母集団全体での期待損失である。以下では二つの関数を定義する。リスク関数fと経験リスク関数gである。訓練データが有限の量しかないとしよう。その結果、ここではgはfよりなめらかでない。
def f(x):
    return x * torch.cos(np.pi * x)

def g(x):
    return f(x) + 0.2 * torch.cos(5 * np.pi * x)
The graph below illustrates that the minimum of the empirical risk on a training dataset may be at a different location from the minimum of the risk (generalization error).
英語のヒント
下のグラフは、訓練データセットでの経験リスクの最小値が、リスク(汎化誤差)の最小値と違う位置にありうることを示している。
def annotate(text, xy, xytext):  #@save
    d2l.plt.gca().annotate(text, xy=xy, xytext=xytext,
                           arrowprops=dict(arrowstyle='->'))

x = torch.arange(0.5, 1.5, 0.01)
d2l.set_figsize((4.5, 2.5))
d2l.plot(x, [f(x), g(x)], 'x', 'risk')
annotate('min of\nempirical risk', (1.0, -1.2), (0.5, -1.1))
annotate('min of risk', (1.1, -1.05), (0.95, -0.5))