プリンキピア

第2章準備

2.3.8. Dot Products2.3.8 内積

So far, we have only performed elementwise operations, sums, and averages. And if this was all we could do, linear algebra would not deserve its own section. Fortunately, this is where things get more interesting. One of the most fundamental operations is the dot product. Given two vectors 𝐱,𝐲∈ℝd, their dot product 𝐱⊤𝐲 (also known as inner product, ⟨𝐱,𝐲⟩) is a sum over the products of the elements at the same position: 𝐱⊤𝐲=∑i=1dxiyi.
英語のヒント
ここまで行ってきたのは、要素ごとの演算、和、平均だけである。もしこれしかできないなら、線形代数に独立した節を割く値打ちはないだろう。幸い、ここから話がおもしろくなる。最も基本的な演算の一つが内積である。二つのベクトル𝐱,𝐲∈ℝdが与えられたとき、その内積𝐱⊤𝐲(ドット積、⟨𝐱,𝐲⟩とも呼ばれる)は、同じ位置にある要素の積の和𝐱⊤𝐲=∑i=1dxiyiである。
y = torch.ones(3, dtype = torch.float32)
x, y, torch.dot(x, y)
(tensor([0., 1., 2.]), tensor([1., 1., 1.]), tensor(3.))
Equivalently, we can calculate the dot product of two vectors by performing an elementwise multiplication followed by a sum:
英語のヒント
同じことだが、二つのベクトルの内積は、要素ごとの積をとってから和をとることでも計算できる。
torch.sum(x * y)
tensor(3.)
Dot products are useful in a wide range of contexts. For example, given some set of values, denoted by a vector 𝐱∈ℝn, and a set of weights, denoted by 𝐰∈ℝn, the weighted sum of the values in 𝐱 according to the weights 𝐰 could be expressed as the dot product 𝐱⊤𝐰. When the weights are nonnegative and sum to 1, i.e., (∑i=1nwi=1), the dot product expresses a weighted average. After normalizing two vectors to have unit length, the dot products express the cosine of the angle between them. Later in this section, we will formally introduce this notion of length.
英語のヒント
内積は、幅広い場面で役に立つ。たとえば、ベクトル𝐱∈ℝnで表される値の集合と、𝐰∈ℝnで表される重みの集合が与えられたとき、重み𝐰による𝐱の値の重み付き和は、内積𝐱⊤𝐰で表せる。重みが非負で和が1のとき、つまり(∑i=1nwi=1)のとき、内積は重み付き平均を表す。二つのベクトルを長さ1に正規化した後なら、内積はそのあいだの角の余弦を表す。この節の後のほうで、この長さの概念を正式に導入する。