プリンキピア

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

22.1.7. Invertibility22.1.7 可逆性

We have seen above that multiplication by a matrix with linearly dependent columns cannot be undone, i.e., there is no inverse operation that can always recover the input. However, multiplication by a full-rank matrix (i.e., some 𝐀 that is n×n matrix with rank n), we should always be able to undo it. Consider the matrix
英語のヒント
線形従属な列をもつ行列による掛け算は元に戻せないこと、つまり入力をいつでも復元できる逆の演算は存在しないことを上で見た。しかし、フルランクの行列(つまり、ランクがnであるn×n行列𝐀)による掛け算なら、いつでも元に戻せるはずである。次の行列を考えよう。
𝐈=[10⋯001⋯0⋮⋮⋱⋮00⋯1].(22.1.21)
which is the matrix with ones along the diagonal, and zeros elsewhere. We call this the identity matrix. It is the matrix which leaves our data unchanged when applied. To find a matrix which undoes what our matrix 𝐀 has done, we want to find a matrix 𝐀−1 such that
英語のヒント
これは、対角線に沿って1が並び、ほかは0である行列である。これを単位行列と呼ぶ。これは、適用してもデータを変えない行列である。行列𝐀がしたことを元に戻す行列を見つけるには、次を満たす行列𝐀−1を見つけたい。
𝐀−1𝐀=𝐀𝐀−1=𝐈.(22.1.22)
If we look at this as a system, we have n×n unknowns (the entries of 𝐀−1) and n×n equations (the equality that needs to hold between every entry of the product 𝐀−1𝐀 and every entry of 𝐈) so we should generically expect a solution to exist. Indeed, in the next section we will see a quantity called the determinant, which has the property that as long as the determinant is not zero, we can find a solution. We call such a matrix 𝐀−1 the inverse matrix. As an example, if 𝐀 is the general 2×2 matrix
英語のヒント
これを連立方程式として見ると、n×n個の未知数(𝐀−1の成分)と、n×n個の方程式(積𝐀−1𝐀のすべての成分と𝐈のすべての成分の間で成り立つ必要がある等式)があるので、一般には解が存在すると期待できる。実際、次の節では行列式と呼ばれる量を見る。行列式には、それが0でないかぎり解が見つかるという性質がある。このような行列𝐀−1を逆行列と呼ぶ。例として、𝐀が一般の2×2行列であれば、
𝐀=[abcd],(22.1.23)
then we can see that the inverse is
英語のヒント
逆行列は次のようになることがわかる。
1ad−bc[d−b−ca].(22.1.24)
We can test to see this by seeing that multiplying by the inverse given by the formula above works in practice.
英語のヒント
上の式で与えられる逆行列を掛けると、実際にうまくいくことを確かめて検証できる。
M = torch.tensor([[1, 2], [1, 4]], dtype=torch.float32)
M_inv = torch.tensor([[2, -1], [-0.5, 0.5]])
M_inv @ M
tensor([[1., 0.],
        [0., 1.]])

22.1.7.1. Numerical Issues22.1.7.1 数値的な問題

While the inverse of a matrix is useful in theory, we must say that most of the time we do not wish to use the matrix inverse to solve a problem in practice. In general, there are far more numerically stable algorithms for solving linear equations like
英語のヒント
逆行列は理論では役に立つが、実際に問題を解くときには、ほとんどの場合逆行列を使いたくないと言わなければならない。一般に、次のような線形方程式を解くには、
𝐀𝐱=𝐛,(22.1.25)
than computing the inverse and multiplying to get
英語のヒント
逆行列を計算し、掛け算をして次を得るよりも、はるかに数値的に安定なアルゴリズムがある。
𝐱=𝐀−1𝐛.(22.1.26)
Just as division by a small number can lead to numerical instability, so can inversion of a matrix which is close to having low rank.
英語のヒント
小さな数で割ると数値的な不安定さにつながりうるのと同じように、ランクが低くなりかけている行列の逆行列を求めることも不安定さにつながりうる。
Moreover, it is common that the matrix 𝐀 is sparse, which is to say that it contains only a small number of non-zero values. If we were to explore examples, we would see that this does not mean the inverse is sparse. Even if 𝐀 was a 1 million by 1 million matrix with only 5 million non-zero entries (and thus we need only store those 5 million), the inverse will typically have almost every entry non-negative, requiring us to store all 1M2 entries—that is 1 trillion entries!
英語のヒント
さらに、行列𝐀が疎であること、つまり0でない値を少ししか含まないことはよくある。例を調べてみれば、これは逆行列が疎であることを意味しないことがわかるだろう。𝐀が、0でない成分が5百万個しかない1百万×1百万の行列だったとしても(したがってその5百万個だけを保存すればよい)、逆行列はふつうほとんどすべての成分が負でなく、1M2個の成分すべてを保存する必要がある。それは1兆個の成分である。
While we do not have time to dive all the way into the thorny numerical issues frequently encountered when working with linear algebra, we want to provide you with some intuition about when to proceed with caution, and generally avoiding inversion in practice is a good rule of thumb.
英語のヒント
線形代数を扱うときによく出会う、やっかいな数値的な問題の奥深くまで入り込む時間はないが、いつ注意して進むべきかについての直観を与えたい。一般に、実際には逆行列を求めるのを避けるのがよい経験則である。