プリンキピア

第22章付録:深層学習のための数学

22.5.1. Geometric Interpretation22.5.1 幾何学的な解釈

Suppose that we have a function f(x). For simplicity, let’s assume that f(x) is non-negative (never takes a value less than zero). What we want to try and understand is: what is the area contained between f(x) and the x-axis?
英語のヒント
関数f(x)があるとする。簡単にするため、f(x)は非負である(0より小さい値を決してとらない)と仮定しよう。理解しようとしたいのは、f(x)とx軸の間に含まれる面積はいくらか、ということである。
%matplotlib inline
import torch
from IPython import display
from mpl_toolkits import mplot3d
from d2l import torch as d2l

x = torch.arange(-2, 2, 0.01)
f = torch.exp(-x**2)

d2l.set_figsize()
d2l.plt.plot(x, f, color='black')
d2l.plt.fill_between(x.tolist(), f.tolist())
d2l.plt.show()
In most cases, this area will be infinite or undefined (consider the area under f(x)=x2), so people will often talk about the area between a pair of ends, say a and b.
英語のヒント
たいていの場合、この面積は無限大になるか定義されないので(f(x)=x2の下の面積を考えよう)、人々はよく、ある一対の端、たとえばaとbの間の面積について話す。
x = torch.arange(-2, 2, 0.01)
f = torch.exp(-x**2)

d2l.set_figsize()
d2l.plt.plot(x, f, color='black')
d2l.plt.fill_between(x.tolist()[50:250], f.tolist()[50:250])
d2l.plt.show()
We will denote this area by the integral symbol below:
英語のヒント
この面積を、次の積分記号で表す。
Area(𝒜)=∫abf(x)dx.(22.5.1)
The inner variable is a dummy variable, much like the index of a sum in a ∑, and so this can be equivalently written with any inner value we like:
英語のヒント
内側の変数は、∑における和の添字とよく似たダミー変数なので、内側の値として好きなものを使って同じことを書ける。
∫abf(x)dx=∫abf(z)dz.(22.5.2)
There is a traditional way to try and understand how we might try to approximate such integrals: we can imagine taking the region in-between a and b and chopping it into N vertical slices. If N is large, we can approximate the area of each slice by a rectangle, and then add up the areas to get the total area under the curve. Let’s take a look at an example doing this in code. We will see how to get the true value in a later section.
英語のヒント
このような積分をどう近似するかを理解しようとする伝統的なやり方がある。aとbの間の領域をとり、それをN本の縦の細切れに切り分けることを想像すればよい。Nが大きければ、各細切れの面積を長方形で近似し、それらの面積を足し合わせて曲線の下の全面積を得られる。これをコードで行う例を見よう。本当の値の求め方は後の節で見る。
epsilon = 0.05
a = 0
b = 2

x = torch.arange(a, b, epsilon)
f = x / (1 + x**2)

approx = torch.sum(epsilon*f)
true = torch.log(torch.tensor([5.])) / 2

d2l.set_figsize()
d2l.plt.bar(x, f, width=epsilon, align='edge')
d2l.plt.plot(x, f, color='black')
d2l.plt.ylim([0, 1])
d2l.plt.show()

f'approximation: {approx}, truth: {true}'
'approximation: 0.7944855690002441, truth: tensor([0.8047])'
The issue is that while it can be done numerically, we can do this approach analytically for only the simplest functions like
英語のヒント
問題は、数値的にはできても、このやり方を解析的に行えるのは、次のような最も単純な関数についてだけだということである。
∫abxdx.(22.5.3)
Anything somewhat more complex like our example from the code above
英語のヒント
上のコードの例のような、いくらかでも複雑なものは、
∫abx1+x2dx.(22.5.4)
is beyond what we can solve with such a direct method.
英語のヒント
このような直接的な方法で解けるものを超えている。
We will instead take a different approach. We will work intuitively with the notion of the area, and learn the main computational tool used to find integrals: the fundamental theorem of calculus. This will be the basis for our study of integration.
英語のヒント
そこで、別のやり方をとる。面積という概念を直観的に扱い、積分を求めるのに使われる主な計算の道具、つまり微積分学の基本定理を学ぶ。これが積分の研究の基礎になる。