Post

PCA

๐Ÿ™…โ€โ™‚๏ธํœด๋Œ€ํฐ์œผ๋กœ ๋ณผ ๋•Œ ํ˜น์‹œ ๊ธ€์ž๋‚˜ ์ˆซ์ž๊ฐ€ ํ™”๋ฉด์— ๋‹ค ์•ˆ๋‚˜์˜ค๋ฉด, ํœด๋Œ€ํฐ ๊ฐ€๋กœ๋กœ ๋Œ๋ฆฌ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค

1
2
3
4
5
6
7
8
9
10
<๋ชฉ์ฐจ>
1. PreRequisites
2. PCA 
 2-1. PCA๋ž€?
 2-2. PCA์ฆ๋ช… (์ข€ ๊ธธ๋‹ค)
  (1) ๐Ÿ˜‹minimize(์ตœ์†Œํ™”)
  (2) ๐Ÿงโ€โ™€๏ธmaximize
3. PCA ์‘์šฉ
 3-1. ์ฐจ์›์ถ•์†Œ(์˜ˆ์‹œ)
 3-2. ์ฐจ์›์ถ•์†Œ(์˜์ƒ)

1. PreRequistes

  1. Eigen decompostion
  2. Lagrange Multiplier
  3. LSM
  4. covariance matrix

2. PCA

2-1. PCA๋ž€?

Desktop View

๋ชฉํ‘œ:

์ฐจ์› ์ถ•์†Œ๋ฅผ ํ•  ๋•Œ ์› ๋ฐ์ดํ„ฐ์˜ ๋ถ„์‚ฐ์„ ๋ณด์กดํ•  ๊ฒƒ

๊ฐœ๋…:

์ขŒํ‘œ๊ฐ’๋“ค์ด ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ๋‹ค ๊ทธ๋ž˜์„œ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋ฐํ„ฐ๊ฐ€ ๋ถ„ํฌ๋ฅผ ์ด๋ฃจ๊ณ  ์žˆ์Œ
์—ฌ๊ธฐ์„œ ๋ฐ์ดํ„ฐ ๋ถ„ํฌ์˜ ํ‰๊ท ์œผ๋กœ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด ๋ฐ์ดํ„ฐ์˜ ๋ถ„ํฌ๋ฅผ ๊ฐ€์žฅ ์ž˜ ์„ค๋ช…ํ•ด์ฃผ๋Š” ๋ฐฉํ–ฅ์„ PCA๋ผ ํ•œ๋‹ค.
์ฆ‰ ๋ชฉํ‘œ๋ฅผ ์žฌ์ •์˜ํ•˜์ž๋ฉด ๋‹ค์‹œ๋งํ•ด \(\color{red}{\nearrow}\)์˜ ๋ฒกํ„ฐ๋ฅผ ์ฐพ์•„ ์ฐจ์›์ถ•์†Œ๋ฅผ ํ•ด์•ผํ•œ๋‹ค

์˜ˆ์‹œ:

๋งŒ์•ฝ ๋‚ด๊ฐ€ ์ฐพ์€ ์ฃผ์„ฑ๋ถ„ ๋ฒกํ„ฐ์— ๋ฐ์ดํ„ฐ๋“ค์„ ํ™•๋Œ€ํ•ด์„œ ๋ดค์„ ๋•Œ,
1์ฐจ์› ์ถ•์œผ๋กœ ๋ฐ์ดํ„ฐ๋“ค์„ ์ •์‚ฌ์˜ ์‹œ์ผฐ๋‹ค๊ณ  ํ•˜์ž
Desktop View
์ฐจ์› ์ถ•์†Œ (2D \(\Rightarrow\) 1D)

๊ฒฐ๋ก :

Desktop View

์œ„์˜ ๊ฐœ๋…์„ ํ† ๋Œ€๋กœ ์ด ๋ถ„ํฌ์˜ ๋ถ„์‚ฐ์ด ๊ฐ€์žฅ ํฐ ๋ฐฉํ–ฅ์ธ \(\color{red}{\nearrow}\)๊ฐ€ ์ด ๋ถ„ํฌ๋ฅผ ๊ฐ€์žฅ ์ž˜์„ค๋ช…ํ•˜๋Š” ๋ฐฉํ–ฅ์ด๊ณ ,
๊ทธ๋ฆฌ๊ณ  ๋‘ ๋ฒˆ์งธ๋กœ ๋ถ„์‚ฐ์ด ํฌ๊ณ  ์ฒซ๋ฒˆ์งธ ์ฃผ์„ฑ๋ถ„๊ณผ orthogonal ํ•œ ๋ฐฉํ–ฅ์ธ \(\color{green}{\nearrow}\)๊ฐ€ 2๋ฒˆ์งธ๋กœ ์ž˜ ์„ค๋ช…ํ•œ๋‹ค.


