第22章付録:深層学習のための数学
22.4.1. Higher-Dimensional Differentiation22.4.1 高次元での微分
What Section 22.3 tells us is that if we change a single one of these billions of weights leaving every other one fixed, we know what will happen! This is nothing more than a function of a single variable, so we can write
英語のヒント
22.3節が教えてくれるのは、この何十億もの重みのうちの一つだけを変え、ほかをすべて固定しておけば、何が起きるかがわかるということである。これは1変数の関数にほかならないので、次のように書ける。
(22.4.1)
We will call the derivative in one variable while fixing the other variables the partial derivative, and we will use the notation for the derivative in (22.4.1).
英語のヒント
ほかの変数を固定したまま一つの変数について微分したものを偏導関数と呼び、式(22.4.1)の導関数には記法を使う。
Now, let’s take this and change a little bit to :
英語のヒント
では、これをとってを少しだけ変えてにしよう。
(22.4.2)
We have again used the idea that is a higher order term that we can discard in the same way we could discard in the previous section, along with what we saw in (22.4.1). By continuing in this manner, we may write that
英語のヒント
ここでも、は高次の項であり、前の節でを捨てられたのと同じように捨てられるという考えを、式(22.4.1)で見たことと合わせて使った。このやり方を続けると、次のように書ける。
(22.4.3)
This may look like a mess, but we can make this more familiar by noting that the sum on the right looks exactly like a dot product, so if we let
英語のヒント
これはごちゃごちゃして見えるかもしれないが、右辺の和がちょうど内積のように見えることに気づけば、もっとなじみのあるものにできる。そこで次のようにおくと、
(22.4.4)
then
英語のヒント
次のようになる。
(22.4.5)
We will call the vector the gradient of .
英語のヒント
ベクトルをの勾配と呼ぶ。
Equation (22.4.5) is worth pondering for a moment. It has exactly the format that we encountered in one dimension, just we have converted everything to vectors and dot products. It allows us to tell approximately how the function will change given any perturbation to the input. As we will see in the next section, this will provide us with an important tool in understanding geometrically how we can learn using information contained in the gradient.
英語のヒント
式(22.4.5)はしばらく考えてみる価値がある。これは1次元で出会ったのとまったく同じ形をしており、ただすべてをベクトルと内積に変換しただけである。これを使うと、入力に何か摂動が与えられたときに関数がおよそどう変わるかがわかる。次の節で見るように、これは、勾配に含まれる情報を使ってどう学習できるかを幾何学的に理解するうえで、重要な道具になる。
But first, let’s see this approximation at work with an example. Suppose that we are working with the function
英語のヒント
しかしまず、この近似が働くところを例で見よう。次の関数を扱っているとする。
(22.4.6)
If we look at a point like , we see that
英語のヒント
のような点を見ると、次がわかる。
(22.4.7)
Thus, if we want to approximate at , we see that we should have the specific instance of (22.4.5):
英語のヒント
したがって、でを近似したいなら、式(22.4.5)の次の具体例を使えばよいことがわかる。
(22.4.8)
We can test this in code to see how good the approximation is.
英語のヒント
この近似がどれくらいよいかを、コードで確かめられる。
%matplotlib inline
import numpy as np
import torch
from IPython import display
from mpl_toolkits import mplot3d
from d2l import torch as d2l
def f(x, y):
return torch.log(torch.exp(x) + torch.exp(y))
def grad_f(x, y):
return torch.tensor([torch.exp(x) / (torch.exp(x) + torch.exp(y)),
torch.exp(y) / (torch.exp(x) + torch.exp(y))])
epsilon = torch.tensor([0.01, -0.03])
grad_approx = f(torch.tensor([0.]), torch.log(
torch.tensor([2.]))) + epsilon.dot(
grad_f(torch.tensor([0.]), torch.log(torch.tensor(2.))))
true_value = f(torch.tensor([0.]) + epsilon[0], torch.log(
torch.tensor([2.])) + epsilon[1])
f'approximation: {grad_approx}, true Value: {true_value}''approximation: tensor([1.0819]), true Value: tensor([1.0821])'