Linear Algebra(2) - Span/Basis/Linear Projection

2021. 1. 30. 10:23[AI]/Data Science Fundamentals

<Learned Stuff>

[Linear Algebra +]

Key points

  • covariance/correlation coefficient
  • span
  • basis
  • rank
  • project $\vec{a}$ onto $\vec{b}$

 

개념

  • orthogonality
  • unit vectors
  • Gaussian Elimination

<New Stuff>

[Covariance/Correlation Coefficient]

$Variance = \frac{\sum(X-\bar{X})^2}{N}$

# A 라는 array가 있다고 가정 

A.var(ddof=) # population : ddof = 0 / sample : ddof = 1
==> # returns variance of 'A'

 

$Standard \ Deviation = \sqrt{Var(X)}$

# A 라는 array가 있다고 가정

A.std(ddof=) # population : ddof = 0 / sample : ddof = 1
# ==> returns std of 'A'

 

$Covariance = \frac{\sum[(X-\bar{X})(Y-\bar{Y})]}{N}$

  • 두 그룹간의 연관성을 의미
  • 하지만 두 그룹의 scale(길이, 무게, etc)이 다르다면 covariance만으로 분석하기 힘듦
# A 와 B라는 array가 있다고 가정 (same length)

np.cov(A,B,ddof=) #population일 경우 ddof=0, sample일 경우 ddof=1
# ==> returns 2 X 2 symmetric matrix with diagnoal : variance
[[var(A) cov(AB)]
[cov(BA) var(B)]]

 

$Correlation \ Coefficient \ or \ \rho = \frac{Cov(X,Y)}{\sigma_X\sigma_Y}$

  • if $0<\rho<1$ : (+) relationship
    • as X increases, Y increases / as X decreases, Y decreases
  • if $-1<\rho<0$ : (-) relationship
    • as X increases, Y decreases / as X decreases, Y increases
  • if $\rho = 0$ : no relationship
  • 의미있는 분석이 가능
# A 와 B라는 array가 있다고 가정 (same length)

np.corrcoef(A,B)
# ==> returns 2 X 2  symmetric matrix with diagonals : 1 (자기 자신에 대한 correlation)

 

[Span/Basis/Rank]

$\begin{bmatrix} a_{11} \\ a_{21} \\ a_{31} \\ \vdots \\ a_{m1} \end{bmatrix}$, $\begin{bmatrix} a_{12} \\ a_{22} \\ a_{32} \\ \vdots \\ a_{m2} \end{bmatrix}$ $\dotsm$ $\begin{bmatrix} a_{1n} \\ a_{2n} \\ a_{3n} \\ \vdots \\ a_{mn} \end{bmatrix}$ 의 linearly independent한 vectors가 있다고 가정

 

$W$ 는 $\mathbb{R^m}$의 부분공간이고,

 

$W = \{c_1\cdot\begin{bmatrix} a_{11} \\ a_{21} \\ a_{31} \\ \vdots \\ a_{m1} \end{bmatrix}+ c_2\cdot\begin{bmatrix} a_{12} \\ a_{22} \\ a_{32} \\ \vdots \\ a_{m2} \end{bmatrix} + \dotsm + c_n\cdot\begin{bmatrix} a_{1n} \\ a_{2n} \\ a_{3n} \\ \vdots \\ a_{mn} \end{bmatrix}|c_1,c_2, \dotsm c_n\in R\}$ 만족하는 모든 벡터 조합

 

이때, $\biggl(\begin{bmatrix} a_{12} \\ a_{21} \\ a_{31} \\ \vdots \\ a_{m1} \end{bmatrix},\begin{bmatrix} a_{12} \\ a_{22} \\ a_{32} \\ \vdots \\ a_{m2} \end{bmatrix},\begin{bmatrix} a_{1n} \\ a_{2n} \\ a_{3n} \\ \vdots \\ a_{mn} \end{bmatrix}\biggr)$ 은 $W$의 basis가 되고 $W$의 Rank는 n이라는 것을 알 수 있다.

 

(basis의 원소의 갯수가 부분공간 $W$의 Rank를 의미)

 

[Project $\vec{a}$ onto $\vec{b}$]

([7,4] 인 vector를 y=x 에 project 시키기)

 

$proj_B(A)$ : project $\vec{A}$ onto $\vec{B}$ ($\vec{\mu}$ 라고 가정)

 

$\vec{\mu} = |\vec{\mu}| \cdot \hat{\mu}$

 

1. $\cos(\theta)$ 를 통해 $|\vec{\mu}|$ 구하기

($\vec{\mu} 와 \vec{A}$ 사이)

$\cos(\theta) = \frac{|\vec{\mu}|}{|\vec{A}|}$

 

($\vec{B}$ 와 $\vec{A}$ 사이)

$\cos(\theta) = \frac{\vec{A}\cdot \vec{B}}{|\vec{A}|\cdot|\vec{B}|}$ , 즉

$\frac{|\vec{\mu}|}{|\vec{A}|} = \frac{\vec{A}\cdot \vec{B}}{|\vec{A}|\cdot|\vec{B}|}$ ==> $|\vec{\mu}| = \frac{\vec{A}\cdot \vec{B}}{|\vec{B}|}$

 

2. $\hat{\mu}$ 구하기
$\hat{\mu} = \hat{B} = \frac{\vec{B}}{|\vec{B}|} $

 

3. 1 & 2 합치기
$\vec{\mu} = |\vec{\mu}| \cdot \hat{\mu} = \frac{\vec{A}\cdot \vec{B}}{|\vec{B}|^2}\cdot\vec{B}$

 

[Orthogonal/Orthonormal]

$Orthogonal$ : dot product of two vectors = 0

$Orthonormal$ : orthogonal and the magnitudes of two vectors = 1 

 

[Unit vectors]

$Unit \ vectors$ : vectors having magnitudes = 0

 

[Gaussian Elimination]

$Gaussian \ Elimination$ : Row-Echelon form으로 바꿔주는 과정

 

 

728x90