2-2. PCA์ฆ๋ช… (์ข€ ๊ธธ๋‹ค)

๋‹น์—ฐํ•˜๊ฒŒ ๋ฐ›์•„๋“ค์ด์ง€๋ง๊ณ  PCA ๊ฐœ๋…์— ๋Œ€ํ•ด ์งˆ๋ฌธ์„ ๋˜์ ธ๋ณด์ž
---------------์งˆ๋ฌธ-----------------
1๏ธโƒฃ ์™œ ๋ถ„์‚ฐ์ด ๊ฐ€์žฅ ํฐ ๋ฐฉํ–ฅ์ด ์ด ๋ถ„ํฌ๋ฅผ ์ž˜ ์„ค๋ช…ํ•˜๋Š”๊ฐ€?
2๏ธโƒฃ ์™œ ๊ทธ๋‹ค์Œ์œผ๋กœ ์ž˜ ์„ค๋ช…ํ•˜๋Š” ๋ฐฉํ–ฅ์€ ์ฒซ ๋ฒˆ์งธ ์ฃผ์„ฑ๋ถ„์— ์ˆ˜์งํ•˜๋ƒ?
-----------------------------------------

์ž ์ฃผ์„ฑ๋ถ„๋ถ„์„ ์ฆ๋ช…์„ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผ ์‹œ์ž‘ํ•ด๋ณด์ž
์šฐ์„  ํ‰๊ท ์œผ๋กœ๋ถ€ํ„ฐ ์ถœ๋ฐœํ•ด ๊ฐ€์žฅ ๋ถ„ํฌ๋ฅผ ์ž˜ ์„ค๋ช…ํ•˜๋Š” ๋ฐฉํ–ฅ์„ ์ฐพ์•„์•ผํ•˜๋‹ˆ
ํ˜„์žฌ 4์‚ฌ๋ถ„๋ฉด์— ์žˆ๋Š” ๋ถ„ํฌ๋“ค์˜ ํ‰๊ท ์ด 0์ด ๋˜๋„๋ก ๋ถ„ํฌ์˜ ์ค‘๊ฐ„์ ์„ ๊ธฐ์ค€์—์„œ ์›์ ์œผ๋กœ ์˜ฎ๊ธฐ์ž
์ด๊ฒŒ ๋ฌด์Šจ ๋ง์ด๋ƒ๋ฉด ์•„๋ž˜ ๊ทธ๋ฆผ ์ฐธ๊ณ 

Desktop View

๋‹ค์‹œ ๋ณธ๋ก ์œผ๋กœ ๋„˜์–ด๊ฐ€์„œ ์•„๋ž˜ ๊ทธ๋ฆผ์„ ๋ณด์ž

Desktop View

์ž ์ด์ œ x,y ๋ถ„ํฌ๋“ค์— ์žˆ๋Š” n๊ฐœ ์ค‘์—์„œ i๋ฒˆ์งธ ๋ฐ์ดํ„ฐ๋ฅผ $d_i$ ๋ผ ํ•˜์ž ย ย ย  \(d_i = \begin{bmatrix} x_i \\ y_i\end{bmatrix}\)
ํ‰๊ท ์„ ๋นผ์ง€ ์•Š์€ ๊ฒƒ์€ ์ด๋ ‡๊ฒŒ ๋‚˜ํƒ€๋‚ด์ž ย ย ย  \(\tilde{d_i} \color{blue}{=} \begin{bmatrix} x_i \\ y_i\end{bmatrix}\)
ํ‰๊ท ์„ ๋บ€ ๊ฒƒ์„ ์ด๋ ‡๊ฒŒ โ€”> ย  \(\bar{d_i} \color{red}{=} \begin{bmatrix} \bar{x_i} \\ \bar{y_i}\end{bmatrix}\)
๊ทธ๋ฆฌ๊ณ  ์œ„์˜ 2๋ฒˆ์งธ ๊ทธ๋ž˜ํ”„๋ฅผ ๋ณด๋ฉด x, y๊ฐ’์˜ ๋ถ„ํฌ๋ฅผ ๋‚˜ํƒ€๋‚ธ ๊ฒƒ์ด \(\ddots\ddots\ddots\ddots\cdots \color{pink}{\bullet}\) ์ด๋ ‡๊ฒŒ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์ ๋“ค๋กœ ์žˆ๋Š”๋ฐ
๊ทธ ํ‰๊ท ์„ ์‹น ๊ตฌํ•ด ๋Œ€์ž…ํ•œ ๊ฒƒ์ด \(\bar{d_i} = \begin{bmatrix} \bar{x_i} \\ \bar{y_i}\end{bmatrix}\) ์ด๊ฒƒ์ด๊ธฐ๋„ ํ•˜๋‹ค

(1) ๐Ÿ˜‹minimize(์ตœ์†Œํ™”)

