1. Linear Algebra - (1)
Matrices
์ด๋ฒ ์๊ฐ์๋ ๊ธฐ๊ณํ์ต์ ์ํ ์ํ ์ค, ์ ํ๋ ์ํ์ Matrix ์ ๋ํ ๊ธฐ๋ณธ์ ์ธ ๊ฐ๋
๋ค์ ์์๋ณธ๋ค.
Inverse
Definition of Inverse:
- Consider a square matrix , Let matrix have the property that .\ is called the inverse of and denoted by
์ฆ ์ ์ ๋ฐฉํ๋ ฌ ์ ๋ํ์ฌ ํ๋ ฌ๊ณฑ์ ํ์ ๋ Identity matrix๊ฐ ๋์ค๊ฒ ํ๋ ์ ๋ฐฉํ๋ ฌ ๋ฅผ ์ inverse matrix ๋ผ๊ณ ํ๋ค.
์ญํ๋ ฌ์ ์ฃผ์ด์ง ํ๋ ฌ์ด ๊ฐ์ญ์ (invertible)์ผ ๋๋ง ์กด์ฌ.
๊ฐ์ญ์ฑ์ ํ๋ ฌ์(Determinant) ๋ฅผ ํตํด์ ํ๋จ ๊ฐ๋ฅํ๊ณ ( โ invertible), ์ด๋ฅผ ๊ตฌํ๊ธฐ ์ํด์๋ ํ๋ ฌ์ด ์ ๋ฐฉํ๋ ฌ์ด์ฌ์ผํจ.
(p.s. ์ ๋ฐฉํ๋ ฌ์ด ์๋ ํ๋ ฌ์์์๋ Moore-Penrose pseudo-inverse ๋ฅผ ํตํด์ ํด๋ฅผ ๊ทผ์ฌํ ์ ์์.)
- ๋ชจ๋ matrix๊ฐ inverse matrix๋ฅผ ๊ฐ์ง๋ ๊ฒ์ ์๋๋ค.
- ๋ง์ฝ inverse matrix๊ฐ ์กด์ฌํ๋ค๋ฉด, ๊ทธ matrix๋ regular/invertible/nonsingular ๋ผ๊ณ ๋ถ๋ฅธ๋ค.
- ๋ง์ฝ ์กด์ฌํ์ง ์๋๋ค๋ฉด, singular/noninvertible ๋ผ๊ณ ๋ถ๋ฅธ๋ค.
Transpose
Definition of Transpose:
- For the matrix with is called the transpose of . We write
์ฆ Matrix ์์๋ค์ Row์ Column์ด ๋ฐ๋ ์ํ๋ฅผ ์๋ฏธํ๋ค.
- ๋ง์ฝ matrix ์ ๋ํด์ ๋ผ๋ฉด ๋ symmetric ์ด๋ผ๊ณ ํ๋ค.
vanilla python์ผ๋ก matrix์ upper triangle๋ง ํ์ํ์ฌ ๊ฐ๋จํ๊ฒ transpose๋ฅผ ๊ตฌํํ ์ ์๋ค. (or numpy.array.T
)
#nxn matrix
for i in range(n): #row
for j in range(i+1, n): #col
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
Compact representation of system of linear equations
์ฐ๋ฆฌ๋ Matrix์ Vector๋ฅผ ์ฌ์ฉํ์ฌ linear equations๋ฅผ ํํํ ์ ์๋ค.
์๋์ ๊ฐ์ Linear equation์
์๋์ ๊ฐ์ด ํํ์ Matrix์ Vector ๋ก ํํ๋ ์ ์๋ค.
์๋ฅผ ๋ค์ด
์์ System์ 2๊ฐ์ equation๊ณผ 4๊ฐ์ unknown variable์ด ์กด์ฌํ๋ค. (์ฆ ๋ฌด์ํ ํด(solutions)๊ฐ ์กด์ฌ)
์ด ๋ฌธ์ ๋ ๋ง์ฐฌ๊ฐ์ง๋ก ์ ํํ๋ก ํํํ ์ ์๋๋ฐ, ์ฌ๊ธฐ์ ๋ ๋ฒ์งธ Column์ด๊ณ ๋ ์ด๋ค.
๊ทธ๋ผ ์ด ์์ ์ด๋ป๊ฒ ํ ์ ์์๊น?
Particular Solution
Particular Solution(ํน๋ณํด)์ ๋ง ๊ทธ๋๋ก ์ด๋ ํ Linear equation system์ ๋ง์กฑํ๋ ํ๋์ ํน์ ํ ํด ์ด๋ค.
์๋ฅผ ๋ค์ด ๋ฐ๋ก ์์ ์ linear equation ์์
์ linear equation์ ๋ง์กฑํ๋ ํด๋ single 1 ์ ํฌํจํ๋ column๋ค์ ํตํด์ ์ฝ๊ฒ ๊ตฌํ ์ ์์ผ๋ฉฐ ์ด ๊ฒฝ์ฐ ๊ฐ ๋ ๊ฒ์ด๋ค.
General Solution
General Solution(์ผ๋ฐํด) ๋ Linear equation system์ ๋ง์กฑํ๋ ๋ชจ๋ ํด๋ค์ ์งํฉ ์ ๋ํ๋ธ๋ค.
๊ฐ๋จํ ์์ด๋์ด๋ก, Linear equation์์ ์ด๋ฏธ ๊ตฌํ Particular solution์ 0์ ๋ํ๋ ๊ฒ์ ๊ธฐ์กด ํด๊ฐ ์ฑ๋ฆฝํ๋๋ฐ ์ ์์ด์ ์๋ฌด๋ฐ ์ํฅ์ ์ฃผ์ง ์์๊ฒ์ด๋ค.
๋ฐ๋ผ์ ์ด๋ฅผ ์ด์ฉํ์ฌ Particular solution์์ ์ฌ์ฉ๋์ง ์๋ ๋ณ์ (์์ ์์ ์์ ) ๋ฅผ linear combination์ผ๋ก ํํํ๊ณ , ์์ ๋ณ์ ๋ฅผ ์ฌ์ฉํ์ฌ homogeneous solution ์ ์ถ๊ฐํด ๋ ๋ง์ ํด๋ค์ ์งํฉ ๋ฅผ ๊ตฌํ ์ ์๋ค.
์์ ์์ ์์ ๋ (which is ) + (which is ) ๋ก ๋ํ๋ผ ์ ์๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก 4๋ฒ์งธ ํญ๋ ์๋์ ๊ฐ์ด ํํ ๊ฐ๋ฅํ๋ค.
์ต์ข ์ ์ผ๋ก general solution์ ์๋์ฒ๋ผ ํํ ๊ฐ๋ฅํ๋ค.
Row-Echelon Form
Linear equation์ Solution์ ๊ตฌํ ๋์๋ Matrix๋ฅผ Reduced Row-Echelon Form์ผ๋ก ๋ง๋ค๋ฉด ๋งค์ฐ ์ ์ฉํ๋ค.
์ฌ๊ธฐ์ (Reduced) Row-Echelon Form์ ๋ญ๊น?
Definition of Row-Echelon Form (REF):
- All rows that contains only zeros are at the bottom of the matrix; correspondingly, all rows that contains at least one nonzero element are on top of rows that contain only zeros.
- Looking at nonzero rows only, the first nonzero number from the left (also called pivot) is always strictly to the right of the pivot of the row above it.
์ฐธ๊ณ : REF ์์ Pivot value์ ๋ํ ์ ์๊ฐ ๋ค๋ฅธ ๊ฒฝ์ฐ๊ฐ ์๋ค.
*Technically, theย leading coefficientย can be any number. However, the majority of Linear Algebra textbooks do state that the leading coefficient must be the number 1. To add to the confusion, some definitions of row echelon form state that there must be zeros both aboveย andย below the leading coefficient. Itโs therefore best to follow the definition given in the textbook youโre following (or the one given to you by your professor). ref;* statisticshowto
์๋ฅผ ๋ค์ด,
์์ Matrix๋ ๋ชจ๋ Pivot ์ด ์ด์ row ์ Pivot ์์น๋ณด๋ค ์ค๋ฅธ์ชฝ์ ์๊ณ ,
๋ชจ๋ ๊ฐ์ด 0์ธ Row๊ฐ ์ ์ผ ๋ฐ์ ์กด์ฌํ๋ฏ๋ก Row-Echelon Form ์ด๋ผ๊ณ ํ ์ ์๋ค.
Definition of Reduced Row-Echelon Form (RREF):
- It is in row-echelon form
- Every pivot is 1.
- The pivot is the only nonzero entry in its column.
์๋ฅผ ๋ค์ด,
์์ Matrix๋ 1) ๋ชจ๋ Pivot value๊ฐ 1์ด๊ณ , 2) ์ด์ row์ Pivot๋ณด๋ค ์ค๋ฅธ์ชฝ์ ์์ผ๋ฉฐ, 3) ๊ฐ Pivot์ Column์ pivot์ด์ธ์ ๊ฐ๋ค์ด ๋ชจ๋ 0์ด๊ธฐ ๋๋ฌธ์ Reduced Row-Echelon Form ์ด๋ผ๊ณ ํ ์ ์๋ค.
Reduced Row-Echelon Form์์๋ Linear equation์ ํด๋ฅผ ๋งค์ฐ ์ฝ๊ฒ ๊ตฌํ ์ ์๋ค.
๊ฐ๊ฐ์ ๋ฒ์งธ Pivot์ด ์ ํด๋ฅผ ๋ํ๋ด๋ฏ๋ก
์ด๊ณ Pivot์ด ์กด์ฌํ์ง ์๋ 2๋ฒ์งธ Column์ free variable์ด ๋๋ฏ๋ก ๋จ์ํ 0 ์ ๋์ ํด ์ ์ป์ผ๋ฉด ํ๋์ Particular Solution์ ์ป์ ์ ์๋ค.
Free variable์ ํ์ฉํ General Solution๋ ๋ง์ฐฌ๊ฐ์ง๋ก ์๋์ ๊ฐ์ด ๊ตฌํ ์ ์๋ค
์ฌ๊ธฐ์ ๋ Free variable์ด๋ฏ๋ก ๋ผ๊ณ ํ๋ฉด
์ฆ
ํน์ Minus one Trick์ ์ฌ์ฉํ์ฌ ์ง๊ด์ ์ผ๋ก ๊ตฌํ ์๋ ์๋ค.
Free variable์ด ์์นํ๋ Column์ -1 ์ ๋ฃ์ด์ฃผ๋ฉด
๋ง์ฐฌ๊ฐ์ง๋ก ๋ฅผ ์ป์ ์ ์๋ค.
Reduced Row-Echelon Form์ ๋ง๋๋ ๋ฐฉ๋ฒ์ผ๋ก๋ Gaussian elimination algorithm์ ์ฌ์ฉํ๋ฉด ๋๋ค.
Ref: Wikipedia
Ref:
- POSTECH CSED343 (Prof. Dongwoo Kim)
- Mathematics for Machine Learning, Marc Peter Deisenroth, A. Aldo Faisal, and Cheng Soon Ong, Cambridge University Press 2020