Post

Matrix

Based on the lecture “Mathematics for Artificial Intelligence (2022-1)” by Prof. Yeo Jin Chung, Dept. of AI, Big Data & Management, College of Business Administration, Kookmin Univ.

What? Matrix


\[\begin{aligned} A_{n\times p}&=\begin{pmatrix} a_{11}&a_{12}&\cdots&a_{1p}\\ a_{21}&a_{22}&\cdots&a_{2p}\\ \vdots&\vdots&\cdots&\vdots\\ a_{n1}&a_{n2}&\cdots&a_{np} \end{pmatrix}\\ &=(a_{ij})\in R^{n\times p}, \\ i&=1, 2, \cdots, n,\\ j&=1, 2, \cdots, p \end{aligned}\]
  • 행렬(Matrix)
    • 행(row)과 열(column)로 구분된 직사각 모양의 배열
    • 행벡터 혹은 열벡터의 집합
  • 표기법
    • 행렬(Matrix) : $A$
    • 벡터(Vector) : $\overrightarrow{a}$
    • 스칼라(Scala) : $\alpha, \beta, \gamma, \cdots$
    • 원소(Element) : $a_{ij}$
  • 크기(Size)
    • 길이(Length; $n$) : 행벡터의 갯수, 관측치의 갯수
    • 차원(Dimention; $p$) : 열벡터의 갯수, 특징의 갯수
    • 크기(Size; $n \times p$) : 행렬의 크기

특수한 행렬


  • 정방행렬(Square Matrix) : 행벡터의 갯수와 열벡터의 갯수가 동일한 행렬

    \[\begin{aligned} A_{n}&=\begin{pmatrix} a_{11}&a_{12}&\cdots&a_{1n}\\ a_{21}&a_{22}&\cdots&a_{2n}\\ \vdots&\vdots&\cdots&\vdots\\ a_{n1}&a_{n2}&\cdots&a_{nn} \end{pmatrix}\\ &=(a_{ij})\in R^{n\times n}, \\ i&=1, 2, \cdots, n,\\ j&=1, 2, \cdots, n \end{aligned}\]
  • 영행렬(Zero-Matrix) : 그 원소가 모두 0인 행렬

    \[0=\begin{pmatrix} 0&0&0\\ 0&0&0\\ 0&0&0 \end{pmatrix}\]
    • 덧셈에 대한 항등원

      \[A + 0 = A\]
  • 항등행렬(Identify Matrix; $I_n$) : 대각항 원소는 모두 1이고, 비대각항 원소는 모두 0인 정방행렬

    \[I_3=\begin{pmatrix} 1&0&0\\ 0&1&0\\ 0&0&1 \end{pmatrix}\]
    • 내적에 대한 항등원

      \[A\cdot I = I \cdot A = A\]
    • 각 차원에 대하여 그 단위벡터들의 모임

      \[\begin{aligned} I_n&= \begin{bmatrix}\overrightarrow{e_1}&\overrightarrow{e_2}&\overrightarrow{e_3}&\cdots&\overrightarrow{e_n}\end{bmatrix}\\ &= \begin{bmatrix} \overrightarrow{e_1}\\ \overrightarrow{e_2}\\ \overrightarrow{e_3}\\ \vdots\\ \overrightarrow{e_n} \end{bmatrix} \end{aligned}\]
  • 대각행렬(Diagonal Matrix; $\text{diag}$) : 대각항을 제외한 모든 원소가 0인 정방행렬

    \[\text{diag}(1, 2, 3)=\begin{pmatrix} 1&0&0\\ 0&2&0\\ 0&0&3 \end{pmatrix}\]
  • 삼각행렬(Triangular Matrix) : 대각항을 기준으로 그 아래 혹은 위에 위치한 원소가 모두 0인 정방행렬

    \[\begin{pmatrix} 1&4&5\\ 0&2&6\\ 0&0&3 \end{pmatrix}, \begin{pmatrix} 1&0&0\\ 4&2&0\\ 5&6&3 \end{pmatrix}\]
  • 대칭행렬(Symmetric Matrix) : 그 전치행렬이 자기 자신이 되는 정방행렬

    \[\begin{aligned} A^T&=A\\ a_{ij}&=a_{ji} \end{aligned}\] \[\begin{pmatrix} 1&3&0\\ 3&2&1\\ 0&1&-1 \end{pmatrix}^T= \begin{pmatrix} 1&3&0\\ 3&2&1\\ 0&1&-1 \end{pmatrix}\]
    • 대칭행렬이 가역성을 가지면 그 역행렬 또한 대칭행렬임

      \[\begin{aligned} if\;A^T&=A,\\ A^{-1}A&=I\\ (A^{-1}A)^T&=I \, (\because I^T=I)\\ A^T(A^{-1})^T&=I\\ A(A^{-1})^T&=I\\ A^{-1}A(A^{-1})^T&=A^{-1}I\\ \therefore (A^{-1})^T&=A^{-1} \end{aligned}\]
  • 직교행렬(Orthogonal Matrix) : 모든 행벡터 혹은 열벡터가 직교정규벡터로 구성된 행렬

    \[\overrightarrow{a_{1}}\perp\overrightarrow{a_{2}}\perp\cdots\perp\overrightarrow{a_{n}},\] \[A= \begin{bmatrix} \overrightarrow{a_1}&\overrightarrow{a_2}&\cdots&\overrightarrow{a_n} \end{bmatrix}\]
    • 직교행렬의 역행렬은 그 전치행렬임

      \[A^TA=AA^T=I\]