์ž ๊น ์˜์ƒ์„ ์ฐธ๊ณ ํ•˜์ž
Desktop View

(์ด ์˜์ƒ์€ ๋ชจ๋“  ๋ถ„ํฌ๋“ค์˜ ์ตœ์†Œ error๋ฅผ ์ฐพ๋Š” ๊ฒƒ, ์ฆ‰ ์ฃผ์„ฑ๋ถ„์„ ์ฐพ๋Š” ๊ณผ์ •์ด๋‹ค)

์ž ์›๋ž˜๋Š” x,y ๋ถ„ํฌ๋“ค์ด ์žˆ์„ ๋•Œ ๋ชจ๋“  ์ ๋“ค๊ณผ ๋น„๊ตํ•˜์—ฌ error(๊ฐ’)์ด ๊ฐ€์žฅ ์ž‘์„ ๋•Œ๊ฐ€ ์–ธ์ œ์ธ์ง€ ๋น„๊ตํ•˜๋Š”๊ฒŒ ๋งž๋Š”๋ฐ ๊ทธ๋Ÿฌ๋ฉด ๋„ˆ๋ฌด ํ• ๊ฒŒ ๋งŽ์•„์ง€๋ฏ€๋กœ ๋‚˜๋Š” ์  ํ•˜๋‚˜๋งŒ ๋ณด๊ฒ ๋‹ค
๊ทธ๋Ÿฌ๋ฉด ์ด์ œ๋ถ€ํ„ฐ orthogonalํ•˜๋ฉด์„œ error๊ฐ€ ๊ฐ€์žฅ ์ ์€ ์ ๊ณผ ์—ฐ๊ฒฐํ•ด์•ผํ•˜๋Š”๋ฐ ์ž„์˜์˜ x,y๋ฅผ ๊ฐ€์ง„ \(\color{pink}{\bullet}\)์ ์„ ํ–ฅํ•˜๋Š” ๋ฒกํ„ฐ๊ฐ€ ์žˆ์„ ๊ฒƒ์ด๊ณ  \(\vec{u}\)๋กœ \(\perp\)ํ•˜๊ฒŒ ์ˆ˜์„ ์˜ ๋ฐœ์„ ๋‚ด๋ฆฌ์ž! ๊ทธ๋ ‡๊ฒŒ ๋˜๋ฉด ๊ทธ ๊ธธ์ด๋Š” ์˜ค์ฐจ๋‹ค
์ž ์—ฌ๊ธฐ์„œ ๊ฐx,y ์ ๋“ค์˜ ๋ถ„ํฌ์˜ ๋ถ„์‚ฐ์„ ๊ฐ€์žฅ ์ž˜ ์„ค๋ช…ํ•˜๋Š” ๋ฐฉํ–ฅ์€ projection ๋‚ด๋ ธ์„ ๋•Œ \(error^2\)์„ ๊ฐ€์žฅ ์ž‘๊ฒŒ ๋งŒ๋“œ๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ํ–ฅํ•˜๋”๋ผ

์•„๋ž˜ ์˜์ƒ์„ ๋ณด๋ฉด ์ตœ์†Œ ๊ตฌ๊ฐ„์„ ์ฐพ๋‹ค๊ฐ€ ์ฐพ์œผ๋ฉด ๋ฉˆ์ถฐ์„œ ๋ง ๊ทธ๋Œ€๋กœ ์ˆ˜์„ ์˜ ๋ฐœ์„ ๋‚ด๋ ค \(\perp\)๋œ๋‹ค

Desktop View Desktop View

์•„ ์ด๊ฒƒ์œผ๋กœ 1๏ธโƒฃ ์™œ ๋ถ„์‚ฐ์ด ๊ฐ€์žฅ ํฐ ๋ฐฉํ–ฅ์ด ์ด ๋ถ„ํฌ๋ฅผ ์ž˜ ์„ค๋ช…ํ•˜๋Š”๊ฐ€? ์— ๋Œ€ํ•œ ์งˆ๋ฌธ์€ ํ•ด๊ฒฐ์ด ๋˜์—ˆ๊ตฐ
์ด์–ด์„œ min์„ ๊ตฌํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ์ˆ˜์„ ์˜๋ฐœ ์ฆ‰ error์˜ ๊ธธ์ด๋ฅผ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด ์•„๋ž˜ ํ‘œ๋ฅผ ๋ณด์ž

