矩陣的跡(matrix trace)的特性以及證明
前言
本篇整理自深藍學院三維點雲處理課程的Lecture 9 – Registration,並補上證明。
definition
tr ( A ) = ∑ i = 1 n a i i = a 11 + a 22 + . . . + a n n \text{tr}(A) = \sum\limits_{i=1}^n a_{ii} = a_{11}+a_{22}+...+a_{nn} tr(A)=i=1∑naii=a11+a22+...+ann
linear mapping
tr ( A + B ) = tr ( A ) + tr ( B ) \text{tr}(\bold{A}+\bold{B}) = \text{tr}(\bold{A})+\text{tr}(\bold{B}) tr(A+B)=tr(A)+tr(B)
tr ( c A ) = c tr ( A ) \text{tr}(c\bold{A}) = c\text{tr}(\bold{A}) tr(cA)=ctr(A)
tr ( A ) = tr ( A T ) \text{tr}(\bold{A}) = \text{tr}(\bold{A}^T) tr(A)=tr(AT)
trace of product
tr ( A B T ) = tr ( A T B ) = tr ( B A T ) = tr ( B T A ) = ∑ i , j A i j B i j , ∀ A , B ∈ R m × n \text{tr}(\bold{A}\bold{B}^T) = \text{tr}(\bold{A}^T\bold{B}) = \text{tr}(\bold{B}\bold{A}^T) = \text{tr}(\bold{B}^T\bold{A}) = \sum\limits_{i,j}A_{ij}B_{ij}, \forall A,B \in \R^{m \times n} tr(ABT)=tr(ATB)=tr(BAT)=tr(BTA)=i,j∑AijBij,∀A,B∈Rm×n
tr ( a b T ) = a T b 向量外積的跡等於向量的內積 ∀ a , b ∈ R n × 1 \begin{aligned}\text{tr}(\bold{a}\bold{b}^T) = \bold{a}^T\bold{b} && \text{向量外積的跡等於向量的內積}\end{aligned} \forall \bold{a},\bold{b} \in \R^{n \times 1} tr(abT)=aTb向量外積的跡等於向量的內積∀a,b∈Rn×1
性質一證明
參考proof of properties of trace of a matrix:
tr ( A B T ) = ∑ i = 1 m ∑ j = 1 n A i j B j i T 對角線上第i個元素為 ∑ j = 1 n A i j B j i T ,trace為m個對角線元素的和 = ∑ j = 1 n ∑ i = 1 m B j i T A i j 交換 ∑ 順序和乘法順序 = ∑ i = 1 n ∑ j = 1 m B i j T A j i i,j互換 = tr ( B T A ) \begin{aligned}\text{tr}(\bold{A}\bold{B}^T) &=\sum\limits_{i=1}^m\sum\limits_{j=1}^nA_{ij}B^T_{ji} && \text{對角線上第i個元素為}\sum\limits_{j=1}^nA_{ij}B^T_{ji}\text{,trace為m個對角線元素的和} \\&= \sum\limits_{j=1}^n\sum\limits_{i=1}^mB^T_{ji}A_{ij} && \text{交換}\sum\text{順序和乘法順序} \\&= \sum\limits_{i=1}^n\sum\limits_{j=1}^mB^T_{ij}A_{ji} && \text{i,j互換} \\&=\text{tr}(\bold{B}^T\bold{A})\end{aligned} tr(ABT)=i=1∑mj=1∑nAijBjiT=j=1∑ni=1∑mBjiTAij=i=1∑nj=1∑mBijTAji=tr(BTA)對角線上第i個元素為j=1∑nAijBjiT,trace為m個對角線元素的和交換∑順序和乘法順序i,j互換
tr ( A B T ) = ∑ i = 1 n ∑ j = 1 m B i j T A j i = ∑ j = 1 m ∑ i = 1 n B j i A i j T 轉置A,B並交換 ∑ 順序 = ∑ i = 1 m ∑ j = 1 n B i j A j i T i,j互換 = tr ( B A T ) \begin{aligned}\text{tr}(\bold{A}\bold{B}^T) &=\sum\limits_{i=1}^n\sum\limits_{j=1}^mB^T_{ij}A_{ji} \\&= \sum\limits_{j=1}^m\sum\limits_{i=1}^nB_{ji}A^T_{ij} && \text{轉置A,B並交換}\sum\text{順序} \\&= \sum\limits_{i=1}^m\sum\limits_{j=1}^nB_{ij}A^T_{ji} && \text{i,j互換} \\&= \text{tr}(\bold{B}\bold{A}^T)\end{aligned} tr(ABT)=i=1∑nj=1∑mBijTAji=j=1∑mi=1∑nBjiAijT=i=1∑mj=1∑nBijAjiT=tr(BAT)轉置A,B並交換∑順序i,j互換
最後因為 tr ( A B T ) = tr ( B T A ) \begin{aligned}\text{tr}(\bold{A}\bold{B}^T) = \text{tr}(\bold{B}^T\bold{A})\end{aligned} tr(ABT)=tr(BTA),同理 tr ( B A T ) = tr ( A T B ) \text{tr}(\bold{B}\bold{A}^T) = \text{tr}(\bold{A}^T\bold{B}) tr(BAT)=tr(ATB)。
性質二證明
參考A Relation between the Dot Product and the Trace:
tr ( a b T ) = tr ( [ a 1 a 2 . . . a n ] [ b 1 b 2 . . . b n ] ) = tr ( [ a 1 b 1 a 1 b 2 . . . a 1 b n a 2 b 1 a 2 b 2 . . . a 2 b n . . . a n b 1 a n b 2 . . . a n b n ] ) = ∑ i = 1 n a i b i = a T b \begin{aligned}\text{tr}(\bold{a}\bold{b}^T) &= \text{tr}(\begin{bmatrix}a_1 \\ a_2 \\ ... \\ a_n\end{bmatrix}\begin{bmatrix}b_1 & b_2 & ... & b_n\end{bmatrix}) \\&= \text{tr}(\begin{bmatrix}a_1b_1 & a_1b_2 & ... & a_1b_n \\ a_2b_1 & a_2b_2 & ... & a_2b_n \\ ... \\ a_nb_1 & a_nb_2 & ... & a_nb_n \end{bmatrix}) \\&= \sum\limits_{i=1}^n a_ib_i \\&= \bold{a}^T\bold{b}\end{aligned} tr(abT)=tr(⎣⎢⎢⎡a1a2...an⎦⎥⎥⎤[b1b2...bn])=tr(⎣⎢⎢⎡a1b1a2b1...anb1a1b2a2b2anb2.........a1bna2bnanbn⎦⎥⎥⎤)=i=1∑naibi=aTb
cyclic property
tr ( A B C D ) = tr ( B C D A ) = tr ( C D A B ) = tr ( D A B C ) \text{tr}(\bold{ABCD}) = \text{tr}(\bold{BCDA}) = \text{tr}(\bold{CDAB}) = \text{tr}(\bold{DABC}) tr(ABCD)=tr(BCDA)=tr(CDAB)=tr(DABC)
證明
參考Prove that trace(ABC)=trace(BCA)=trace(CAB)。
trace of product的性質一 tr ( A B T ) = tr ( B T A ) , ∀ A , B ∈ R m × n \text{tr}(\bold{A}\bold{B}^T) = \text{tr}(\bold{B}^T\bold{A}), \forall A,B \in \R^{m \times n} tr(ABT)=tr(BTA),∀A,B∈Rm×n可以被重新表述成:
tr ( X Y ) = tr ( Y X ) , ∀ X ∈ R m × n , Y ∈ R n × m \text{tr}(\bold{X}\bold{Y}) = \text{tr}(\bold{Y}\bold{X}), \forall X \in \R^{m \times n},Y \in \R^{n \times m} tr(XY)=tr(YX),∀X∈Rm×n,Y∈Rn×m。
先從三個矩陣相乘開始:
tr ( A B C ) = tr ( A ( B C ) ) 矩陣的結合律 = tr ( ( B C ) A ) tr ( X Y ) = tr ( Y X ) = tr ( B C A ) = tr ( B ( C A ) ) = tr ( ( C A ) B ) tr ( X Y ) = tr ( Y X ) = tr ( C A B ) \begin{aligned}\text{tr}(\bold{A}\bold{B}\bold{C}) &= \text{tr}(\bold{A}(\bold{B}\bold{C})) && \text{矩陣的結合律}\\&= \text{tr}((\bold{B}\bold{C})\bold{A}) && \text{tr}(\bold{X}\bold{Y}) = \text{tr}(\bold{Y}\bold{X})\\&= \text{tr}(\bold{B}\bold{C}\bold{A}) \\&= \text{tr}(\bold{B}(\bold{C}\bold{A})) \\&= \text{tr}((\bold{C}\bold{A})\bold{B}) && \text{tr}(\bold{X}\bold{Y}) = \text{tr}(\bold{Y}\bold{X})\\&= \text{tr}(\bold{C}\bold{A}\bold{B})\end{aligned} tr(ABC)=tr(A(BC))=tr((BC)A)=tr(BCA)=tr(B(CA))=tr((CA)B)=tr(CAB)矩陣的結合律tr(XY)=tr(YX)tr(XY)=tr(YX)
四個矩陣相乘:
tr ( A B C D ) = tr ( A ( B C D ) ) = tr ( ( B C D ) A ) = tr ( B C D A ) = tr ( B ( C D A ) ) = tr ( ( C D A ) B ) = tr ( C D A B ) = tr ( C ( D A B ) ) = tr ( ( D A B ) C ) = tr ( D A B C ) \begin{aligned}\text{tr}(\bold{ABCD}) &= \text{tr}(\bold{A}(\bold{BCD})) = \text{tr}((\bold{BCD})\bold{A}) = \text{tr}(\bold{BCDA}) \\&= \text{tr}(\bold{B}(\bold{CDA}))= \text{tr}((\bold{CDA})\bold{B}) = \text{tr}(\bold{CDAB}) \\&= \text{tr}(\bold{C}(\bold{DAB}))= \text{tr}((\bold{DAB})\bold{C}) = \text{tr}(\bold{DABC})\end{aligned} tr(ABCD)=tr(A(BCD))=tr((BCD)A)=tr(BCDA)=tr(B(CDA))=tr((CDA)B)=tr(CDAB)=tr(C(DAB))=tr((DAB)C)=tr(DABC)