Matrix Operation


  • 덧셈과 뺄셈
    • 크기가 $n\times p$ 로 동일한 행렬 $A, B$ 의 덧셈 혹은 뺄셈을 대응 원소의 합 혹은 차로 정의함

      \[\begin{aligned} A_{n \times p}&=\begin{bmatrix}a_{ij}\end{bmatrix},\\ B_{n \times p}&=\begin{bmatrix}b_{ij}\end{bmatrix}\\ A+B&=\begin{bmatrix}a_{ij}+b_{ij}\end{bmatrix},\\ i&=1, 2, 3, \cdots, n, \\ j&=1, 2, 3, \cdots, p \end{aligned}\]
  • 스칼라-행렬 곱셈
    • 스칼라와 행렬의 곱셈을 행렬의 모든 원소에 대한 스칼라 곱으로 정의함

      \[\begin{aligned} \alpha &\in R, \\ A_{n \times p}&=\begin{bmatrix}a_{ij}\end{bmatrix} \\ \alpha A_{n \times p}&=\begin{bmatrix}\alpha \times a_{ij}\end{bmatrix},\\ i&=1, 2, 3, \cdots, n, \\ j&=1, 2, 3, \cdots, p \end{aligned}\]
  • 전치(Transpose)
    • 행렬의 전치는 그 행과 열의 위치를 바꾸는 연산으로 정의함

      \[\begin{aligned} A_{n \times p}&=\begin{bmatrix}a_{ij}\end{bmatrix} \\ (A_{n \times p})^T&=\begin{bmatrix}a_{ji}\end{bmatrix} \\ &=A_{p \times n}, \\ i&=1, 2, 3, \cdots, n, \\ j&=1, 2, 3, \cdots, p \end{aligned}\]
    • 성질

      • $\alpha^T=\alpha$
      • $(A+B)^T=A^T+B^T$
      • $(\alpha A)^T=\alpha(A^T)$
      • $(AB)^T=B^TA^T$
  • 대각합(Trace; $\text{tr}$)
    • 정방행렬 $A_n$ 의 대각합은 그 대각항의 총합으로 정의함

      \[\text{tr}(A_n)=\sum_{i=1}^{n}a_{ii}\]

Matrix Multiplication


  • 적합성 조건(Conformability Condition)
    • 전항의 차원(열벡터 갯수)과 후항의 길이(행벡터 갯수)가 동일함
  • 행렬 곱셈
    • 적합성 조건을 만족하는 행렬 $A_{n \times p},B_{p \times m}\(을 곱한 값\)C_{n \times m}$$ 를 다음과 같이 정의함

      \[\begin{aligned} C_{n \times m}&=\begin{bmatrix}c_{il}\end{bmatrix}\\ c_{il}&=\sum_{j=1}^{p}(a_{ij}\times b_{jl}), \\ i&=1, 2, 3, \cdots, n, \\ j&=1, 2, 3, \cdots, p, \\ l&=1, 2, 3, \cdots, m \end{aligned}\]
      • 즉, 전항의 $i$ 번째 행벡터와 후항의 $i$ 번째 열벡터 간 내적의 집합임
    • 교환법칙이 성립하지 않음

      \[A_{n \times p}B_{p \times m} \ne B_{p \times m}A_{n \times p}\]