----------------์ฐธ๊ณ -------------------
(1) \(d_i^T u\) ย  ์ •์‚ฌ์˜ํ•œ ๊ฒฐ๊ณผ \(\Rightarrow\) ์ฆ‰ ์Šค์นผ๋ผ
(2) \(d_i^T u\cdot u\) ย  ์ •์‚ฌ์˜ํ•œ ๊ฒฐ๊ณผ์— u์™€ ๋‚ด์ ํ•˜์—ฌ u๋ฐฉํ–ฅ์„ฑ๋ถ„์„ ํš๋“
(3) \(\left(d_i-d_i^T u\cdot u\right)\) ย  \(d_i\) ๋ฒกํ„ฐ์—์„œ u๋ฒกํ„ฐ์˜ ์„ฑ๋ถ„ ์ œ๊ฑฐ
(์ฆ‰ \(a^Ta\) ๊ผด๋กœ ๋งŒ๋“ค๋ฉด ์ œ๊ณฑ์ฒ˜๋Ÿผ ๋˜์–ด ๋†’์ด์ธ ์˜ค์ฐจ๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค)
-------------------------------------------

Desktop View

์ž ์ € ๋ฐ์ดํ„ฐ ํ•˜๋‚˜์˜ error length์— ๋Œ€ํ•œ ์‹์€ ์ด๋ ‡๋‹ค \(\color{red}{\Rightarrow}\) \(\left(d_i-d_i^T uu\right)^T \left(d_i-d_i^T uu\right)\)
์–ด ์ด๊ฑด \(L_2\) norm์˜ \(\sqrt{x_1^{2}+x_2^{2}+\cdots}\) ํ˜•์‹์ด๋„ค?

๊ทผ๋ฐ ์•„๊นŒ๋„ ๋งํ–ˆ์ง€๋งŒ \(d_i\)๋“ค ์ค‘ ํ•œ ์ ์ด ์•„๋‹ˆ๋ผ N๊ฐœ์˜ ๋ชจ๋“  ๋ฐ์ดํ„ฐ์—์„œ ๊ณ ๋ คํ•ด์•ผํ•˜๋‹ˆ
\(\frac{1}{N}\sum_{i} \left(d_i-d_i^T uu\right)^T \left(d_i-d_i^T uu\right)\\ S.T. \quad \vert\vert u\vert\vert_2^2 = u^Tu=1\)
ํ•ด์„ \(\Rightarrow\) ์ „์ฒด \(d_i\) error length๋ฅผ ๋”ํ•œ ๊ฒƒ์„ ์ œ๊ณฑํ•ด N๊ฐœ๋กœ ๋‚˜๋ˆ ์ฃผ๋Š”๋ฐ, ย  ์กฐ๊ฑด์€ ์˜ค์ฐจ๊ฑฐ๋ฆฌ์ œ๊ณฑ์ด 1์ผ๊ฒƒ

์—ฌ๊ธฐ์„œ ๋ถ„๋ฐฐ๋ฒ•์น™ํ•ด๋ณด์ž ย ย  ์ฐธ๊ณ ๋กœ \(d_i^T u\)๋Š” ์Šค์นผ๋ผ๋ผ์„œ transposed ์˜ํ–ฅ ์•ˆ ๋ฐ›๋Š”๋‹ค
\(\frac{1}{N}\sum_{i} \left(d_i^Td_i-d_i^Tu\cdot u^Td_i-d_i^T(d_i^Tu)u+d_i^Tu\cdot u^T(d_i^Tu)u\right)\)
์ž ์•„๊นŒ ์ž„์˜๋กœ $u^Tu=1$๋กœ ์กฐ๊ฑด์„ ๋ถ€์—ฌํ•˜์˜€๊ณ  ์Šค์นผ๋ผ๋Š” ์•ž์œผ๋กœ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ
\(\frac{1}{N}\sum_{i} \left(d_i^Td_i-d_i^Tu\cdot u^Td_i-(d_i^Tu)d_i^Tu+(d_i^Tu)d_i^Tu\cdot u^Tu\right)\\ \Rightarrow \frac{1}{N}\sum_{i} \left(d_i^Td_i-d_i^Tu\cdot u^Td_i\right)\)
์œ„์ฒ˜๋Ÿผ ์ „๊ฐœ๊ฐ€ ๋˜๋Š”๋ฐ ์šฐ๋ฆฌ๋Š” \(\vec{u}\)๊ฐ€ ํ•„์š”ํ•˜๊ณ , \(d_i^Td_i\) ์ด๊ฑฐ ํ•„์š” ์—†์œผ๋‹ˆ๊นŒ ์ œ๊ฑฐํ•˜์ž
why?โ€“> ์–ด์ฐจํ”ผ ๋ฐ์ดํ„ฐ์˜ ์ œ๊ณฑํ•ฉ์„ ๊ตฌํ• ๊ฑด๋ฐ ์ €๊ฑด bias๋ผ์„œ ์žˆ์œผ๋ฉด ๋ชจ๋ธ ์˜ˆ์ธก์— ๋ถˆํ•„์š”ํ•œ ์˜ํ–ฅ์„ ์ฃผ๊ฑฐ๋“ 

