プリンキピア

第2章準備

2.4.1. Derivatives and Differentiation2.4.1 導関数と微分

Put simply, a derivative is the rate of change in a function with respect to changes in its arguments. Derivatives can tell us how rapidly a loss function would increase or decrease were we to increase or decrease each parameter by an infinitesimally small amount. Formally, for functions f:ℝ→ℝ, that map from scalars to scalars, the derivative of f at a point x is defined as
英語のヒント
簡単に言えば、導関数とは、引数の変化に対する関数の変化率である。導関数は、各パラメータを無限に小さな量だけ増やしたり減らしたりしたら、損失関数がどれほど速く増えたり減ったりするかを教えてくれる。形式的には、スカラーからスカラーへ写す関数f:ℝ→ℝについて、点xでのfの導関数は次のように定義される。
f′(x)=limh→0f(x+h)−f(x)h.(2.4.1)
This term on the right hand side is called a limit and it tells us what happens to the value of an expression as a specified variable approaches a particular value. This limit tells us what the ratio between a perturbation h and the change in the function value f(x+h)−f(x) converges to as we shrink its size to zero.
英語のヒント
右辺のこの項は極限と呼ばれ、指定した変数がある値に近づくとき、式の値に何が起きるかを教えてくれる。この極限は、摂動hと関数の値の変化f(x+h)−f(x)との比が、その大きさをゼロに縮めていくときに何に収束するかを教えてくれる。
When f′(x) exists, f is said to be differentiable at x; and when f′(x) exists for all x on a set, e.g., the interval [a,b], we say that f is differentiable on this set. Not all functions are differentiable, including many that we wish to optimize, such as accuracy and the area under the receiving operating characteristic (AUC). However, because computing the derivative of the loss is a crucial step in nearly all algorithms for training deep neural networks, we often optimize a differentiable surrogate instead.
英語のヒント
f′(x)が存在するとき、fはxで微分可能であるという。また、ある集合、たとえば区間[a,b]上のすべてのxについてf′(x)が存在するとき、fはこの集合上で微分可能であるという。すべての関数が微分可能なわけではない。最適化したい関数の多く、たとえば正解率や受信者動作特性曲線の下の面積(AUC)も微分可能ではない。しかし、損失の導関数を計算することは、深いニューラルネットワークを訓練するほぼすべてのアルゴリズムで決定的な段階なので、代わりに微分可能な代理を最適化することが多い。
We can interpret the derivative f′(x) as the instantaneous rate of change of f(x) with respect to x. Let’s develop some intuition with an example. Define u=f(x)=3x2−4x.
英語のヒント
導関数f′(x)は、xに対するf(x)の瞬間的な変化率と解釈できる。例で直観を養おう。u=f(x)=3x2−4xと定義する。
def f(x):
    return 3 * x ** 2 - 4 * x
Setting x=1, we see that f(x+h)−f(x)h approaches 2 as h approaches 0. While this experiment lacks the rigor of a mathematical proof, we can quickly see that indeed f′(1)=2.
英語のヒント
x=1とすると、hが0に近づくにつれてf(x+h)−f(x)hが2に近づくことがわかる。この実験には数学的な証明の厳密さはないが、確かにf′(1)=2であることがすぐにわかる。
for h in 10.0**np.arange(-1, -6, -1):
    print(f'h={h:.5f}, numerical limit={(f(1+h)-f(1))/h:.5f}')
h=0.10000, numerical limit=2.30000
h=0.01000, numerical limit=2.03000
h=0.00100, numerical limit=2.00300
h=0.00010, numerical limit=2.00030
h=0.00001, numerical limit=2.00003
There are several equivalent notational conventions for derivatives. Given y=f(x), the following expressions are equivalent:
英語のヒント
導関数には、同値な記法の約束がいくつかある。y=f(x)が与えられたとき、次の式はすべて同値である。
f′(x)=y′=dydx=dfdx=ddxf(x)=Df(x)=Dxf(x),(2.4.2)
where the symbols ddx and D are differentiation operators. Below, we present the derivatives of some common functions:
英語のヒント
ここで記号ddxとDは微分演算子である。下に、よく使う関数の導関数を示す。
ddxC=0for any constant Cddxxn=nxn−1for n≠0ddxex=exddxln⁡x=x−1.(2.4.3)
Functions composed from differentiable functions are often themselves differentiable. The following rules come in handy for working with compositions of any differentiable functions f and g, and constant C.
英語のヒント
微分可能な関数から合成された関数は、それ自体も微分可能であることが多い。任意の微分可能な関数fとg、定数Cの合成を扱うには、次の規則が役に立つ。
ddx[Cf(x)]=Cddxf(x)Constant multiple ruleddx[f(x)+g(x)]=ddxf(x)+ddxg(x)Sum ruleddx[f(x)g(x)]=f(x)ddxg(x)+g(x)ddxf(x)Product ruleddxf(x)g(x)=g(x)ddxf(x)−f(x)ddxg(x)g2(x)Quotient rule(2.4.4)
Using this, we can apply the rules to find the derivative of 3x2−4x via
英語のヒント
これを使って、規則を当てはめ、3x2−4xの導関数を次のように求められる。
ddx[3x2−4x]=3ddxx2−4ddxx=6x−4.(2.4.5)
Plugging in x=1 shows that, indeed, the derivative equals 2 at this location. Note that derivatives tell us the slope of a function at a particular location.
英語のヒント
x=1を代入すると、確かにこの位置で導関数が2に等しいことがわかる。導関数は、ある位置での関数の傾きを教えてくれることに注意してほしい。