Inverse Matrix


  • 역행렬(Inverse Matrix)
    • 정방행렬 $A_n, B_n$ 에 대하여 다음을 만족하는 경우 양자는 서로 역행렬 관계에 있음

      \[AB=BA=I \Rightarrow A^{-1}=B\,and\,B^{-1}=A\]
  • 성질
    • $I^{-1}=I$
    • $A_n=diag\begin{bmatrix}a_{ii}\end{bmatrix},\;i=1,2,3,\cdots,n \ \Rightarrow A^{-1}=diag\begin{bmatrix}\frac{1}{a_{ii}}\end{bmatrix}$
    • $A=\begin{bmatrix}\overrightarrow{a_1}&\overrightarrow{a_2}&\cdots&\overrightarrow{a_n}\end{bmatrix},\;\overrightarrow{a_{1}}\perp\overrightarrow{a_{2}}\perp\cdots\perp\overrightarrow{a_{n}} \ \Rightarrow A^{-1}=A^T$
    • $(\alpha A)^{-1}=\alpha^{-1}A^{-1}$
    • $(A^{T})^{-1}=(A^{-1})^T$
    • $(AB)^{-1}=B^{-1}A^{-1}$
  • 가역성
    • 가역성(Inverible) : 그 역을 계산할 수 있는 성질
      • 정칙행렬(Non-Singular Matrix) : 가역성을 가지는 행렬
      • 특이행렬(Singular Matrix) : 가역성을 가지지 않는 행렬
    • 가역성을 가질 조건
      • $\text{det}(A_n) \ne 0$
      • $\text{rank}(A_n)=n$
      • 행렬 $A_n$ 를 구성하는 모든 벡터는 선형 독립임
      • 행렬 $A_n$ 를 구성하는 모든 벡터를 $span$ 하여 $n$ 차원 공간을 구성할 수 있음
  • 계산 방법
    • $2\times 2$ 정방행렬에 한하여 그 역행렬을 다음과 같이 구할 수 있음

      \[\begin{aligned} &A_2= \begin{pmatrix} a&b\\ c&d \end{pmatrix},\;ad-bc \ne 0 \\ &\Rightarrow A_{2}^{-1}=\frac{1}{ad-bc}\begin{pmatrix} d&-b\\ -c&a \end{pmatrix} \end{aligned}\]
    • $3\times 3$ 이상의 정방행렬에 대하여 그 역행렬은 가우스-조르단 소거법(Gaussian Elimination)으로 구함

Determinant


  • 행렬식(Determinant; $\text{det}$)

    \[\text{det}(A_n)\; or\; |A|\]
    • 정방행렬 $A_n$ 를 실수에 대응시키는 함수
    • 기하학적으로 봤을 때, 정방행렬 $A_n$ 를 구성하는 열벡터에 의해 결정되는 평행사변형의 부피를 의미함
  • 해석
    • $n \times n$ 정방행렬에 대하여 그 행렬식이 $0$ 이 아닌 경우 그 역행렬이 존재함
    • $n \times n$ 정방행렬에 대하여 그 행렬식이 $0$ 이 아닌 경우 그 계수는 $n$ 임
    • $n \times n$ 정방행렬에 대하여 그 행렬식이 $0$ 이 아닌 경우 이를 구성하는 구성하는 모든 벡터는 선형 독립임
    • $n \times n$ 정방행렬에 대하여 그 행렬식이 $0$ 이 아닌 경우 이를 구성하는 구성하는 모든 벡터를 $span$ 하여 $n$ 차원 공간을 구성할 수 있음
  • 성질
    • $\text{det}(\alpha)=\alpha$
    • $\text{det}(I)=1$
    • $\text{det}(A)=det(A^T)$
    • $\text{det}(A^{-1})=\text{det}(A)^{-1}$
    • $\text{det}(AB)=\text{det}(A) \times \text{det}(B)$
    • $\text{det}(\alpha \times A_n)=\alpha^n \times \text{det}(A_n)$
    • $\begin{vmatrix} \cdots & \overrightarrow{a_i} \cdots \overrightarrow{a_j} \end{vmatrix}=-\begin{vmatrix} \cdots & \overrightarrow{a_j} \cdots \overrightarrow{a_i} \end{vmatrix}$
    • $\begin{vmatrix}\alpha \times a & \alpha \times b \ c & d\end{vmatrix} = \alpha \times \begin{vmatrix}a&b\ c&d\end{vmatrix}$
  • 계산 방법
    • $\text{det}(A_2)=a_{11}a_{22}-a_{12}a_{21}$
    • 삼각행렬에 대하여 그 행렬식은 대각항 원소들의 곱으로 구할 수 있음
    • $3\times 3$ 이상의 정방행렬에 대하여 그 행렬식은 가우스-조르단 소거법(Gaussian Elimination)으로 구함

Rank


  • 계수(Rank) : 임의의 행렬을 구성하는 벡터 중 선형 독립인 벡터의 갯수

    \[\text{rank}(A)\]
  • Full-Rank : 크기가 $n \times p$ 인 모든 행렬에 대하여 그 계수가 될 수 있는 가장 큰 값

    \[\text{rank}(A_{n \times p})=\min{(n,p)}\]
  • 해석

    • $n \times n$ 정방행렬에 대하여 그 계수가 $Full-Rank$ 인 경우 그 역행렬이 존재함
    • $n \times n$ 정방행렬에 대하여 그 계수가 $Full-Rank$ 인 경우 그 행렬식은 $0$ 이 아님
    • $n \times n$ 정방행렬에 대하여 그 계수가 $Full-Rank$ 인 경우 이를 구성하는 구성하는 모든 벡터는 선형 독립임
    • $n \times n$ 정방행렬에 대하여 그 계수가 $Full-Rank$ 인 경우 이를 구성하는 구성하는 모든 벡터를 $span$ 하여 $n$ 차원 공간을 구성할 수 있음
This post is licensed under CC BY 4.0 by the author.