๊ทธ๋ ‡๊ฒŒ ๋˜๋ฉด ๋‚จ๋Š” ์‹์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค
\(\Rightarrow \frac{1}{N}\sum \left(-d_i^Tu\cdot u^Td_i\right)\)
์ž ๊ทธ๋ฆฌ๊ณ  ์•„๊นŒ error์ธ ์ด์‹์„ ์ฐธ๊ณ  ํ•˜์ž ย  \(d_i=\tilde{d_i}-\bar{d_i}\)
๊ทธ๋ฆฌ๊ณ  u๋Š” \(d_i\)์™€ ๊ด€๊ณ„์—†์œผ๋‹ˆ ์•ž์— ๋นผ์ฃผ์ž ๊ทธ๋Ÿผ ์‹์„ ์œ„์น˜๋ฅผ ๋ฐ”๊พธ์–ด ์ „๊ฐœ ๊ฐ€๋Šฅํ•˜๊ฒ ๋„คโฌ‡๏ธ
\(\Rightarrow \frac{1}{N}\sum_{i} \left(-u^Td_i\cdot d_i^Tu\right) \\ \Rightarrow -u^T\frac{1}{N}\sum \left(d_i\cdot d_i^T\right)u \\ \Rightarrow -u^T\frac{1}{N}\sum_i \left((\tilde{d_i}-\bar{d_i})(\tilde{d_i}-\bar{d_i})^T\right)u\)
Desktop View

์ž \(\color{lightgreen}{\square}\)๋Š” sample covariance matrix๋ž‘ ๋น„์Šทํ•˜๋„ค?
\(\begin{bmatrix} cov(x,x) & cos(x,y) \\cov(y,x) & cos(y,y) \end{bmatrix}\) ย  ์ด๊ฒŒ covariance matrix์ธ๋ฐ symmetricํ•˜์—ฌ diagonalizableํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
๊ทผ๋ฐ diagonalizableํ•˜๋‹ค๊ณ  symmetricํ•˜์ง€๋Š” ์•Š๋‹ค ์•Œ์•„๋‘์ž
์•„๋ฌดํŠผ \(\color{lightgreen}{\square} = R_d\)๋ผ ํ•˜๊ฒ ๋‹ค
์ž ๊ทธ๋Ÿฌ๋ฉด \(-u^TR_du\)๋ผ๊ณ  ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค
์ด๋•Œ \(R_d\)๋ฅผ ํ†ตํ•ด ์ƒ๊ฐํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๋“ค ย ย  \(\begin{cases}if \quad 1D \rightarrow ๋ถ„์‚ฐ\\ if \quad 2D \rightarrow covariance \quad matrix\end{cases}\)

์ž ์š”์•ฝํ•˜์ž๋ฉด \(min=-u^T\frac{1}{N}\sum_i \left((\tilde{d_i}-\bar{d_i})(\tilde{d_i}-\bar{d_i})^T\right)u\) ์ด๊ณ 
๋ณ€์ˆ˜๋ฅผ ํ†ตํ•ด ๋ฐ”๊พธ๋ฉด \(min\color{red}{=}-u^TR_du\) ์ด๋ ‡๊ฒŒ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๊ฒ ๋„ค


(2) ๐Ÿงโ€โ™€๏ธmaximize(์ตœ๋Œ€ํ™”)

์ž ๊ฐ„๋‹จํ•˜๊ฒŒ ์–˜๊ธฐํ•ด ์œ„์˜ ์‹์—์„œ -๋ถ€ํ˜ธ๋งŒ ๋บ€ ๊ฒƒ์ด๋‹ค ย  \(max\color{red}{=}u^TR_du\)
์ด๊ฒƒ์— ๋Œ€ํ•œ ์ฆ๋ช…์€ Lagrangian function ์“ฐ์ž
\(L=u^TR_du+\gamma(1-u^Tu)\)

\(\vec{u}\) ์— ๋Œ€ํ•œ ๋ฏธ๋ถ„ \(\Rightarrow\) ์ฆ‰ \(\vec{u}\)์— ๋Œ€ํ•œ ๋ณ€ํ™”๋Ÿ‰์„ ์•Œ์•„๋ณธ๋‹ค๋Š” ๋œป์ด๋‹ค.
\(dLu=du^TR_du\color{red}{+} u^TR_ddu\color{red}{-}\gamma d\color{skyblue}{u^Tu}\color{red}{-} \gamma\color{skyblue}{u^T}d\color{skyblue}{u}\)
์—ฌ๊ธฐ์„œ \(\color{skyblue}{u^Tu}\)๋Š” ์Šค์นผ๋ผ๋‹ˆ๊นŒ transposed ์ทจํ•ด๋„ ๋˜‘๊ฐ™๋‹ค

