๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
AI ๊ณต๋ถ€ ํ•ญ์ƒํ•˜์ž/๊ด€๋ จ ์ด๋ก 

[Math] ๋ฒกํ„ฐ๋ฅผ ์•Œ์•„๋ณด์ž

by ์ž„๋ฆฌ๋‘ฅ์ ˆ 2024. 11. 22.
๋ฐ˜์‘ํ˜•
๋”๋ณด๊ธฐ

๊ธฐ์กด ๋ถ€์บ  ๋•Œ ๋…ธ์…˜์— ๊ฐœ์ธ์ ์œผ๋กœ ์ •๋ฆฌํ•œ ๊ฒƒ์„ ๊ณต๋ถ€ํ•  ๊ฒธ ์ž‘์„ฑํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค.
๊ฐœ์ธ์ ์œผ๋กœ ํ•ด์„ํ•ด์„œ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. (ํ‹€๋ฆด ์ˆ˜ ์žˆ์Œ. ์ •์ •์š”์ฒญ ์š”๋งใ…‹)
** ๊ฐ•์˜์ž๋ฃŒ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค **
** ์ƒ์—…์  ์ด์šฉ์„ ๊ธˆ์ง€ํ•ฉ๋‹ˆ๋‹ค **

Today's Keyword

๋ฒกํ„ฐ, Norm, L1-norm, L2-norm, ๋‚ด์ , ์ •์‚ฌ์˜


๋ฒกํ„ฐ

  • ๊ณต๊ฐ„์—์„œ ํ•œ ์ . ์›์ ์œผ๋กœ๋ถ€ํ„ฐ ์ƒ๋Œ€์  ์œ„์น˜ ํ‘œํ˜„
  • ์Šค์นผ๋ผ ๊ณฑ ํ•˜๋ฉด ๊ธธ์ด๋งŒ ๋ณ€ํ•จ.
  • ์ˆซ์ž๋ฅผ ์›์†Œ๋กœ ๊ฐ€์ง€๋Š” ๋ฆฌ์ŠคํŠธ, ๋ฐฐ์—ด
  • ๊ฐ™์€ ๋ชจ์–‘์ด๋ฉด ์„ฑ๋ถ„๊ณฑ Hadamard product
  • ๋ฒกํ„ฐ์˜ ๋ง์…ˆ == ๋‹ค๋ฅธ ๋ฒกํ„ฐ๋กœ๋ถ€ํ„ฐ ์ƒ๋Œ€์  ์ด๋™

Norm = ์›์ ์—์„œ ๋ถ€ํ„ฐ์˜ ๊ฑฐ๋ฆฌ

p = ์ฐจ์ˆ˜. 1์ด๋ฉด ๋…ธ๋ฆ„1, 2๋ฉด 2

  • ๋…ธ๋ฆ„์˜ ์ข…๋ฅ˜๋”ฐ๋ผ ๋‹ค๋ฆ„ -> ๊ธฐํ•˜ํ•™์  ์„ฑ์งˆ๋„ ๋‹ฌ๋ผ์ง
  • L1 norm - ๋ณ€ํ™”๋Ÿ‰์˜ ์ ˆ๋Œ€๊ฐ’ ๋ชจ๋‘ ๋”ํ•ด !
    for Robust ํ•™์Šต, Lasso ํšŒ๊ท€

L1

  • L2 norm - ํ”ผํƒ€๊ณ ๋ผ์Šค ์ •๋ฆฌ (a^2 + b^2 = c^2) ์จ์„œ ์œ ํด๋ฆฌ๋“œ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐํ•ด !
    for Laplace ๊ทผ์‚ฌ, Ridge ํšŒ๊ท€

L2
์ด๋ž˜์„œ ๋…ธ๋ฆ„๋งˆ๋‹ค์˜ ๊ธฐํ•˜ํ•™์  ์„ฑ์งˆ์ด ๋‹ฌ๋ผ์ง„๋‹ค

 

  • ๋‘ ์  ์‚ฌ์ด ๊ฑฐ๋ฆฌ(๋ฒกํ„ฐ์˜ ๋บ„์…ˆ) -> ์ œ 2์ฝ”์‚ฌ์ธ ๋ฒ•์น™์œผ๋กœ ๊ฐ๋„๋„ ๊ณ„์‚ฐ ๊ฐ€๋Šฅ (๊ฐ๋„๋Š” L2 norm)

