๐ Self Study/๐ Deep Learning Basic
Deep learning (Gradient Descent, Chain Rule, Learning Rate)
UKHYUN22
2021. 12. 23. 21:50
728x90
Neural Network Classifier


Gradient Descent
๋ฏธ๋ถ์ ํตํด์ Optimizeํ๊ฒ ๋๋ค. ํ๋์ ์ค์นผ๋ผ ๊ฐ์ W์ ๋ํด ๋ฏธ๋ถ์ ํ๊ฒ ๋๋ค. W์ ๊ฐ์ ์ผ๋ ฌ๋ก ์ธ์์ ์ผ์ฐจ์ ๋ฒกํฐ์ธ ๊ฒ์ผ๋ก ์๊ฐํ์.
scalar ๊ฐ์ ๋์ดํ๋ฉด ๋ค์๊ณผ ๊ฐ์ ์์ ์ป์ ์ ์๋ค. (๊ฐ์ฅ ์ค๋ฅธ์ชฝ ์) ์ด๋ฌํ ๋ฒกํฐ๋ฅผ Gradient ๋ฒกํฐ๋ผ๊ณ ํ๋ค.
๊ฐ๊ฐ Element๋ค์ด ํด๋น Weight๋ก ๋ฏธ๋ถ์ด ๋๊ฒ์ด Gradient ๋ฒกํฐ๋ผ๊ณ ํ๋ค. ์ํ์ ์ผ๋ก Error surface์ error๊ฐ ๊ธ๊ฒฉํ๊ฒ ๋ณํ๋ ๋ฐฉํฅ์ด๋ผ๊ณ ๋ณผ ์ ์๋ค.

W์ Gradient๋ฅผ ๋ง์ด๋์ค ํ๋ค๋ ๊ฒ์ ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ๊ฐ๋ค๋ ๊ฒ์ ์๋ฏธํ๋ค.
๊ฐ์ํ๋ ๋ฐฉํฅ์ผ๋ก ์ด๋ํ๊ฒ ๋๋ค. ํ์ฌ Weight์์ Gradient๋ฅผ ๋นผ์ฃผ๋ ๊ฒ์ด
Gradient Minimize pattern์ด๋ผ๊ณ ํ๋ค. ๋ฏธ๋ถ์ ํด์ Gradient Vector๋ฅผ ์ฐพ์์ง๋ง ์ผ๋ง๋ ๊ฐ์ผ ํ๋์ง๋ ๊ณ์ฐ์ ํด์ผ ํ๋ค.
์ด๋ค ์ซ์๋ฅผ ๊ณฑํ๊ฒ ๋๋๋ฐ Running rate๋ผ๊ณ ํ๋๋ฐ ํด๋น ๋ฐฉํฅ์ผ๋ก ์ผ๋ง๋ ์ด๋ํ ๊ฒ์ธ๊ฐ๋ฅผ ๊ฒฐ์ ํ๊ฒ ๋๋ค.
๋๋ค์ด๋ผ๋ ์์น์์ W๊ฐ ์์๋๊ณ ๋ฏธ๋ถ์ ํตํด์ Gradient๋ฅผ ๊ตฌํ๊ฒ ๋๊ณ ์ด๋์ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๋ํ ์์น์์
๋ค์ Gradient๋ฅผ ๊ตฌํ๊ฒ ๋๊ณ MInimize๋ฅผ ๋ฐ๋ณตํ๋ค.
Gradient๋ฅผ ์ด๋ป๊ฒ ๊ตฌํ ๊ฒ์ธ๊ฐ???

Chain Rule
๋๋ถ๋ถ์ Gradinet๋ฅผ ๊ตฌํ๋ ์์ Chain Rule์ ์ํด์ ๊ณ์ฐ๋๋ค.
๋ณ์๊ฐ 3๊ฐ๊ฐ ์๋ค๊ณ ๊ฐ์ ํ์. y๋ x์ functiion z๋ y์ function์ด๋ผ๊ณ ํ์
์ฌ๊ธฐ์ z๋ฅผ x์ ๋ํด์ ๋ฏธ๋ถ์ ํ๊ณ ์ถ์ ๊ฒฝ์ฐ...!! ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ ์งํํ๋ค.
๊ฐ๊ฐ์ ๋ณ์๋ฅผ Layer๋ผ๊ณ ๋ด๋ ๋ฌด๋ฐฉํ ๊ฒ.

Gradient Descent
W์ Gradient๋ฅผ ๊ตฌํ๊ณ learning rate๋ฅผ ๊ณฑํด์ Gradient minimize๋ฅผ ํ๊ฒ ๋๋ค.
Error๋ output์ function์ด๋ค.
Error๋ฅผ output์ ๋ํด ๋ฏธ๋ถํ๋ ๊ฒ์ ๊ทธ๋ฅ ํ ์ ์๋ค. ์ฆ, Error์ output์ ๋ํด ๋ฏธ๋ถํ๋ฉด
real output - expected output์ด ๋๋ค. = o - d ๊ฐ ๋๋ค๋ผ๋ ๊ฒ.
o๋ฅผ net์ผ๋ก ๋ฏธ๋ถ,, net์ activate function์ ๋ค์ด๊ฐ๊ธฐ ์ ์ ๊ฐ.
๊ฒฐ๊ตญ Activate Fucntion์ ๋ํจ์๊ฐ ๋์จ๋ค.
net์ Weight์ ๋ํด ๋ฏธ๋ถ์ ์งํ!!
์๊ทธ๋ง wx๋ฅผ w์ ๋ํด ๋ฏธ๋ถ์ ํ๊ฒ ๋๋ฉด x๊ฐ ๋์จ๋ค.
ํ์ต์์ ๋ค์๊ณผ ๊ฐ์ด ๋์ค๊ฒ ๋๋ค. ==> "Update rule"
Learning Rate
๋๋ฌด ์ปค๋ ์๋ผ๊ณ ๋๋ฌด ์์๋ ์๋๋ค.
๋๋ฌด ์์ผ๋ฉด ํ ๋ฒ์ ์์ฃผ ์กฐ๊ธ์ฉ ๊ฐ๋ฏ๋ก error๊ฐ ์กฐ๊ธ์ฉ ์ค์ด๋ ๋ค. ์ฆ ์๋ ด์ด ๋๋ ค์ง๋ค.
Local Minimun์ ๊ฐํ ์ ์๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค.
Learning Rate๊ฐ ๋ง์์ง๋ฉด ๋น ๋ฅด๊ฒ ์๋ ดํ๋ ๊ฒ์ด ์๋๋ผ ์ฒ์ฒํ ์๋ ดํ๋ค.
์คํ๋ ค Error๊ฐ ์ปค์ง๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์๋ ์๋ค.