\(\Rightarrow 2u^TR_du \color{red}{-} 2\gamma u^Tdu \\ = \color{violet}{(}2u^TR_d-2\gamma u^T\color{violet}{)}du\)
์ด์‹์—์„œ $\color{violet}{(}~~~~\color{violet}{)}$ ๋ถ€๋ถ„์€ $\frac{dL}{du^T}$๋‹ค ์ด๊ฒŒ ๋ฌด์Šจ๋ง์ด๋ƒ๋ฉด L/ u row vectors๋กœ ๋ฏธ๋ถ„ํ–ˆ๋‹ค๋Š” ๋œป

---------------๋ฒกํ„ฐ์˜ ๋ฏธ๋ถ„-----------------
1๊ฐœ์”ฉ ๋ฏธ๋ถ„ํ•œ ๊ฒƒ์„ ๊ฐ€๋กœ๋กœ ์Œ“์€ ๊ฒƒ
\(\frac{dL}{du^T}\) \(\color{red}{=}\) \(\left[\frac{dL}{du_1} \color{lightgreen}{,} \frac{dL}{du_2} \color{lightgreen}{,} \frac{dL}{du_3} \cdots\right]\)
---------------------------------------------

์•„๋ฌดํŠผ ์šฐ๋ฆฌ๋Š” \(\color{violet}{(}~~~~ \color{violet}{)}\)du ๋ผ๋Š” ์‹์—์„œ \(\color{violet}{(}~~~~ \color{violet}{)}\)๊ฐ€ ๋ฏธ๋ถ„์ด๋ž€ ๊ฒƒ์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค

๐Ÿง‘โ€๐ŸŽจ๊ณ„์‚ฐ

์ž ๊ทธ๋Ÿผ ์šฐ๋ฆฌ๊ฐ€ ํ•  ๊ฒƒ์€ $\frac{dL}{du^T}=0$ ์„ ๋งŒ์กฑํ•˜๋Š” u ์ค‘์—์„œ ๊ฐ€์žฅ max๋ฅผ ์ฐพ์•„์•ผ ํ•˜๊ณ  ์•„๊นŒ $L$์‹์„ ๋งŒ์กฑํ•œ๋‹ค
์•„๋ฌดํŠผ ์•„๊นŒ \(\color{violet}{(}~~~~\color{violet}{)}\)์‹์—์„œ ์–‘๋ณ€์œผ๋กœ ๋„˜๊ธฐ๋ฉด \(u^Tr_d=\gamma u^T\)๊ฐ€ ๋˜๋„ค
๊ทธ๋ฆฌ๊ณ  transposed ์ทจํ•ด์ฃผ์ž whyโ€”> \(R_d\)๊ฐ€ symmetricํ•˜๋‹ˆ ๋‹น์—ฐํžˆ diagonalizableํ•˜์—ฌ orthogonal matrix๋กœ decompose ๊ฐ€๋Šฅ
(์ฐธ๊ณ ๋กœ \(\gamma\)๋Š” ์Šค์นผ๋ผ๋ผ transposed ์˜ํ–ฅ ์—†๋‹ค)

\(\left(u^Tr_d\right)^T=\left(\gamma u^T\right)^T \\ \color{red}{\Rightarrow} R_du = \gamma u \quad\quad\quad (\gamma: EigenValue,\quad u: EigenVector)\)

์ž ์ด์ œ \(R_d\)๋ฅผ decompose ํ•˜์ž
๊ทธ๋Ÿฌ๊ธฐ ์œ„ํ•ด ์•„๊นŒ ์ „์— ๋ดค๋˜ ์‹์ธ \(max=u^TR_du\)๋กœ ๋„˜์–ด๊ฐ€์ž
\(R_d\): ย ย ย  symmetricํ•ด์„œ diagonalizable๋˜๋ฏ€๋กœ orthogonal matrix๋กœ decompose๋œ๋‹ค๊ณ  ํ–ˆ๋‹ค
\(u^TR_du \color{red}{=} u^T\left(\gamma_1 q_1q_1^T \color{red}{+} \gamma_2 q_2q_2^T \color{red}{+} \cdots \right)u\)
u๊ฐ€ ๋ฌด์—‡์ผ ๋•Œ \(q_1, ~~ q_2, ~~ \cdots\)๊ฐ€ ํฐ ๊ฐ’์œผ๋กœ ๋‚˜์˜ฌ๊นŒ ?