u·v ๋Š” ๋‘ ๋ฒกํ„ฐ์˜ ๋‚ด์ . ๋ฐ‘์€ ๋…ธ๋ฆ„

์•„ ์ž ๋งŒ ๋‚ด์ ์ด์š”?

  • ์ •์‚ฌ์˜(orthogonal projection)๋œ ๋ฒกํ„ฐ์˜ ๊ธธ์ด์™€ ๊ด€๋ จ์žˆ๋‹ค.
    • ์ •์‚ฌ์˜์ด ๋ˆ„๊ตฌ์„ธ์š” : "๊ณง๊ฒŒ ์œ ๊ทธ๋ฆผ์ž" (์ง„์งœ์ž„)

์ •์‚ฌ์˜ ์„ค๋ช…ํ•˜๋Š” ๊ทธ๋ฆผ
x -> ์ฝ”์‚ฌ์ธ์ด์šฉํ•ด ์ •์‚ฌ์˜ -> ์ด๋ฅผ โ˜โ˜yโ˜โ˜๋งŒํผ ์กฐ์ • (๊ท€์ฐฎ์•„์„œ ๊ทธ๋ƒฅ ๊ทธ๋ฆผ)

 

  • ๋‚ด์ ์€ ๋‘ ๋ฒกํ„ฐ์˜ Similarity๋ฅผ ์ธก์ •ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค 

๊ฐ‘์ž๊ธฐ ๋ถ„์œ„๊ธฐ ๋ฌธ์ œ (๊ฐ‘๋ถ„๋ฌธ)

Q. ๋‘ ๋ฒกํ„ฐ์˜ ๋‚ด์  (๋‹จ์ผ์„ ํƒ , 10์ )

๋‚ด์ ์ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ •์˜ ๋  ๋•Œ, ๋‹ค์Œ ๋‘ ๋ฒกํ„ฐ ( xx ,  yy )์˜ ๋‚ด์ ์„ ๊ตฌํ•˜์‹œ์˜ค.

 

๊ฐ‘์ž๊ธฐ ๋ถ„์œ„๊ธฐ ์ฝ”๋“œ (๊ฐ‘๋ถ„์ฝ”)

import numpy as np

# ๋‘ ๋ฒกํ„ฐ ์ •์˜
u = np.array([3, 4])
v = np.array([4, 3])

# L1 ๋…ธ๋ฆ„ (๋ฒกํ„ฐ ์š”์†Œ์˜ ์ ˆ๋Œ“๊ฐ’ ํ•ฉ)
l1_norm_u = np.sum(np.abs(u))
l1_norm_v = np.sum(np.abs(v))

# L2 ๋…ธ๋ฆ„ (๋ฒกํ„ฐ ํฌ๊ธฐ, Euclidean Norm)
l2_norm_u = np.linalg.norm(u)
l2_norm_v = np.linalg.norm(v)

# ๋‚ด์  ๊ณ„์‚ฐ
dot_product = np.dot(u, v)

# ๊ฒฐ๊ณผ ์ถœ๋ ฅ
print("๋ฒกํ„ฐ u:", u)					# ๋ฒกํ„ฐ u: [3 4]
print("๋ฒกํ„ฐ v:", v)					# ๋ฒกํ„ฐ v: [4 3]
print("\nL1 ๋…ธ๋ฆ„ (u):", l1_norm_u)	# L1 ๋…ธ๋ฆ„ (u): 7
print("L1 ๋…ธ๋ฆ„ (v):", l1_norm_v)		# L1 ๋…ธ๋ฆ„ (v): 7
print("\nL2 ๋…ธ๋ฆ„ (u):", l2_norm_u)	# L2 ๋…ธ๋ฆ„ (u): 5.0
print("L2 ๋…ธ๋ฆ„ (v):", l2_norm_v)		# L2 ๋…ธ๋ฆ„ (v): 5.0
print("\n๋‚ด์  (u · v):", dot_product) # ๋‚ด์  (u · v): 24

 

 

 

์ฐธ๊ณ  : L1 norm, L2 norm, ๋‚ด์   https://hwanii-with.tistory.com/5 https://m.blog.naver.com/ryumochyee-logarithm/221542210272 

๋ฐ˜์‘ํ˜•

์ตœ๊ทผ๋Œ“๊ธ€

์ตœ๊ทผ๊ธ€

skin by ยฉ 2024 ttutta