์ž ์•„๊นŒ u๋Š” \(R_d\)์˜ EigenVector๋ผ๊ณ  ํ–ˆ๋‹ค ๊ทธ๋ง์€ u๊ฐ€ \(q_1, q_2, \cdots\) ์ค‘์— ํ•˜๋‚˜๋ผ๋Š” ์–˜๊ธฐ๋‹ค
์ข‹๋‹ค ๊ทธ๋Ÿผ ๋งŒ์•ฝ \(\gamma_1 \quad \gamma_2\cdots\)์ด ๋‚ด๋ฆผ์ฐจ์ˆœ์ด๊ณ ,ย ย  \(u=q_1\) ๋กœ ๋ณด์ž
\(\Rightarrow q_1^T \left(\gamma_1 q_1q_1^T\right)q_1\) ย  ์ด๋ ‡๊ฒŒ ๋˜๋Š”๋ฐ \(q_1^Tq_1=1\)๋กœ ์ƒ์‡„๋˜๋‹ˆ \(\gamma_1\)๋งŒ ๋‚จ๋Š”๋‹ค
์ž ๊ทธ๋Ÿผ ๋‚ด๋ฆผ์ฐจ์ˆœ์ด๋ผ ํ–ˆ์œผ๋‹ˆ \(\gamma_1\)์ด ๊ฐ€์žฅ ํฐ ์ฃผ์„ฑ๋ถ„ ๋ฒกํ„ฐ๊ณ  ๊ทธ๋‹ค์Œ์œผ๋กœ๋Š” \(\gamma_2\)๋‹ค
์ฐธ \(q_1 \perp q_2\)๋‹ˆ๊นŒ ์ฆ‰ orthogonalํ•˜์—ฌ ์•„๋ž˜ ๊ทธ๋ฆผ์˜ ๋ถ„์‚ฐ์ •๋„๋ฅผ ๋ณด๋ฉด \(q_2\)๊ฐ€ ์™œ 2๋ฒˆ์งธ๋กœ ํฐ ์ฃผ์„ฑ๋ถ„์œผ๋กœ ๋ถ„ํฌ๋ฅผ ์ž˜ ์„ค๋ช…ํ•˜๋Š”์ง€ ์•Œ ์ˆ˜ ์žˆ๋‹ค

Desktop View

์ž ์ด์ œ 2๏ธโƒฃ ์™œ ๊ทธ๋‹ค์Œ์œผ๋กœ ์ž˜ ์„ค๋ช…ํ•˜๋Š” ๋ฐฉํ–ฅ์€ ์ฒซ ๋ฒˆ์งธ ์ฃผ์„ฑ๋ถ„์— ์ˆ˜์งํ•˜๋ƒ? ์งˆ๋ฌธ์— ๋Œ€ํ•œ ๋‹ต์„ ํ•  ์ˆ˜ ์žˆ๋‹ค


3. PCA ์‘์šฉ

3-1. ์ฐจ์›์ถ•์†Œ(์˜ˆ์‹œ)

100์ฐจ์› ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•˜์ž

\(\begin{bmatrix} x\\y\\z\\ \vdots\\\vdots\\\vdots \end{bmatrix}\) ย  ์ด๊ฒƒ์„ 100์ฐจ์›์˜ ํ•œ ์ ์ด๋ผ ํ•˜์ž

Desktop View

์—ฌ๊ธฐ์„œ 100 Dim data์— ์žˆ๋Š” ํ•œ ์  โ€”> 2 Dim data๋กœ ์ถ•์†Œํ•˜๋ ค๋ฉด
i๋ฒˆ์งธ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ์„ ๋•Œ ์ถ•์†Œํ•œ ๊ฒฐ๊ณผ๊ฐ€ ์ด๋ ‡๊ฒŒ ๋œ๋‹ค \(d_i^Tq_1\cdot q_1+d_i^Tq_2\cdot q_2\)
์ž ์•ž์—์„œ๋„ ์–˜๊ธฐํ–ˆ์ง€๋งŒ ๋ฐ”๋กœ ์œ„์˜ ์‹์€ ๊ฐ๊ฐ (๋‚ด์ x๋ฐฉํ–ฅ์„ฑ) + (๋‚ด์ x๋ฐฉํ–ฅ์„ฑ)์„ ๋‚˜ํƒ€๋‚ธ ๊ฑฐ์ด๋‹ค
์•„๋ฌดํŠผ ์ด ์‹์ด ๋ฌด์Šจ ๋ง์ด๋ƒ๋ฉด ์–ด๋–ค ๊ณต๊ฐ„์ด ์žˆ์„ ๋•Œ 2 Dim์— ๋‚ด๋ฆฐ๋‹ค๋Š” ๊ฒƒ์ธ๋ฐ
์ด 2์ฐจ์›์€ \(q_1 \quad q_2\)๊ฐ€ span ํ•˜๋Š” ๊ณณ์ด๋‹ค

Desktop View

์ด๊ฒŒ ๋ฌด์Šจ ๋ง์ด๋ƒ๋ฉด \(q_1=\begin{bmatrix} \vdots\\\vdots\\\vdots \end{bmatrix}, \quad q_2=\begin{bmatrix} \vdots\\\vdots\\\vdots \end{bmatrix}\) ย  ๊ฐ๊ฐ 100๊ฐœ์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋Š”๋ฐ
\(q_1\)๊ณผ \(q_2\)๋กœ linear combination ์ฆ‰ spanํ•˜๊ฒŒ ๋˜๋ฉด
\(a\begin{bmatrix} \vdots\\\vdots\\\vdots \end{bmatrix}+ b\begin{bmatrix} \vdots\\\vdots\\\vdots \end{bmatrix}\) ย  ์ฆ‰ 2 Dim ํ‰๋ฉด๋งŒ ๋‚˜ํƒ€๋‚ธ๋‹ค๋Š” ๋œป

์ž ๊ทธ๋Ÿผ \(\color{blue}{\bullet}\)์„ 100 Dim ์œ„์˜ ํ•œ ์ ์ด๋ผ ํ•˜๊ณ  ๊ทธ๊ฒƒ์„ ์•„๋ž˜๋กœ ๋‚ด๋ ธ๋‹ค๊ณ  ์น˜์ž

Desktop View

์—ฌ๊ธฐ์„œ 2 Dim์œผ๋กœ ๋‚ด๋ฆฐ ์ ์ด \(d_i^Tq_1\cdot q_1+d_i^Tq_2\cdot q_2\) ๋‹ค

์ž ์—ฌ๊ธฐ์„œ ์ •์‚ฌ์˜ํ•œ ์ ์˜ ๊ฐ’์„ ์ฐพ๊ธฐ ์œ„ํ•ด ์ขŒํ‘œ๊ฐ’์„ ๊ตฌํ•ด์•ผ๋˜๋Š”๋ฐ
\(q_1\) ์ถ•์œผ๋กœ์˜ ์ขŒํ‘œ๊ฐ’์„ ๋‚ด์ ํ•œ ๊ฐ’ \(\Rightarrow\) \(d_i^Tq_1\)
๋งˆ์ฐฌ๊ฐ€์ง€๋กœ $q_2$ ์ถ•์œผ๋กœ์˜ ์ขŒํ‘œ๊ฐ’์„ ๋‚ด์ ํ•œ ๊ฐ’ \(\Rightarrow\) \(d_i^Tq_2\)
๊ทธ๋Ÿผ ์ •์‚ฌ์˜ํ•œ ์ ์„ ํ‘œํ˜„ํ•˜๋ ค๋ฉด \(a\begin{bmatrix} 1\\0 \end{bmatrix}+ b\begin{bmatrix} 0\\1 \end{bmatrix}\) ย  ์ด๋Ÿฐ์‹์œผ๋กœ ์ง„ํ–‰๋˜๊ฒ ์ง€?

Desktop View

์ •์‚ฌ์˜ํ•œ ์ ์˜ ์‹์€ ์•„๋ž˜ ์‹์˜ ์—ญํ• ์„ ๋Œ€์ฒดํ•ด์ค€๋‹ค

Desktop View

์Œ ๊ทธ๋Ÿฌ๋ฉด ๋ฐ์ดํ„ฐ 10000๊ฐœ ์ค‘์—์„œ \(q_{1(100*1)}\), ย  \(q_{2(100*1)}\)์ด๋‹ˆ
2์ฐจ์› ์ถ•์†Œ๋ฅผ ์œ„ํ•ด์„œ๋Š” ์ˆซ์ž 200๊ฐœ๊ฐ€ ํ•„์š”ํ•˜๊ฒ ๊ตฐ

3-2. ์ฐจ์›์ถ•์†Œ(์˜์ƒ)

16x16์ธ 256 Dim์—์„œ PCA๋ฅผ ํ†ตํ•ด 3 Dim์œผ๋กœ ์••์ถ•ํ–ˆ์„ ๋•Œ

Desktop View

์ฐธ๊ณ 

  1. ํ˜ํŽœํ•˜์ž„ ย ย  ์ฃผ์„ฑ๋ถ„ ๋ถ„์„ (PCA: Principal Component Analysis) ์˜ ๋ชจ๋“  ๊ฒƒ!, ๊ณ ์œณ๊ฐ’ ๋ถ„ํ•ด์˜ ์‘์šฉ
  2. ๊ณต๋Œ์ด์˜ ์ˆ˜ํ•™์ •๋ฆฌ ๋…ธํŠธ ย ย ย  ์ฃผ์„ฑ๋ถ„ ๋ถ„์„(PCA)์˜ ๊ธฐํ•˜ํ•™์  ์˜๋ฏธ
  3. ๋ธŒ๋ฆญ ย ย ย  ์ฃผ์„ฑ๋ถ„ ๋ถ„์„ (PCA)์˜ ์›๋ฆฌ์™€ ์ „์‚ฌ์ฒด ๋ฐ์ดํ„ฐ ๋ถ„์„์—์„œ์˜ ํ™œ์šฉ
  4. ๊ณ ๋ ค๋Œ€ํ•™๊ต ์‚ฐ์—…๊ฒฝ์˜๊ณตํ•™๋ถ€ DSBA ย ย ย  01-4: Dimensionality Reduction - PCA
This post is licensed under CC BY 4.0 by the author.
3D GIF